@tangle-network/agent-runtime 0.103.1 → 0.104.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/dist/agent.d.ts +1 -1
- package/dist/agent.js +5 -5
- package/dist/analyst-loop.d.ts +1 -1
- package/dist/{chunk-TUSOOIDV.js → chunk-2QJSNOGK.js} +2 -2
- package/dist/{chunk-ZOYN3JR5.js → chunk-2UABGGUB.js} +3 -3
- package/dist/{chunk-6WZZXQV5.js → chunk-2X65HYMI.js} +1 -1
- package/dist/chunk-2X65HYMI.js.map +1 -0
- package/dist/{chunk-AAN2MB2X.js → chunk-3PPVCS75.js} +3 -3
- package/dist/chunk-3PPVCS75.js.map +1 -0
- package/dist/{chunk-EAQ5YRRY.js → chunk-5HNDYWUT.js} +39 -22
- package/dist/chunk-5HNDYWUT.js.map +1 -0
- package/dist/{chunk-3LJF5XSE.js → chunk-ATDFUJYI.js} +6 -6
- package/dist/chunk-ATDFUJYI.js.map +1 -0
- package/dist/{chunk-LFM4JBRW.js → chunk-FJI3EXU3.js} +46 -5
- package/dist/chunk-FJI3EXU3.js.map +1 -0
- package/dist/{chunk-5AITUUHO.js → chunk-HAO4CXHP.js} +2 -2
- package/dist/{chunk-M6MD6JBS.js → chunk-KRBFHMV6.js} +429 -1
- package/dist/chunk-KRBFHMV6.js.map +1 -0
- package/dist/{chunk-AYU35OTU.js → chunk-PZZKQVQV.js} +1 -1
- package/dist/chunk-PZZKQVQV.js.map +1 -0
- package/dist/{chunk-QYCKIV6C.js → chunk-STJEHM5F.js} +2 -2
- package/dist/{completion-gate-DLINnrkM.d.ts → completion-gate-Bv47cOnn.d.ts} +2 -2
- package/dist/{coordination-DTehA977.d.ts → coordination-CxtzMxSM.d.ts} +27 -27
- package/dist/environment-provider.d.ts +18 -7
- package/dist/environment-provider.js +3 -1
- package/dist/{improve-B40dRu0X.d.ts → improve--2A0gK1-.d.ts} +10 -4
- package/dist/index.d.ts +13 -13
- package/dist/index.js +10 -10
- package/dist/index.js.map +1 -1
- package/dist/intelligence.d.ts +46 -9
- package/dist/intelligence.js +117 -20
- package/dist/intelligence.js.map +1 -1
- package/dist/knowledge.d.ts +5 -5
- package/dist/knowledge.js +7 -7
- package/dist/{loop-runner-bin-DhIXsLAd.d.ts → loop-runner-bin-DUOGtvOl.d.ts} +3 -3
- package/dist/loop-runner-bin.d.ts +5 -5
- package/dist/loop-runner-bin.js +6 -6
- package/dist/loops.d.ts +66 -41
- package/dist/loops.js +9 -5
- package/dist/mcp/bin.js +4 -4
- package/dist/mcp/index.d.ts +6 -6
- package/dist/mcp/index.js +10 -10
- package/dist/mcp/index.js.map +1 -1
- package/dist/primeintellect/index.d.ts +1 -1
- package/dist/primeintellect/index.js.map +1 -1
- package/dist/profiles.d.ts +6 -6
- package/dist/profiles.js.map +1 -1
- package/dist/{structural-rollout-BFPIy3iw.d.ts → structural-rollout-C4mabf87.d.ts} +3 -3
- package/dist/{supervise-Cp8bNcJi.d.ts → supervise-7q9F5brx.d.ts} +3 -3
- package/dist/testing.js +8 -8
- package/dist/testing.js.map +1 -1
- package/dist/{types-DK11_O4L.d.ts → types-BCoemcXU.d.ts} +4 -4
- package/dist/{types-lZTE_LBd.d.ts → types-CvNwMzQt.d.ts} +4 -4
- package/dist/{worktree-fanout-DiiJWjJO.d.ts → worktree-fanout-WsOzt8qu.d.ts} +5 -5
- package/package.json +3 -3
- package/dist/chunk-3LJF5XSE.js.map +0 -1
- package/dist/chunk-6WZZXQV5.js.map +0 -1
- package/dist/chunk-AAN2MB2X.js.map +0 -1
- package/dist/chunk-AYU35OTU.js.map +0 -1
- package/dist/chunk-EAQ5YRRY.js.map +0 -1
- package/dist/chunk-LFM4JBRW.js.map +0 -1
- package/dist/chunk-M6MD6JBS.js.map +0 -1
- /package/dist/{chunk-TUSOOIDV.js.map → chunk-2QJSNOGK.js.map} +0 -0
- /package/dist/{chunk-ZOYN3JR5.js.map → chunk-2UABGGUB.js.map} +0 -0
- /package/dist/{chunk-5AITUUHO.js.map → chunk-HAO4CXHP.js.map} +0 -0
- /package/dist/{chunk-QYCKIV6C.js.map → chunk-STJEHM5F.js.map} +0 -0
|
@@ -5,10 +5,10 @@ import {
|
|
|
5
5
|
definePersona,
|
|
6
6
|
runPersonified,
|
|
7
7
|
worktreeFanout
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-ATDFUJYI.js";
|
|
9
9
|
import {
|
|
10
10
|
createExecutorRegistry
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-5HNDYWUT.js";
|
|
12
12
|
import {
|
|
13
13
|
runAnalystLoop
|
|
14
14
|
} from "./chunk-FD2MBMOH.js";
|
|
@@ -196,4 +196,4 @@ export {
|
|
|
196
196
|
runLoopRunnerCli,
|
|
197
197
|
parseLoopRunnerArgv
|
|
198
198
|
};
|
|
199
|
-
//# sourceMappingURL=chunk-
|
|
199
|
+
//# sourceMappingURL=chunk-3PPVCS75.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/loop-runner.ts","../src/loop-runner-bin.ts"],"sourcesContent":["/**\n *\n * `runDelegatedLoop` — the configured delegated loop-runner.\n *\n * One typed entrypoint a worker agent (or a scheduled routine) calls to run a\n * disciplined loop in a chosen MODE, over agent-runtime's hardened engines:\n *\n * code → build-in-a-loop on the GENERIC recursive path (worktreeLoopRunner: author one\n * `AgentProfile` per harness → worktree-CLI leaves → `patchDelivered` gate)\n * review → caller-registered runner — a `code` runner with an approval gate over candidates\n * research → research-in-a-loop with valid-only KB growth (createKbGate)\n * audit → analyze trace/run data → findings (runAnalystLoop, caller-wired)\n * self-improve → closed-loop text/config optimization (selfImprove, held-out gated)\n *\n * It is intentionally a thin façade: the value is that EVERY product reuses the\n * one hardened engine instead of forking delegation logic. The dispatcher owns\n * mode routing, timing, fail-loud on an unregistered mode, and a uniform result\n * shape; each mode's engine is a pre-configured runner in the registry (build it\n * with the factories below, or inject your own / a stub).\n *\n * @experimental\n */\n\nimport type { Scenario } from '@tangle-network/agent-eval/campaign'\nimport {\n type SelfImproveOptions,\n type SelfImproveResult,\n selfImprove,\n} from '@tangle-network/agent-eval/contract'\nimport { runAnalystLoop } from './analyst-loop'\nimport type { RunAnalystLoopOpts, RunAnalystLoopResult } from './analyst-loop/types'\nimport { ConfigError } from './errors'\nimport { type CreateKbGateOptions, createKbGate, type FactCandidate } from './mcp/kb-gate'\nimport {\n type AuthoredHarness,\n type Budget,\n createExecutorRegistry,\n definePersona,\n runPersonified,\n type WinnerStrategy,\n type WorktreeFanoutOptions,\n type WorktreePatchArtifact,\n worktreeFanout,\n} from './runtime'\n\n/** All valid delegated-loop mode names — used for validation and CLI surfaces. @experimental */\nexport const DELEGATED_LOOP_MODES = ['code', 'review', 'research', 'audit', 'self-improve'] as const\n\n/** @experimental */\nexport type DelegatedLoopMode = (typeof DELEGATED_LOOP_MODES)[number]\n\n/** Type guard — returns true when `value` is a valid `DelegatedLoopMode` string. @experimental */\nexport function isDelegatedLoopMode(value: unknown): value is DelegatedLoopMode {\n return typeof value === 'string' && (DELEGATED_LOOP_MODES as readonly string[]).includes(value)\n}\n\n/** @experimental A pre-configured loop for one mode. Returns the mode's raw\n * output; the dispatcher wraps it in a {@link DelegatedLoopResult}. */\nexport type DelegatedLoopRunner<T = unknown> = (signal: AbortSignal) => Promise<T>\n\n/** @experimental Mode → configured runner. Partial: only register the modes a\n * given product/routine actually uses. */\nexport type DelegatedLoopRegistry = Partial<Record<DelegatedLoopMode, DelegatedLoopRunner>>\n\n/** @experimental Uniform result — never throws from a registered runner; a\n * thrown engine becomes `{ ok: false, error }` so a routine can record + move on. */\nexport interface DelegatedLoopResult<T = unknown> {\n mode: DelegatedLoopMode\n ok: boolean\n output?: T\n error?: string\n durationMs: number\n}\n\n/** @experimental */\nexport interface RunDelegatedLoopOptions {\n signal?: AbortSignal\n /** Clock override for deterministic tests. */\n now?: () => number\n}\n\n/**\n *\n * Dispatch a configured loop by mode. Fails loud (throws `ConfigError`) when no\n * runner is registered for the mode — a routine pointed at an unwired mode is a\n * config bug, not a silent no-op. A runner that throws is captured as\n * `{ ok: false }` so unattended runs record the failure rather than crash.\n *\n * @experimental\n */\nexport async function runDelegatedLoop<T = unknown>(\n mode: DelegatedLoopMode,\n registry: DelegatedLoopRegistry,\n options: RunDelegatedLoopOptions = {},\n): Promise<DelegatedLoopResult<T>> {\n const runner = registry[mode] as DelegatedLoopRunner<T> | undefined\n if (!runner) {\n throw new ConfigError(\n `runDelegatedLoop: no runner registered for mode '${mode}' (registered: ${\n Object.keys(registry).join(', ') || 'none'\n })`,\n )\n }\n const now = options.now ?? Date.now\n const signal = options.signal ?? new AbortController().signal\n const start = now()\n try {\n const output = await runner(signal)\n return { mode, ok: true, output, durationMs: now() - start }\n } catch (err) {\n return {\n mode,\n ok: false,\n error: err instanceof Error ? err.message : String(err),\n durationMs: now() - start,\n }\n }\n}\n\n/** @experimental Options for the local-repo `code` runner over the GENERIC recursive path. */\nexport interface WorktreeLoopRunnerOptions {\n /** Absolute path to the local git checkout each worktree is cut from. */\n repoRoot: string\n /** The instruction handed to every authored harness (composed under each profile's systemPrompt). */\n taskPrompt: string\n /** The supervisor-authored harness profiles — one fanout item (one worktree-CLI leaf) each. */\n harnesses: ReadonlyArray<AuthoredHarness>\n /** Conserved budget pool bounding the fanout (equal-k holds by construction). */\n budget: Budget\n /** Shell command run in each worktree to derive the tests-PASS signal. */\n testCmd?: string\n /** Shell command run in each worktree to derive the typecheck-PASS signal. */\n typecheckCmd?: string\n /** Which verification signals the deliverable REQUIRES present-and-passing (default none). */\n require?: ReadonlyArray<'tests' | 'typecheck'>\n /** Diff-size cap (lines). */\n maxDiffLines?: number\n /** Literal path prefixes the patch must not touch (the secret-floor is always on regardless). */\n forbiddenPaths?: string[]\n /** Winner-selection strategy among gated candidates. Default `highest-score`. */\n winnerStrategy?: WinnerStrategy\n /** Test seams forwarded to the worktree-CLI leaves so the runner drives offline. */\n runGit?: WorktreeFanoutOptions['runGit']\n runHarness?: WorktreeFanoutOptions['runHarness']\n runCommand?: WorktreeFanoutOptions['runCommand']\n}\n\n/**\n *\n * `code` mode on the GENERIC recursive path: author one `AgentProfile` per harness, run them as a\n * `worktreeFanout` (N `createWorktreeCliExecutor` leaves, each `gateOnDeliverable`) through\n * `runPersonified` on the keystone Supervisor. The sandbox-session counterpart that drives the in-box\n * harness over a `SandboxClient` is `detachedSessionDelegate` (`./mcp/delegates`); here there is no\n * `runAgentRounds` driver, no role-coupled delegate — the harness list is the fanout, the gate is\n * `patchDelivered`,\n * the winner is the shared valid-only selector (NOT `defaultSelectWinner`, whose non-valid fallback\n * would surface an ungated patch). Equal-k holds by the conserved budget pool. Returns the winning\n * patch artifact, or throws when no candidate is delivered (fail loud, never a vacuous done).\n *\n * @experimental\n */\nexport function worktreeLoopRunner(\n options: WorktreeLoopRunnerOptions,\n): DelegatedLoopRunner<WorktreePatchArtifact> {\n const shape = worktreeFanout<string>({\n repoRoot: options.repoRoot,\n taskPrompt: options.taskPrompt,\n harnesses: options.harnesses,\n ...(options.testCmd !== undefined ? { testCmd: options.testCmd } : {}),\n ...(options.typecheckCmd !== undefined ? { typecheckCmd: options.typecheckCmd } : {}),\n ...(options.require !== undefined ? { require: options.require } : {}),\n ...(options.maxDiffLines !== undefined ? { maxDiffLines: options.maxDiffLines } : {}),\n ...(options.forbiddenPaths !== undefined ? { forbiddenPaths: options.forbiddenPaths } : {}),\n ...(options.winnerStrategy !== undefined ? { winnerStrategy: options.winnerStrategy } : {}),\n ...(options.runGit ? { runGit: options.runGit } : {}),\n ...(options.runHarness ? { runHarness: options.runHarness } : {}),\n ...(options.runCommand ? { runCommand: options.runCommand } : {}),\n })\n // The persona's only role here is to carry the fanout shape onto the Supervisor; each item's\n // executor is BYO (the gated worktree-CLI leaf), so the registry only needs to pass BYO through.\n const persona = definePersona<WorktreePatchArtifact>({\n name: 'worktree-coder',\n root: { profile: { name: 'worktree-coder' }, harness: null },\n directive: 'deliver a minimal validated patch on a fresh worktree',\n context: { role: 'coder' },\n executors: { registry: createExecutorRegistry() },\n })\n return async (signal) => {\n const result = await runPersonified<string, WorktreePatchArtifact>({\n persona,\n shape,\n task: options.taskPrompt,\n budget: options.budget,\n signal,\n })\n if (result.kind !== 'winner' || result.out.kind !== 'done') {\n const blockers =\n result.kind === 'winner' && result.out.kind === 'blocked'\n ? result.out.blockers.join('; ')\n : `supervisor settled ${result.kind}`\n throw new Error(`worktreeLoopRunner: no delivered patch (${blockers})`)\n }\n return result.out.deliverable\n }\n}\n\n/** @experimental A fact rejected at the KB gate — surfaced, never dropped. */\nexport interface VetoedFact {\n candidate: FactCandidate\n vetoedBy?: string\n reason?: string\n}\n\n/** @experimental */\nexport interface ResearchLoopResult {\n /** Facts that passed the fail-closed gate — safe to write to the KB. */\n accepted: FactCandidate[]\n /** Facts the gate vetoed in the final round — escalate, do not silently drop. */\n vetoed: VetoedFact[]\n /** Research rounds actually run. */\n rounds: number\n}\n\n/** @experimental Options for the default `research` runner. */\nexport interface ResearchLoopRunnerOptions {\n /**\n * The research engine (the consumer's web/doc searcher + extractor). Called\n * each round with the prior round's vetoes so it can re-research the gaps.\n * Returns fact candidates carrying their grounding (`verbatimPassage` +\n * `sourceText`).\n */\n research: (round: number, vetoed: VetoedFact[]) => Promise<FactCandidate[]>\n /** Gate config (extra judges, self-artifact kinds, …). The floor is always on. */\n gate?: CreateKbGateOptions\n /** Max research rounds (correct-on-veto remediation). Default 1. */\n maxRounds?: number\n}\n\n/**\n * `research` mode — research-in-a-loop with valid-only KB growth.\n *\n * Each round: research → gate every candidate (fail-closed; passage MUST be in\n * the source) → accept the clean ones → re-research the vetoed ones next round,\n * up to `maxRounds`. Vetoed facts in the final round are RETURNED (escalate,\n * never silently dropped) so the caller audits vs retries.\n *\n * @experimental\n */\nexport function researchLoopRunner(\n o: ResearchLoopRunnerOptions,\n): DelegatedLoopRunner<ResearchLoopResult> {\n const gate = createKbGate(o.gate)\n const maxRounds = Math.max(1, Math.trunc(o.maxRounds ?? 1))\n return async (signal) => {\n const accepted: FactCandidate[] = []\n let vetoed: VetoedFact[] = []\n let rounds = 0\n for (let round = 0; round < maxRounds; round += 1) {\n if (signal.aborted) break\n rounds += 1\n const candidates = await o.research(round, vetoed)\n if (candidates.length === 0) break\n vetoed = []\n for (const c of candidates) {\n const v = await gate(c)\n if (v.accepted) accepted.push(c)\n else vetoed.push({ candidate: c, vetoedBy: v.vetoedBy, reason: v.reason })\n }\n if (vetoed.length === 0) break\n }\n return { accepted, vetoed, rounds }\n }\n}\n\n/**\n * `self-improve` mode — agent-eval's one-call closed improvement loop (held-out gated).\n *\n * @experimental\n */\nexport function selfImproveLoopRunner<TScenario extends Scenario, TArtifact>(\n options: SelfImproveOptions<TScenario, TArtifact>,\n): DelegatedLoopRunner<SelfImproveResult<TScenario, TArtifact>> {\n return async () => selfImprove<TScenario, TArtifact>(options)\n}\n\n/**\n * `audit` mode — analyst loop over captured trace/run data.\n *\n * @experimental\n */\nexport function auditLoopRunner<TProposal = unknown, TEdit = unknown>(\n options: RunAnalystLoopOpts,\n): DelegatedLoopRunner<RunAnalystLoopResult<TProposal, TEdit>> {\n return async () => runAnalystLoop<TProposal, TEdit>(options)\n}\n","#!/usr/bin/env node\n/**\n *\n * `agent-runtime-loop` — the schedulable entrypoint for the configured\n * delegated loop-runner. A cron job / routine / Makefile target invokes:\n *\n * agent-runtime-loop --mode research --config ./loops.config.js\n *\n * The config module wires the registry (with full access to env / creds —\n * which is why the deps live there, not in this generic bin). It must default-\n * export a `DelegatedLoopRegistry`, or a `() => DelegatedLoopRegistry | Promise<…>`.\n * The bin runs the selected mode, prints the `DelegatedLoopResult` as JSON, and\n * exits 0 on `ok`, 1 on a recorded failure, 2 on a usage/config error.\n *\n * @experimental\n */\n\nimport {\n DELEGATED_LOOP_MODES,\n type DelegatedLoopMode,\n type DelegatedLoopRegistry,\n type DelegatedLoopResult,\n isDelegatedLoopMode,\n runDelegatedLoop,\n} from './loop-runner'\n\n/** @experimental Parsed CLI invocation. */\nexport interface LoopRunnerCliArgs {\n mode: string\n /** Loads the registry — the bin wires this from `--config`; tests inject a stub. */\n loadRegistry: () => Promise<DelegatedLoopRegistry> | DelegatedLoopRegistry\n now?: () => number\n}\n\n/** @experimental */\nexport interface LoopRunnerCliResult {\n exitCode: number\n result?: DelegatedLoopResult\n error?: string\n}\n\n/**\n *\n * Pure CLI core (no process / argv / IO) so it's unit-testable: validate the\n * mode, load the registry, dispatch, map to an exit code (0 ok / 1 failed /\n * 2 usage). Exported for embedding in custom runners + tests.\n *\n * @experimental\n */\nexport async function runLoopRunnerCli(args: LoopRunnerCliArgs): Promise<LoopRunnerCliResult> {\n if (!isDelegatedLoopMode(args.mode)) {\n return {\n exitCode: 2,\n error: `unknown mode '${args.mode}' (expected one of: ${DELEGATED_LOOP_MODES.join(', ')})`,\n }\n }\n let registry: DelegatedLoopRegistry\n try {\n registry = await args.loadRegistry()\n } catch (err) {\n return { exitCode: 2, error: `failed to load registry: ${errMsg(err)}` }\n }\n if (!registry[args.mode]) {\n return {\n exitCode: 2,\n error: `config registers no runner for mode '${args.mode}' (registered: ${\n Object.keys(registry).join(', ') || 'none'\n })`,\n }\n }\n // runDelegatedLoop throws only on a missing runner (guarded above); a failing\n // engine is captured as { ok: false } → exit 1, not a crash.\n const result = await runDelegatedLoop(args.mode as DelegatedLoopMode, registry, {\n ...(args.now ? { now: args.now } : {}),\n })\n return { exitCode: result.ok ? 0 : 1, result }\n}\n\n/** Parse `--mode X --config Y` from an argv tail (`process.argv.slice(2)`). */\nexport function parseLoopRunnerArgv(argv: string[]): { mode?: string; config?: string } {\n const out: { mode?: string; config?: string } = {}\n for (let i = 0; i < argv.length; i += 1) {\n const a = argv[i]\n if (a === '--mode') out.mode = argv[++i]\n else if (a === '--config') out.config = argv[++i]\n else if (a?.startsWith('--mode=')) out.mode = a.slice('--mode='.length)\n else if (a?.startsWith('--config=')) out.config = a.slice('--config='.length)\n }\n return out\n}\n\n/** Normalize a config module's default export → a registry. */\nfunction resolveRegistry(mod: unknown): DelegatedLoopRegistry {\n const def = (mod as { default?: unknown })?.default ?? mod\n const value = typeof def === 'function' ? (def as () => unknown)() : def\n return value as DelegatedLoopRegistry\n}\n\nfunction errMsg(err: unknown): string {\n return err instanceof Error ? err.message : String(err)\n}\n\n/** The argv → IO → exit shell. Kept thin; logic lives in `runLoopRunnerCli`. */\nasync function main(): Promise<void> {\n const { mode, config } = parseLoopRunnerArgv(process.argv.slice(2))\n if (!mode || !config) {\n process.stderr.write(\n 'usage: agent-runtime-loop --mode <mode> --config <module>\\n' +\n ` modes: ${DELEGATED_LOOP_MODES.join(' | ')}\\n` +\n ' config: a JS/TS module default-exporting a DelegatedLoopRegistry (or a factory)\\n',\n )\n process.exit(2)\n }\n const { pathToFileURL } = await import('node:url')\n const { resolve } = await import('node:path')\n const cli = await runLoopRunnerCli({\n mode,\n loadRegistry: async () => resolveRegistry(await import(pathToFileURL(resolve(config)).href)),\n })\n process.stdout.write(`${JSON.stringify(cli.result ?? { error: cli.error }, null, 2)}\\n`)\n if (cli.error) process.stderr.write(`${cli.error}\\n`)\n process.exit(cli.exitCode)\n}\n\n// Run only when executed as the bin — never when imported for the testable\n// core, and never when bundled into a runtime that has no `process.argv`\n// (e.g. Cloudflare Workers, where `process` is a shim without `argv`). Reading\n// `process.argv[1]` directly would throw at module load there; `process.argv?.`\n// keeps the guard a no-op instead of crashing the Worker on startup.\nconst invokedScript = typeof process !== 'undefined' ? process.argv?.[1] : undefined\nif (invokedScript && /loop-runner-bin\\.(js|ts|mjs)$/.test(invokedScript)) {\n void main()\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAwBA;AAAA,EAGE;AAAA,OACK;AAkBA,IAAM,uBAAuB,CAAC,QAAQ,UAAU,YAAY,SAAS,cAAc;AAMnF,SAAS,oBAAoB,OAA4C;AAC9E,SAAO,OAAO,UAAU,YAAa,qBAA2C,SAAS,KAAK;AAChG;AAoCA,eAAsB,iBACpB,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,IAAI,MAAO,SAAQ,OAAO,MAAM,GAAG,IAAI,KAAK;AAAA,CAAI;AACpD,UAAQ,KAAK,IAAI,QAAQ;AAC3B;AAOA,IAAM,gBAAgB,OAAO,YAAY,cAAc,QAAQ,OAAO,CAAC,IAAI;AAC3E,IAAI,iBAAiB,gCAAgC,KAAK,aAAa,GAAG;AACxE,OAAK,KAAK;AACZ;","names":[]}
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
runWorktreeChecks,
|
|
19
19
|
runWorktreeHarness,
|
|
20
20
|
withDriverExecutor
|
|
21
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-2X65HYMI.js";
|
|
22
22
|
import {
|
|
23
23
|
FileResultBlobStore,
|
|
24
24
|
FileSpawnJournal,
|
|
@@ -29,7 +29,7 @@ import {
|
|
|
29
29
|
import {
|
|
30
30
|
providerAsExecutor,
|
|
31
31
|
resolveAgentEnvironmentProvider
|
|
32
|
-
} from "./chunk-
|
|
32
|
+
} from "./chunk-KRBFHMV6.js";
|
|
33
33
|
import {
|
|
34
34
|
addTokenUsage,
|
|
35
35
|
deleteBoxSafe,
|
|
@@ -69,6 +69,17 @@ function gateOnDeliverable(inner, deliverable) {
|
|
|
69
69
|
runtime: inner.runtime,
|
|
70
70
|
...inner.budgetExempt !== void 0 ? { budgetExempt: inner.budgetExempt } : {},
|
|
71
71
|
...inner.deliver ? { deliver: (m) => inner.deliver?.(m) } : {},
|
|
72
|
+
// Forward the OPTIONAL live-observation surfaces so a gated worker stays supervisable
|
|
73
|
+
// mid-flight. The scope captures `progress`/`traceSource` at spawn and only if the executor
|
|
74
|
+
// exposes them; a gate that drops them makes `observe_agent` read `recentActivity:[]` and
|
|
75
|
+
// loses online detection for a running worker (it saw the tokens/turns the fold derives, but
|
|
76
|
+
// none of the harness's own turn count or tool activity). `metered` is a driver-executor's
|
|
77
|
+
// OWN-inference subtree total, re-homed by the parent on settle — dropping it would leak a
|
|
78
|
+
// gated sub-driver's inference out of the journal. Preserve the "undefined ⟺ not implemented"
|
|
79
|
+
// contract: only expose a method the inner executor actually implements.
|
|
80
|
+
...inner.progress ? { progress: () => inner.progress?.() } : {},
|
|
81
|
+
...inner.traceSource ? { traceSource: () => inner.traceSource?.() } : {},
|
|
82
|
+
...inner.metered ? { metered: () => inner.metered?.() } : {},
|
|
72
83
|
execute(task, signal) {
|
|
73
84
|
const r = inner.execute(task, signal);
|
|
74
85
|
if (isAsyncIterable(r)) {
|
|
@@ -369,19 +380,19 @@ async function destroyBounded(box) {
|
|
|
369
380
|
// src/runtime/run-loop.ts
|
|
370
381
|
var DEFAULT_MAX_ITERATIONS = 10;
|
|
371
382
|
var DEFAULT_MAX_CONCURRENCY = 4;
|
|
372
|
-
async function
|
|
383
|
+
async function runAgentRounds(options) {
|
|
373
384
|
const specs = resolveAgentRuns(options);
|
|
374
385
|
const maxIterations = options.maxIterations ?? DEFAULT_MAX_ITERATIONS;
|
|
375
386
|
if (!Number.isFinite(maxIterations) || maxIterations <= 0) {
|
|
376
|
-
throw new ValidationError("
|
|
387
|
+
throw new ValidationError("runAgentRounds: maxIterations must be > 0");
|
|
377
388
|
}
|
|
378
389
|
const maxConcurrency = options.maxConcurrency ?? DEFAULT_MAX_CONCURRENCY;
|
|
379
390
|
if (!Number.isFinite(maxConcurrency) || maxConcurrency <= 0) {
|
|
380
|
-
throw new ValidationError("
|
|
391
|
+
throw new ValidationError("runAgentRounds: maxConcurrency must be > 0");
|
|
381
392
|
}
|
|
382
393
|
const sandboxStreaming = options.lineage?.streaming ?? "sse";
|
|
383
394
|
if (!options.ctx?.sandboxClient || typeof options.ctx.sandboxClient.create !== "function") {
|
|
384
|
-
throw new ValidationError("
|
|
395
|
+
throw new ValidationError("runAgentRounds: ctx.sandboxClient.create is required");
|
|
385
396
|
}
|
|
386
397
|
const now = options.now ?? Date.now;
|
|
387
398
|
const runId = options.runId ?? `loop-${randomSuffix()}`;
|
|
@@ -559,12 +570,13 @@ async function runLoop(options) {
|
|
|
559
570
|
if (lineageState) await lineageState.lineage.teardown();
|
|
560
571
|
}
|
|
561
572
|
}
|
|
573
|
+
var runLoop = runAgentRounds;
|
|
562
574
|
async function setUpLineage(options, maxConcurrency, recordMount) {
|
|
563
575
|
const lineageOpts = options.lineage;
|
|
564
576
|
if (!lineageOpts || !lineageOpts.sessionContinuity && !lineageOpts.forkFanout) return void 0;
|
|
565
577
|
if (options.onWorkerBox) {
|
|
566
578
|
throw new ValidationError(
|
|
567
|
-
"
|
|
579
|
+
"runAgentRounds: `lineage` and `onWorkerBox` both own worker boxes \u2014 pass only one"
|
|
568
580
|
);
|
|
569
581
|
}
|
|
570
582
|
const capabilities = await probeSandboxCapabilities(options.ctx.sandboxClient);
|
|
@@ -584,12 +596,14 @@ function planLineageRound(state, specs, slice, parentIndex, signal) {
|
|
|
584
596
|
const parent = parentIndex !== void 0 ? state.handles.get(parentIndex) : void 0;
|
|
585
597
|
const promptFor = (offset) => {
|
|
586
598
|
const spec = specs[offset % specs.length];
|
|
587
|
-
if (!spec)
|
|
599
|
+
if (!spec)
|
|
600
|
+
throw new ValidationError("runAgentRounds: no AgentRunSpec available for lineage iteration");
|
|
588
601
|
return spec.taskToPrompt(slice[offset]);
|
|
589
602
|
};
|
|
590
603
|
const specAt = (offset) => {
|
|
591
604
|
const spec = specs[offset % specs.length];
|
|
592
|
-
if (!spec)
|
|
605
|
+
if (!spec)
|
|
606
|
+
throw new ValidationError("runAgentRounds: no AgentRunSpec available for lineage iteration");
|
|
593
607
|
return spec;
|
|
594
608
|
};
|
|
595
609
|
if (slice.length === 1 && parent && state.options.sessionContinuity) {
|
|
@@ -615,7 +629,7 @@ function planLineageRound(state, specs, slice, parentIndex, signal) {
|
|
|
615
629
|
const branches = await ensureForked();
|
|
616
630
|
const branch = branches[offset];
|
|
617
631
|
if (!branch)
|
|
618
|
-
throw new ValidationError("
|
|
632
|
+
throw new ValidationError("runAgentRounds: lineage fork produced no branch for offset");
|
|
619
633
|
return branch;
|
|
620
634
|
}
|
|
621
635
|
}));
|
|
@@ -673,9 +687,9 @@ async function runBatch(args) {
|
|
|
673
687
|
async function executeIteration(args) {
|
|
674
688
|
const slot = args.iterations[args.item.index];
|
|
675
689
|
if (!slot)
|
|
676
|
-
throw new ValidationError(`
|
|
690
|
+
throw new ValidationError(`runAgentRounds: missing iteration slot at index ${args.item.index}`);
|
|
677
691
|
const spec = args.specs[args.item.index % args.specs.length];
|
|
678
|
-
if (!spec) throw new ValidationError("
|
|
692
|
+
if (!spec) throw new ValidationError("runAgentRounds: no AgentRunSpec available for iteration");
|
|
679
693
|
slot.startedAt = args.now();
|
|
680
694
|
slot.agentRunName = spec.name ?? spec.profile.name ?? "agent";
|
|
681
695
|
await emitTrace(args.ctx.traceEmitter, {
|
|
@@ -986,11 +1000,11 @@ function defaultSelectWinner(iterations) {
|
|
|
986
1000
|
}
|
|
987
1001
|
function resolveAgentRuns(options) {
|
|
988
1002
|
if (options.agentRun && options.agentRuns) {
|
|
989
|
-
throw new ValidationError("
|
|
1003
|
+
throw new ValidationError("runAgentRounds: pass exactly one of `agentRun` or `agentRuns`");
|
|
990
1004
|
}
|
|
991
1005
|
if (options.agentRun) return [options.agentRun];
|
|
992
1006
|
if (options.agentRuns && options.agentRuns.length > 0) return options.agentRuns;
|
|
993
|
-
throw new ValidationError("
|
|
1007
|
+
throw new ValidationError("runAgentRounds: `agentRun` or non-empty `agentRuns` is required");
|
|
994
1008
|
}
|
|
995
1009
|
function isTerminalDecision(decision) {
|
|
996
1010
|
return decision === "stop" || decision === "pick-winner" || decision === "fail" || decision === "done";
|
|
@@ -1301,9 +1315,9 @@ var piExecutor = (spec, ctx) => {
|
|
|
1301
1315
|
};
|
|
1302
1316
|
return {
|
|
1303
1317
|
runtime: PI_RUNTIME,
|
|
1304
|
-
// pi owns the queue; `deliver` only routes
|
|
1305
|
-
//
|
|
1306
|
-
//
|
|
1318
|
+
// pi owns the queue; `deliver` only routes through its state-safe `prompt` command. Its
|
|
1319
|
+
// streaming behavior chooses steer versus follow-up atomically in pi, rather than trusting
|
|
1320
|
+
// this adapter's delayed view of whether the current run has already ended.
|
|
1307
1321
|
deliver: (m) => inbox.deliver(m),
|
|
1308
1322
|
progress: () => ({
|
|
1309
1323
|
turns: state.turns,
|
|
@@ -1361,6 +1375,7 @@ async function* streamPiSession(args) {
|
|
|
1361
1375
|
};
|
|
1362
1376
|
const stdoutLines = readJsonLines(proc, (value) => {
|
|
1363
1377
|
const ev = value;
|
|
1378
|
+
if (ev.type === "agent_start") idle = false;
|
|
1364
1379
|
if (ev.type === "agent_end") idle = true;
|
|
1365
1380
|
events.push(ev);
|
|
1366
1381
|
notify();
|
|
@@ -1396,7 +1411,7 @@ ${taskText(args.task)}` : taskText(args.task);
|
|
|
1396
1411
|
sendCommand(proc, { type: "prompt", message: opening });
|
|
1397
1412
|
state.note = "turn 0";
|
|
1398
1413
|
for (; ; ) {
|
|
1399
|
-
forwardPending(proc, inbox, activity);
|
|
1414
|
+
if (!idle) forwardPending(proc, inbox, activity);
|
|
1400
1415
|
while (events.length > 0) {
|
|
1401
1416
|
const ev = events.shift();
|
|
1402
1417
|
for (const usage of projectPiEvent(ev, args, tokens)) {
|
|
@@ -1445,8 +1460,9 @@ function forwardPending(proc, inbox, activity) {
|
|
|
1445
1460
|
const pending = inbox.drain();
|
|
1446
1461
|
for (const m of pending) {
|
|
1447
1462
|
sendCommand(proc, {
|
|
1448
|
-
type:
|
|
1449
|
-
message: renderOne(m)
|
|
1463
|
+
type: "prompt",
|
|
1464
|
+
message: renderOne(m),
|
|
1465
|
+
streamingBehavior: m.interrupt ? "steer" : "followUp"
|
|
1450
1466
|
});
|
|
1451
1467
|
activity.push({
|
|
1452
1468
|
at: Date.now(),
|
|
@@ -2299,7 +2315,7 @@ async function* streamSandboxLeaf(args) {
|
|
|
2299
2315
|
...args.seam.lineage !== void 0 ? { lineage: args.seam.lineage } : {}
|
|
2300
2316
|
};
|
|
2301
2317
|
try {
|
|
2302
|
-
const result = await
|
|
2318
|
+
const result = await runAgentRounds(loopOptions);
|
|
2303
2319
|
const out = result.winner?.output ?? { events: [] };
|
|
2304
2320
|
const verdict = result.winner?.verdict;
|
|
2305
2321
|
const spent = {
|
|
@@ -6310,6 +6326,7 @@ export {
|
|
|
6310
6326
|
acquireSandbox,
|
|
6311
6327
|
probeSandboxCapabilities,
|
|
6312
6328
|
createSandboxLineage,
|
|
6329
|
+
runAgentRounds,
|
|
6313
6330
|
runLoop,
|
|
6314
6331
|
createSandboxForSpec,
|
|
6315
6332
|
defaultSelectWinner,
|
|
@@ -6404,4 +6421,4 @@ export {
|
|
|
6404
6421
|
workerFromBackend,
|
|
6405
6422
|
supervise
|
|
6406
6423
|
};
|
|
6407
|
-
//# sourceMappingURL=chunk-
|
|
6424
|
+
//# sourceMappingURL=chunk-5HNDYWUT.js.map
|