Documentation
¶
Overview ¶
Package coding is the keystone that turns @hanzo from a chatbot into an engineer: it orchestrates ONE autonomous coding run — register a live agent session, dispatch the job to the bot-gateway sandbox runtime, mirror the sandbox's progress into the session live, verify the pushed branch landed in native git, and open a native "PR" work item — then returns a Result the trigger surface (Slack today, console/API tomorrow) renders.
It is a LEAF, transport-agnostic library. It touches its collaborators only through interface seams (Sessions, Tracker, Runner) plus two git functions (CloneURL, VerifyRef), so the whole orchestration is unit-testable with fakes and — critically — coding does NOT import clients/git: git imports clients/integrations, integrations calls coding, so coding->git would cycle. The composition root assembles the real Dispatcher (adapters.go) and injects it into the trigger surface.
ISOLATION: org is the ONLY tenant key and is threaded to every seam call (session, tracker, git, and the bot-gateway X-Org-Id). A run for org A can only ever open A's session, read/verify A's repo, and file A's PR. The clone URL is built from (org, repo) so the sandbox is pointed only at this org's namespace, and the credential (write-only) is scoped by IAM to this org at the edge.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Dispatcher ¶
type Dispatcher struct {
Sessions Sessions
Tracker Tracker
Runner Runner
CloneURL func(org, repo string) string
VerifyRef func(ctx context.Context, org, repo, branch string) (string, bool)
// Log is an optional structured log seam for best-effort mirror failures; nil
// is fine (mirror failures are non-fatal and simply dropped).
Log func(msg string, kv ...any)
}
Dispatcher wires the seams. The two git functions are injected (not an interface) because they are pure reads with no cloud-side state.
func NewDispatcher ¶
func NewDispatcher( cloneURL func(org, repo string) string, verifyRef func(ctx context.Context, org, repo, branch string) (string, bool), log func(msg string, kv ...any), ) Dispatcher
NewDispatcher assembles the production Dispatcher: sessions on the live agent registry, PRs on the tracker, the runner on coding's own runtime stub, plus the two git seams (cloneURL, verifyRef) the composition root passes from clients/git (which coding cannot import directly). log is the structured logger for best-effort mirror failures.
type PRInput ¶
type PRInput struct {
Org string
Project string
Repo string
Base string
Head string
Title string
Body string
Assignee string
}
PRInput / PRRef mirror tracker's agent-PR shape without leaking its types into the seam (the adapter bridges).
type Req ¶
type Req struct {
Org string
UserID string // linked Hanzo subject — session attribution + X-User-Id
AgentRef string // agent label (e.g. "hanzo")
Repo string
Project string // IAM project slug (tracker + git scope); "" = org default
Base string // base branch; "" = repo default
Prompt string
CredUser string
CredToken string
TimeoutSeconds int
}
Req is one coding request the trigger surface dispatches. Credential is the per-org agent git secret the caller resolved from KMS fail-closed; it is relayed to the sandbox and NEVER logged or placed in a session event.
type Result ¶
type Result struct {
SessionID string
Repo string
Branch string
CommitSha string
Diffstat string
Changed bool
OK bool
Verified bool // pushed branch confirmed present in native git
PR PRRef
LogTail string
Error string
}
Result is the terminal outcome the trigger surface renders.
type RunRequest ¶
type RunRequest struct {
CloneURL string
BaseBranch string
Branch string
Prompt string
SessionID string
RunTimeoutSeconds int
CredUser string
CredToken string // write-only secret — never logged
}
RunRequest / Step / RunResult mirror the bot coding contract.
type Runner ¶
type Runner interface {
Run(ctx context.Context, org, userID string, req RunRequest, onStep func(Step)) (RunResult, error)
}
Runner is the bot-gateway coding-task seam (clients/bot in-process client).
type Sessions ¶
type Sessions interface {
Open(ctx context.Context, org, actor, agent, title string) (string, error)
Log(ctx context.Context, org, sessionID, kind, actor string, payload []byte) error
Close(ctx context.Context, org, sessionID, status string) error
}
Sessions is the live agent-session registry seam (clients/agents in-process).