Documentation
¶
Overview ¶
Package coding orchestrates ONE autonomous coding run: open a live agent session, dispatch the job to the bot-gateway sandbox runtime, mirror the sandbox's progress into the session, verify the pushed branch landed in native git, open a native "PR" work item, and return a Result the caller renders.
It is a LIBRARY, not an app: no route, no plugin, no manifest row. Its one caller is apps/integrations (the Slack `code:` trigger). 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 apps/git: git imports apps/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 ¶
- func DeliverRoutedRunActivity(ctx context.Context, in agents.RoutedRun) (agents.RoutedResult, error)
- func RoutedRunWorkflow(ctx workflow.Context, in agents.RoutedRun) (agents.RoutedResult, error)
- type Dispatcher
- type PRInput
- type PRRef
- type Req
- type Result
- type RoutedResult
- type RoutedRun
- type RunRequest
- type RunResult
- type Runner
- type Sessions
- type Step
- type Tracker
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeliverRoutedRunActivity ¶
func DeliverRoutedRunActivity(ctx context.Context, in agents.RoutedRun) (agents.RoutedResult, error)
DeliverRoutedRunActivity offers the run to the live mailbox and blocks until the machine reports a terminal result or the budget elapses. It derives an internal deadline from the same budget so the goroutine can never outlive the activity even if the engine does not cancel the passed ctx exactly at StartToClose. Exported for worker registration; not called directly.
COMPLETION PARITY (#48): once the report is in hand, it runs the cloud-side completion (routedFinalizer) — VerifyRef the pushed branch landed, file the native PR, and CLOSE THE SESSION (the machine never closes it) — the SAME steps the local keystone path runs after a sandbox push. It runs on a cancel-immune, bounded context so a run near its deadline still transitions to terminal, and only AFTER a real report (never on the re-offer/timeout path), so a completed run is never re-executed by a retry.
func RoutedRunWorkflow ¶
RoutedRunWorkflow is the durable owner of one routed run. Exported for worker registration; not called directly.
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)
// Route enqueues a routed run on the durable engine (the tasks-engine binding
// in routed.go). Nil disables routing — a run with a TargetID then fails
// closed rather than silently running in the sandbox.
Route func(ctx context.Context, run RoutedRun) error
// TargetGate is the fail-closed liveness+existence check for a routed run's
// target (agents.TargetDispatchable): the target exists in this org, is
// online, and has a live runner. Nil disables routing.
TargetGate func(ctx context.Context, org, targetID string) error
}
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
TargetID string // when set, route to this registered machine instead of the sandbox
}
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.
TargetID, when set, ROUTES the run to a registered machine (#48): the run is enqueued as a durable task addressed to that target instead of executing in the cloud-side sandbox, and the credential is NOT used (the machine authenticates with its own). When empty, the local sandbox path runs unchanged.
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
// Routed reports that the run was ENQUEUED to a target machine rather than run
// in the cloud sandbox. When true, OK means "accepted + queued" (not
// "completed"): the terminal outcome flows through the session stream as the
// machine executes. TargetID is the machine it was routed to.
Routed bool
TargetID string
}
Result is the terminal outcome the trigger surface renders.
type RoutedResult ¶
type RoutedResult struct {
OK bool
Changed bool
Branch string
CommitSha string
Diffstat string
Error string
}
RoutedResult mirrors agents.RoutedResult so coding.go stays free of an agents import on the completion path (the adapter bridges). It is the terminal a machine reports.
type RoutedRun ¶
type RoutedRun struct {
Org string
TargetID string
SessionID string
Repo string
Project string
Base string
Branch string
Prompt string
CloneURL string
TimeoutSeconds int
// Actor + AgentRef are the dispatching user + agent label, carried so the durable
// completion path can attribute the session close and file the PR with the same
// assignee the local path uses. Neither is a secret and neither crosses to the
// machine (the durable view the machine claims omits them).
Actor string
AgentRef string
}
RoutedRun is the NON-SECRET spec coding hands the Route seam to enqueue on the durable engine. It mirrors agents.RoutedRun so coding.go stays pure (no agents import); the adapter bridges the two, exactly as PRInput/RunRequest mirror their downstream types. It carries no credential by design — the executing machine authenticates git + model routing with its own already-held creds.
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)
// OpenOn opens a session tagged with the run's dispatch TARGET, so a routed
// run shows in mission-control on the machine it was sent to. An empty target
// behaves exactly like Open.
OpenOn(ctx context.Context, org, actor, agent, title, target 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).