@caupulican/pi-adaptative 0.90.4 → 0.90.5
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/CHANGELOG.md +6 -0
- package/dist/core/autonomy/lane-tracker.d.ts +5 -0
- package/dist/core/autonomy/lane-tracker.d.ts.map +1 -1
- package/dist/core/autonomy/lane-tracker.js +8 -0
- package/dist/core/autonomy/lane-tracker.js.map +1 -1
- package/dist/core/delegation/worker-authority-resolver.d.ts +2 -0
- package/dist/core/delegation/worker-authority-resolver.d.ts.map +1 -1
- package/dist/core/delegation/worker-authority-resolver.js +23 -3
- package/dist/core/delegation/worker-authority-resolver.js.map +1 -1
- package/dist/core/delegation/worker-delegation-controller.d.ts +1 -1
- package/dist/core/delegation/worker-delegation-controller.d.ts.map +1 -1
- package/dist/core/delegation/worker-delegation-controller.js +48 -13
- package/dist/core/delegation/worker-delegation-controller.js.map +1 -1
- package/dist/core/delegation/worker-lane-projection.d.ts.map +1 -1
- package/dist/core/delegation/worker-lane-projection.js +6 -0
- package/dist/core/delegation/worker-lane-projection.js.map +1 -1
- package/dist/core/delegation/worker-profile-resolver.d.ts +28 -1
- package/dist/core/delegation/worker-profile-resolver.d.ts.map +1 -1
- package/dist/core/delegation/worker-profile-resolver.js +38 -9
- package/dist/core/delegation/worker-profile-resolver.js.map +1 -1
- package/dist/core/orchestration/worker-model-pins.d.ts +28 -0
- package/dist/core/orchestration/worker-model-pins.d.ts.map +1 -0
- package/dist/core/orchestration/worker-model-pins.js +141 -0
- package/dist/core/orchestration/worker-model-pins.js.map +1 -0
- package/dist/core/runtime-builder.d.ts.map +1 -1
- package/dist/core/runtime-builder.js +1 -0
- package/dist/core/runtime-builder.js.map +1 -1
- package/dist/core/settings-manager.d.ts +4 -1
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +24 -0
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/tools/delegate-status.d.ts +2 -0
- package/dist/core/tools/delegate-status.d.ts.map +1 -1
- package/dist/core/tools/delegate-status.js +7 -0
- package/dist/core/tools/delegate-status.js.map +1 -1
- package/dist/core/tools/delegate.d.ts +6 -0
- package/dist/core/tools/delegate.d.ts.map +1 -1
- package/dist/core/tools/delegate.js +38 -6
- package/dist/core/tools/delegate.js.map +1 -1
- package/docs/settings.md +31 -0
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/npm-shrinkwrap.json +12 -12
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
## [0.90.5] - 2026-08-12
|
|
2
|
+
|
|
3
|
+
### Added
|
|
4
|
+
|
|
5
|
+
- Added optional provider-neutral worker model pins with global-first role/default precedence, immutable fresh-worker and verifier admission, fail-closed validation and availability checks, effective-binding reporting, and zero provider prompt/routing overhead when unconfigured.
|
|
6
|
+
|
|
1
7
|
## [0.90.4] - 2026-08-12
|
|
2
8
|
|
|
3
9
|
## [0.90.3] - 2026-08-12
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* counts reflect lanes actually running in THIS process, never inferred/faked from historical
|
|
6
6
|
* snapshots. Terminal lane records are persisted separately via `session-lane-record.ts`.
|
|
7
7
|
*/
|
|
8
|
+
import { type OrchestrationThinkingLevel } from "../orchestration/contracts.ts";
|
|
8
9
|
export type LaneType = "research" | "worker" | "learning" | "tmux-worker";
|
|
9
10
|
export type LaneTerminalStatus = "succeeded" | "partial" | "blocked" | "failed" | "canceled" | "timeout" | "budget_exhausted";
|
|
10
11
|
export type LaneStatus = "queued" | "running" | LaneTerminalStatus;
|
|
@@ -16,6 +17,10 @@ export interface LaneRecord {
|
|
|
16
17
|
label?: string;
|
|
17
18
|
/** Owner-authored profile that fixed the worker's model, thinking, tools, and budget. */
|
|
18
19
|
profileId?: string;
|
|
20
|
+
/** Effective provider/model admitted into the immutable worker execution contract. */
|
|
21
|
+
modelRef?: string;
|
|
22
|
+
/** Effective thinking level admitted with modelRef. */
|
|
23
|
+
thinkingLevel?: OrchestrationThinkingLevel;
|
|
19
24
|
reasonCode?: string;
|
|
20
25
|
startedAt?: string;
|
|
21
26
|
completedAt?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lane-tracker.d.ts","sourceRoot":"","sources":["../../../src/core/autonomy/lane-tracker.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,MAAM,QAAQ,GAAG,UAAU,GAAG,QAAQ,GAAG,UAAU,GAAG,aAAa,CAAC;AAE1E,MAAM,MAAM,kBAAkB,GAC3B,WAAW,GACX,SAAS,GACT,SAAS,GACT,QAAQ,GACR,UAAU,GACV,SAAS,GACT,kBAAkB,CAAC;AAEtB,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,SAAS,GAAG,kBAAkB,CAAC;AAEnE,MAAM,WAAW,UAAU;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,QAAQ,CAAC;IACf,MAAM,EAAE,UAAU,CAAC;IACnB,wEAAwE;IACxE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,yFAAyF;IACzF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;;;;OAKG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;CACzB;
|
|
1
|
+
{"version":3,"file":"lane-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AC,EAAE,QAAQ,GAAG,MAAM,CAQtC;IAED,eAAe,CAAC,IAAI,CAAC,EAAE,QAAQ,GAAG,MAAM,CAQvC;IAED,UAAU,IAAI,UAAU,EAAE,CAEzB;IAED,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS,CAGhD;CACD"}
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* counts reflect lanes actually running in THIS process, never inferred/faked from historical
|
|
6
6
|
* snapshots. Terminal lane records are persisted separately via `session-lane-record.ts`.
|
|
7
7
|
*/
|
|
8
|
+
import { ORCHESTRATION_THINKING_LEVELS } from "../orchestration/contracts.js";
|
|
8
9
|
const LANE_TYPES = ["research", "worker", "learning", "tmux-worker"];
|
|
9
10
|
const TERMINAL_STATUSES = [
|
|
10
11
|
"succeeded",
|
|
@@ -16,6 +17,7 @@ const TERMINAL_STATUSES = [
|
|
|
16
17
|
"budget_exhausted",
|
|
17
18
|
];
|
|
18
19
|
const LANE_STATUSES = ["queued", "running", ...TERMINAL_STATUSES];
|
|
20
|
+
const ORCHESTRATION_THINKING_LEVEL_SET = new Set(ORCHESTRATION_THINKING_LEVELS);
|
|
19
21
|
export function isLaneTerminalStatus(value) {
|
|
20
22
|
return typeof value === "string" && TERMINAL_STATUSES.includes(value);
|
|
21
23
|
}
|
|
@@ -36,6 +38,12 @@ export function isLaneRecord(value) {
|
|
|
36
38
|
return false;
|
|
37
39
|
if (!isOptionalString(record.profileId))
|
|
38
40
|
return false;
|
|
41
|
+
if (!isOptionalString(record.modelRef))
|
|
42
|
+
return false;
|
|
43
|
+
if (record.thinkingLevel !== undefined &&
|
|
44
|
+
(typeof record.thinkingLevel !== "string" || !ORCHESTRATION_THINKING_LEVEL_SET.has(record.thinkingLevel))) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
39
47
|
if (!isOptionalString(record.reasonCode))
|
|
40
48
|
return false;
|
|
41
49
|
if (!isOptionalString(record.startedAt))
|
|
@@ -1 +1 @@
|
|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CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,MAAM,EAAE,CAAC,CAAC,CAAC;IACnE,CAAC;IAED,SAAS,CAAC,MAAc;QACvB,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACvC,OAAO,MAAM,CAAC,CAAC,CAAC,EAAE,GAAG,MAAM,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;IAC3C,CAAC;CACD","sourcesContent":["/**\n * Live lane registry for autonomous background work (research/worker/learning lanes).\n *\n * This is the first real concurrency tracker behind `AutonomyStatusSnapshot.activeLaneCount`:\n * counts reflect lanes actually running in THIS process, never inferred/faked from historical\n * snapshots. Terminal lane records are persisted separately via `session-lane-record.ts`.\n */\n\nexport type LaneType = \"research\" | \"worker\" | \"learning\" | \"tmux-worker\";\n\nexport type LaneTerminalStatus =\n\t| \"succeeded\"\n\t| \"partial\"\n\t| \"blocked\"\n\t| \"failed\"\n\t| \"canceled\"\n\t| \"timeout\"\n\t| \"budget_exhausted\";\n\nexport type LaneStatus = \"queued\" | \"running\" | LaneTerminalStatus;\n\nexport interface LaneRecord {\n\tlaneId: string;\n\ttype: LaneType;\n\tstatus: LaneStatus;\n\t/** Bounded human-readable work label retained across session resume. */\n\tlabel?: string;\n\t/** Owner-authored profile that fixed the worker's model, thinking, tools, and budget. */\n\tprofileId?: string;\n\treasonCode?: string;\n\tstartedAt?: string;\n\tcompletedAt?: string;\n\tcostUsd?: number;\n\tgoalId?: string;\n\tevidenceEntryId?: string;\n\t/**\n\t * Worktree-sync lane key this lane record was correlated to at dispatch (set only for a\n\t * tmux-worker lane whose fire_task carried a `worktreeLane` -- see `tmux-dispatch.ts`'s\n\t * `createLaneWorktree`). Optional so every pre-existing record/caller keeps compiling and\n\t * behaving unchanged; `undefined` for a lane never bound to a worktree-sync lane.\n\t */\n\tworktreeLaneKey?: string;\n}\n\nconst LANE_TYPES: readonly string[] = [\"research\", \"worker\", \"learning\", \"tmux-worker\"];\nconst TERMINAL_STATUSES: readonly string[] = [\n\t\"succeeded\",\n\t\"partial\",\n\t\"blocked\",\n\t\"failed\",\n\t\"canceled\",\n\t\"timeout\",\n\t\"budget_exhausted\",\n];\nconst LANE_STATUSES: readonly string[] = [\"queued\", \"running\", ...TERMINAL_STATUSES];\n\nexport function isLaneTerminalStatus(value: unknown): value is LaneTerminalStatus {\n\treturn typeof value === \"string\" && TERMINAL_STATUSES.includes(value);\n}\n\nfunction isOptionalString(value: unknown): boolean {\n\treturn value === undefined || typeof value === \"string\";\n}\n\nexport function isLaneRecord(value: unknown): value is LaneRecord {\n\tif (!value || typeof value !== \"object\" || Array.isArray(value)) return false;\n\tconst record = value as Record<string, unknown>;\n\tif (typeof record.laneId !== \"string\" || record.laneId.length === 0) return false;\n\tif (typeof record.type !== \"string\" || !LANE_TYPES.includes(record.type)) return false;\n\tif (typeof record.status !== \"string\" || !LANE_STATUSES.includes(record.status)) return false;\n\tif (!isOptionalString(record.label)) return false;\n\tif (!isOptionalString(record.profileId)) return false;\n\tif (!isOptionalString(record.reasonCode)) return false;\n\tif (!isOptionalString(record.startedAt)) return false;\n\tif (!isOptionalString(record.completedAt)) return false;\n\tif (record.costUsd !== undefined && (typeof record.costUsd !== \"number\" || !Number.isFinite(record.costUsd))) {\n\t\treturn false;\n\t}\n\tif (!isOptionalString(record.goalId)) return false;\n\tif (!isOptionalString(record.evidenceEntryId)) return false;\n\tif (!isOptionalString(record.worktreeLaneKey)) return false;\n\treturn true;\n}\n\nexport function cloneLaneRecordForStorage(record: LaneRecord): LaneRecord {\n\treturn { ...record };\n}\n\n/** Terminal records kept in memory for diagnostics; older ones are evicted (the session log holds history). */\nconst MAX_TERMINAL_LANES_IN_MEMORY = 100;\n\nexport class LaneTracker {\n\tprivate readonly _lanes = new Map<string, LaneRecord>();\n\tprivate _nextLaneNumber = 1;\n\tprivate readonly _now: () => string;\n\n\tconstructor(options?: { now?: () => string }) {\n\t\tthis._now = options?.now ?? (() => new Date().toISOString());\n\t}\n\n\t/** Seed the id counter (e.g. from persisted lane records) so resumed sessions don't reuse ids. */\n\tensureCounterAtLeast(next: number): void {\n\t\tif (Number.isFinite(next) && next > this._nextLaneNumber) {\n\t\t\tthis._nextLaneNumber = Math.floor(next);\n\t\t}\n\t}\n\n\tprivate _evictOldTerminal(): void {\n\t\tlet terminal = 0;\n\t\tfor (const record of this._lanes.values()) {\n\t\t\tif (isLaneTerminalStatus(record.status)) terminal++;\n\t\t}\n\t\tif (terminal <= MAX_TERMINAL_LANES_IN_MEMORY) return;\n\t\t// Map iteration is insertion-ordered: drop oldest terminal records first.\n\t\tfor (const [laneId, record] of this._lanes) {\n\t\t\tif (terminal <= MAX_TERMINAL_LANES_IN_MEMORY) break;\n\t\t\tif (isLaneTerminalStatus(record.status)) {\n\t\t\t\tthis._lanes.delete(laneId);\n\t\t\t\tterminal--;\n\t\t\t}\n\t\t}\n\t}\n\n\tenqueue(args: { type: LaneType; goalId?: string; worktreeLaneKey?: string }): LaneRecord {\n\t\tconst laneId = `${args.type}-${this._nextLaneNumber++}`;\n\t\tconst record: LaneRecord = {\n\t\t\tlaneId,\n\t\t\ttype: args.type,\n\t\t\tstatus: \"queued\",\n\t\t};\n\t\tif (args.goalId !== undefined) record.goalId = args.goalId;\n\t\tif (args.worktreeLaneKey !== undefined) record.worktreeLaneKey = args.worktreeLaneKey;\n\t\tthis._lanes.set(laneId, record);\n\t\treturn { ...record };\n\t}\n\n\t/** Restore an exact durable projection without minting a replacement logical id or timestamp. */\n\trestore(record: LaneRecord): LaneRecord {\n\t\tconst restored = { ...record };\n\t\tthis._lanes.set(restored.laneId, restored);\n\t\tconst suffix = /-(\\d+)$/.exec(restored.laneId)?.[1];\n\t\tif (suffix) this.ensureCounterAtLeast(Number(suffix) + 1);\n\t\tthis._evictOldTerminal();\n\t\treturn { ...restored };\n\t}\n\n\t/** Start or restart a caller-named lane. The supplied id is its durable logical identity. */\n\tstartNamed(args: { laneId: string; type: LaneType; goalId?: string; worktreeLaneKey?: string }): LaneRecord {\n\t\tif (!args.laneId) throw new TypeError(\"A named lane requires a non-empty laneId.\");\n\t\tconst record: LaneRecord = {\n\t\t\tlaneId: args.laneId,\n\t\t\ttype: args.type,\n\t\t\tstatus: \"running\",\n\t\t\tstartedAt: this._now(),\n\t\t};\n\t\tif (args.goalId !== undefined) record.goalId = args.goalId;\n\t\tif (args.worktreeLaneKey !== undefined) record.worktreeLaneKey = args.worktreeLaneKey;\n\t\tthis._lanes.set(record.laneId, record);\n\t\tconst suffix = /-(\\d+)$/.exec(record.laneId)?.[1];\n\t\tif (suffix) this.ensureCounterAtLeast(Number(suffix) + 1);\n\t\treturn { ...record };\n\t}\n\n\tmarkRunning(laneId: string): LaneRecord | undefined {\n\t\tconst record = this._lanes.get(laneId);\n\t\tif (!record || record.status !== \"queued\") return undefined;\n\t\tconst next = { ...record, status: \"running\" as const, startedAt: this._now() };\n\t\tthis._lanes.set(laneId, next);\n\t\treturn { ...next };\n\t}\n\n\tstart(args: { type: LaneType; goalId?: string; worktreeLaneKey?: string }): LaneRecord {\n\t\tconst record = this.enqueue(args);\n\t\treturn this.markRunning(record.laneId) as LaneRecord;\n\t}\n\n\tcomplete(\n\t\tlaneId: string,\n\t\targs: { status: LaneTerminalStatus; reasonCode?: string; costUsd?: number; evidenceEntryId?: string },\n\t): LaneRecord | undefined {\n\t\tconst record = this._lanes.get(laneId);\n\t\tif (!record || isLaneTerminalStatus(record.status)) return undefined;\n\t\tconst next: LaneRecord = {\n\t\t\t...record,\n\t\t\tstatus: args.status,\n\t\t\tcompletedAt: this._now(),\n\t\t};\n\t\tif (args.reasonCode !== undefined) next.reasonCode = args.reasonCode;\n\t\tif (args.costUsd !== undefined) next.costUsd = args.costUsd;\n\t\tif (args.evidenceEntryId !== undefined) next.evidenceEntryId = args.evidenceEntryId;\n\t\tthis._lanes.set(laneId, next);\n\t\tthis._evictOldTerminal();\n\t\treturn { ...next };\n\t}\n\n\tgetActiveCount(type?: LaneType): number {\n\t\tlet count = 0;\n\t\tfor (const record of this._lanes.values()) {\n\t\t\tif (isLaneTerminalStatus(record.status)) continue;\n\t\t\tif (type !== undefined && record.type !== type) continue;\n\t\t\tcount++;\n\t\t}\n\t\treturn count;\n\t}\n\n\tgetRunningCount(type?: LaneType): number {\n\t\tlet count = 0;\n\t\tfor (const record of this._lanes.values()) {\n\t\t\tif (record.status !== \"running\") continue;\n\t\t\tif (type !== undefined && record.type !== type) continue;\n\t\t\tcount++;\n\t\t}\n\t\treturn count;\n\t}\n\n\tgetRecords(): LaneRecord[] {\n\t\treturn [...this._lanes.values()].map((record) => ({ ...record }));\n\t}\n\n\tgetRecord(laneId: string): LaneRecord | undefined {\n\t\tconst record = this._lanes.get(laneId);\n\t\treturn record ? { ...record } : undefined;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"lane-tracker.js","sourceRoot":"","sources":["../../../src/core/autonomy/lane-tracker.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,6BAA6B,EAAmC,MAAM,+BAA+B,CAAC;AA0C/G,MAAM,UAAU,GAAsB,CAAC,UAAU,EAAE,QAAQ,EAAE,UAAU,EAAE,aAAa,CAAC,CAAC;AACxF,MAAM,iBAAiB,GAAsB;IAC5C,WAAW;IACX,SAAS;IACT,SAAS;IACT,QAAQ;IACR,UAAU;IACV,SAAS;IACT,kBAAkB;CAClB,CAAC;AACF,MAAM,aAAa,GAAsB,CAAC,QAAQ,EAAE,SAAS,EAAE,GAAG,iBAAiB,CAAC,CAAC;AACrF,MAAM,gCAAgC,GAAwB,IAAI,GAAG,CAAC,6BAA6B,CAAC,CAAC;AAErG,MAAM,UAAU,oBAAoB,CAAC,KAAc;IAClD,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,iBAAiB,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACvE,CAAC;AAED,SAAS,gBAAgB,CAAC,KAAc;IACvC,OAAO,KAAK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C3C,CAAC;CACD","sourcesContent":["/**\n * Live lane registry for autonomous background work (research/worker/learning lanes).\n *\n * This is the first real concurrency tracker behind `AutonomyStatusSnapshot.activeLaneCount`:\n * counts reflect lanes actually running in THIS process, never inferred/faked from historical\n * snapshots. Terminal lane records are persisted separately via `session-lane-record.ts`.\n */\n\nimport { ORCHESTRATION_THINKING_LEVELS, type OrchestrationThinkingLevel } from \"../orchestration/contracts.ts\";\n\nexport type LaneType = \"research\" | \"worker\" | \"learning\" | \"tmux-worker\";\n\nexport type LaneTerminalStatus =\n\t| \"succeeded\"\n\t| \"partial\"\n\t| \"blocked\"\n\t| \"failed\"\n\t| \"canceled\"\n\t| \"timeout\"\n\t| \"budget_exhausted\";\n\nexport type LaneStatus = \"queued\" | \"running\" | LaneTerminalStatus;\n\nexport interface LaneRecord {\n\tlaneId: string;\n\ttype: LaneType;\n\tstatus: LaneStatus;\n\t/** Bounded human-readable work label retained across session resume. */\n\tlabel?: string;\n\t/** Owner-authored profile that fixed the worker's model, thinking, tools, and budget. */\n\tprofileId?: string;\n\t/** Effective provider/model admitted into the immutable worker execution contract. */\n\tmodelRef?: string;\n\t/** Effective thinking level admitted with modelRef. */\n\tthinkingLevel?: OrchestrationThinkingLevel;\n\treasonCode?: string;\n\tstartedAt?: string;\n\tcompletedAt?: string;\n\tcostUsd?: number;\n\tgoalId?: string;\n\tevidenceEntryId?: string;\n\t/**\n\t * Worktree-sync lane key this lane record was correlated to at dispatch (set only for a\n\t * tmux-worker lane whose fire_task carried a `worktreeLane` -- see `tmux-dispatch.ts`'s\n\t * `createLaneWorktree`). Optional so every pre-existing record/caller keeps compiling and\n\t * behaving unchanged; `undefined` for a lane never bound to a worktree-sync lane.\n\t */\n\tworktreeLaneKey?: string;\n}\n\nconst LANE_TYPES: readonly string[] = [\"research\", \"worker\", \"learning\", \"tmux-worker\"];\nconst TERMINAL_STATUSES: readonly string[] = [\n\t\"succeeded\",\n\t\"partial\",\n\t\"blocked\",\n\t\"failed\",\n\t\"canceled\",\n\t\"timeout\",\n\t\"budget_exhausted\",\n];\nconst LANE_STATUSES: readonly string[] = [\"queued\", \"running\", ...TERMINAL_STATUSES];\nconst ORCHESTRATION_THINKING_LEVEL_SET: ReadonlySet<string> = new Set(ORCHESTRATION_THINKING_LEVELS);\n\nexport function isLaneTerminalStatus(value: unknown): value is LaneTerminalStatus {\n\treturn typeof value === \"string\" && TERMINAL_STATUSES.includes(value);\n}\n\nfunction isOptionalString(value: unknown): boolean {\n\treturn value === undefined || typeof value === \"string\";\n}\n\nexport function isLaneRecord(value: unknown): value is LaneRecord {\n\tif (!value || typeof value !== \"object\" || Array.isArray(value)) return false;\n\tconst record = value as Record<string, unknown>;\n\tif (typeof record.laneId !== \"string\" || record.laneId.length === 0) return false;\n\tif (typeof record.type !== \"string\" || !LANE_TYPES.includes(record.type)) return false;\n\tif (typeof record.status !== \"string\" || !LANE_STATUSES.includes(record.status)) return false;\n\tif (!isOptionalString(record.label)) return false;\n\tif (!isOptionalString(record.profileId)) return false;\n\tif (!isOptionalString(record.modelRef)) return false;\n\tif (\n\t\trecord.thinkingLevel !== undefined &&\n\t\t(typeof record.thinkingLevel !== \"string\" || !ORCHESTRATION_THINKING_LEVEL_SET.has(record.thinkingLevel))\n\t) {\n\t\treturn false;\n\t}\n\tif (!isOptionalString(record.reasonCode)) return false;\n\tif (!isOptionalString(record.startedAt)) return false;\n\tif (!isOptionalString(record.completedAt)) return false;\n\tif (record.costUsd !== undefined && (typeof record.costUsd !== \"number\" || !Number.isFinite(record.costUsd))) {\n\t\treturn false;\n\t}\n\tif (!isOptionalString(record.goalId)) return false;\n\tif (!isOptionalString(record.evidenceEntryId)) return false;\n\tif (!isOptionalString(record.worktreeLaneKey)) return false;\n\treturn true;\n}\n\nexport function cloneLaneRecordForStorage(record: LaneRecord): LaneRecord {\n\treturn { ...record };\n}\n\n/** Terminal records kept in memory for diagnostics; older ones are evicted (the session log holds history). */\nconst MAX_TERMINAL_LANES_IN_MEMORY = 100;\n\nexport class LaneTracker {\n\tprivate readonly _lanes = new Map<string, LaneRecord>();\n\tprivate _nextLaneNumber = 1;\n\tprivate readonly _now: () => string;\n\n\tconstructor(options?: { now?: () => string }) {\n\t\tthis._now = options?.now ?? (() => new Date().toISOString());\n\t}\n\n\t/** Seed the id counter (e.g. from persisted lane records) so resumed sessions don't reuse ids. */\n\tensureCounterAtLeast(next: number): void {\n\t\tif (Number.isFinite(next) && next > this._nextLaneNumber) {\n\t\t\tthis._nextLaneNumber = Math.floor(next);\n\t\t}\n\t}\n\n\tprivate _evictOldTerminal(): void {\n\t\tlet terminal = 0;\n\t\tfor (const record of this._lanes.values()) {\n\t\t\tif (isLaneTerminalStatus(record.status)) terminal++;\n\t\t}\n\t\tif (terminal <= MAX_TERMINAL_LANES_IN_MEMORY) return;\n\t\t// Map iteration is insertion-ordered: drop oldest terminal records first.\n\t\tfor (const [laneId, record] of this._lanes) {\n\t\t\tif (terminal <= MAX_TERMINAL_LANES_IN_MEMORY) break;\n\t\t\tif (isLaneTerminalStatus(record.status)) {\n\t\t\t\tthis._lanes.delete(laneId);\n\t\t\t\tterminal--;\n\t\t\t}\n\t\t}\n\t}\n\n\tenqueue(args: { type: LaneType; goalId?: string; worktreeLaneKey?: string }): LaneRecord {\n\t\tconst laneId = `${args.type}-${this._nextLaneNumber++}`;\n\t\tconst record: LaneRecord = {\n\t\t\tlaneId,\n\t\t\ttype: args.type,\n\t\t\tstatus: \"queued\",\n\t\t};\n\t\tif (args.goalId !== undefined) record.goalId = args.goalId;\n\t\tif (args.worktreeLaneKey !== undefined) record.worktreeLaneKey = args.worktreeLaneKey;\n\t\tthis._lanes.set(laneId, record);\n\t\treturn { ...record };\n\t}\n\n\t/** Restore an exact durable projection without minting a replacement logical id or timestamp. */\n\trestore(record: LaneRecord): LaneRecord {\n\t\tconst restored = { ...record };\n\t\tthis._lanes.set(restored.laneId, restored);\n\t\tconst suffix = /-(\\d+)$/.exec(restored.laneId)?.[1];\n\t\tif (suffix) this.ensureCounterAtLeast(Number(suffix) + 1);\n\t\tthis._evictOldTerminal();\n\t\treturn { ...restored };\n\t}\n\n\t/** Start or restart a caller-named lane. The supplied id is its durable logical identity. */\n\tstartNamed(args: { laneId: string; type: LaneType; goalId?: string; worktreeLaneKey?: string }): LaneRecord {\n\t\tif (!args.laneId) throw new TypeError(\"A named lane requires a non-empty laneId.\");\n\t\tconst record: LaneRecord = {\n\t\t\tlaneId: args.laneId,\n\t\t\ttype: args.type,\n\t\t\tstatus: \"running\",\n\t\t\tstartedAt: this._now(),\n\t\t};\n\t\tif (args.goalId !== undefined) record.goalId = args.goalId;\n\t\tif (args.worktreeLaneKey !== undefined) record.worktreeLaneKey = args.worktreeLaneKey;\n\t\tthis._lanes.set(record.laneId, record);\n\t\tconst suffix = /-(\\d+)$/.exec(record.laneId)?.[1];\n\t\tif (suffix) this.ensureCounterAtLeast(Number(suffix) + 1);\n\t\treturn { ...record };\n\t}\n\n\tmarkRunning(laneId: string): LaneRecord | undefined {\n\t\tconst record = this._lanes.get(laneId);\n\t\tif (!record || record.status !== \"queued\") return undefined;\n\t\tconst next = { ...record, status: \"running\" as const, startedAt: this._now() };\n\t\tthis._lanes.set(laneId, next);\n\t\treturn { ...next };\n\t}\n\n\tstart(args: { type: LaneType; goalId?: string; worktreeLaneKey?: string }): LaneRecord {\n\t\tconst record = this.enqueue(args);\n\t\treturn this.markRunning(record.laneId) as LaneRecord;\n\t}\n\n\tcomplete(\n\t\tlaneId: string,\n\t\targs: { status: LaneTerminalStatus; reasonCode?: string; costUsd?: number; evidenceEntryId?: string },\n\t): LaneRecord | undefined {\n\t\tconst record = this._lanes.get(laneId);\n\t\tif (!record || isLaneTerminalStatus(record.status)) return undefined;\n\t\tconst next: LaneRecord = {\n\t\t\t...record,\n\t\t\tstatus: args.status,\n\t\t\tcompletedAt: this._now(),\n\t\t};\n\t\tif (args.reasonCode !== undefined) next.reasonCode = args.reasonCode;\n\t\tif (args.costUsd !== undefined) next.costUsd = args.costUsd;\n\t\tif (args.evidenceEntryId !== undefined) next.evidenceEntryId = args.evidenceEntryId;\n\t\tthis._lanes.set(laneId, next);\n\t\tthis._evictOldTerminal();\n\t\treturn { ...next };\n\t}\n\n\tgetActiveCount(type?: LaneType): number {\n\t\tlet count = 0;\n\t\tfor (const record of this._lanes.values()) {\n\t\t\tif (isLaneTerminalStatus(record.status)) continue;\n\t\t\tif (type !== undefined && record.type !== type) continue;\n\t\t\tcount++;\n\t\t}\n\t\treturn count;\n\t}\n\n\tgetRunningCount(type?: LaneType): number {\n\t\tlet count = 0;\n\t\tfor (const record of this._lanes.values()) {\n\t\t\tif (record.status !== \"running\") continue;\n\t\t\tif (type !== undefined && record.type !== type) continue;\n\t\t\tcount++;\n\t\t}\n\t\treturn count;\n\t}\n\n\tgetRecords(): LaneRecord[] {\n\t\treturn [...this._lanes.values()].map((record) => ({ ...record }));\n\t}\n\n\tgetRecord(laneId: string): LaneRecord | undefined {\n\t\tconst record = this._lanes.get(laneId);\n\t\treturn record ? { ...record } : undefined;\n\t}\n}\n"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Api, Model } from "@caupulican/pi-ai";
|
|
2
2
|
import type { ModelRegistry } from "../model-registry.ts";
|
|
3
|
+
import { type OrchestrationModelBinding } from "../orchestration/contracts.ts";
|
|
3
4
|
import type { WorkerDelegationAuthorityRequest } from "./worker-delegation-request.ts";
|
|
4
5
|
import type { ResolvedWorkerProfile } from "./worker-profile-resolver.ts";
|
|
5
6
|
/**
|
|
@@ -14,6 +15,7 @@ export declare const MIN_VIABLE_WORKER_TOKEN_BUDGET = 5000;
|
|
|
14
15
|
export interface WorkerAuthorityResolutionInput {
|
|
15
16
|
authority?: WorkerDelegationAuthorityRequest;
|
|
16
17
|
base?: ResolvedWorkerProfile;
|
|
18
|
+
modelPin?: OrchestrationModelBinding;
|
|
17
19
|
foregroundModel?: Model<Api>;
|
|
18
20
|
modelRegistry: ModelRegistry;
|
|
19
21
|
isModelExhausted(model: Model<Api>): boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-authority-resolver.d.ts","sourceRoot":"","sources":["../../../src/core/delegation/worker-authority-resolver.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAGpD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"worker-authority-resolver.d.ts","sourceRoot":"","sources":["../../../src/core/delegation/worker-authority-resolver.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAGpD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAGN,KAAK,yBAAyB,EAE9B,MAAM,+BAA+B,CAAC;AAIvC,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,gCAAgC,CAAC;AAEvF,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAE1E;;;;;;;GAOG;AACH,eAAO,MAAM,8BAA8B,OAAQ,CAAC;AAyBpD,MAAM,WAAW,8BAA8B;IAC9C,SAAS,CAAC,EAAE,gCAAgC,CAAC;IAC7C,IAAI,CAAC,EAAE,qBAAqB,CAAC;IAC7B,QAAQ,CAAC,EAAE,yBAAyB,CAAC;IACrC,eAAe,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;IAC7B,aAAa,EAAE,aAAa,CAAC;IAC7B,gBAAgB,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC;CAC7C;AAED,MAAM,MAAM,yBAAyB,GAClC;IACA,EAAE,EAAE,IAAI,CAAC;IACT,QAAQ,EAAE,qBAAqB,CAAC;IAChC,kBAAkB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACvC,mBAAmB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACvC,GACD;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAqCjC,8FAA8F;AAC9F,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,8BAA8B,GAAG,yBAAyB,CA4HvG"}
|
|
@@ -37,7 +37,9 @@ const DEFAULT_CAPABILITIES = [
|
|
|
37
37
|
"service.mcp",
|
|
38
38
|
"memory.query",
|
|
39
39
|
];
|
|
40
|
-
function selectModelBinding(authority, base, foregroundModel, modelRegistry) {
|
|
40
|
+
function selectModelBinding(modelPin, authority, base, foregroundModel, modelRegistry) {
|
|
41
|
+
if (modelPin)
|
|
42
|
+
return { ...modelPin };
|
|
41
43
|
const provider = authority?.model?.provider ?? base?.modelBinding.provider ?? foregroundModel?.provider;
|
|
42
44
|
const modelId = authority?.model?.modelId ?? base?.modelBinding.modelId ?? foregroundModel?.id;
|
|
43
45
|
if (!provider || !modelId)
|
|
@@ -66,9 +68,27 @@ function tokenBudgetFloorFailure(maxTokens) {
|
|
|
66
68
|
export function resolveWorkerAuthority(input) {
|
|
67
69
|
if (!input.authority && input.base) {
|
|
68
70
|
const floorFailure = tokenBudgetFloorFailure(input.base.profile.budget.maxTokens);
|
|
69
|
-
|
|
71
|
+
if (floorFailure)
|
|
72
|
+
return { ok: false, reason: floorFailure };
|
|
73
|
+
if (!input.modelPin)
|
|
74
|
+
return { ok: true, shipment: input.base };
|
|
75
|
+
const resolvedModel = resolvePinnedOrchestrationModel(input.modelPin, input.modelRegistry, input.isModelExhausted);
|
|
76
|
+
if (!resolvedModel)
|
|
77
|
+
return { ok: false, reason: "orchestration_model_unavailable" };
|
|
78
|
+
return {
|
|
79
|
+
ok: true,
|
|
80
|
+
shipment: {
|
|
81
|
+
...input.base,
|
|
82
|
+
model: resolvedModel.model,
|
|
83
|
+
modelBinding: resolvedModel.binding,
|
|
84
|
+
profile: {
|
|
85
|
+
...input.base.profile,
|
|
86
|
+
modelPolicy: { mode: "fixed", candidates: [resolvedModel.binding] },
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
};
|
|
70
90
|
}
|
|
71
|
-
const binding = selectModelBinding(input.authority, input.base, input.foregroundModel, input.modelRegistry);
|
|
91
|
+
const binding = selectModelBinding(input.modelPin, input.authority, input.base, input.foregroundModel, input.modelRegistry);
|
|
72
92
|
if (!binding)
|
|
73
93
|
return { ok: false, reason: "orchestration_model_required" };
|
|
74
94
|
const resolvedModel = resolvePinnedOrchestrationModel(binding, input.modelRegistry, input.isModelExhausted);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-authority-resolver.js","sourceRoot":"","sources":["../../../src/core/delegation/worker-authority-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AACrE,OAAO,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAE7F,OAAO,EAEN,4BAA4B,GAG5B,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,0BAA0B,EAAE,MAAM,yCAAyC,CAAC;AACrF,OAAO,EAAE,+BAA+B,EAAE,MAAM,mCAAmC,CAAC;AACpF,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAEvE,OAAO,EAAE,6BAA6B,EAAE,MAAM,0BAA0B,CAAC;AAGzE;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAG,KAAK,CAAC;AAEpD,MAAM,kBAAkB,GAAG;IAC1B,MAAM;IACN,MAAM;IACN,MAAM;IACN,IAAI;IACJ,OAAO;IACP,MAAM;IACN,QAAQ;IACR,sBAAsB;IACtB,UAAU;CACD,CAAC;AACX,MAAM,oBAAoB,GAAwB,IAAI,GAAG,CAAC,CAAC,GAAG,0BAA0B,EAAE,UAAU,CAAC,CAAC,CAAC;AACvG,MAAM,oBAAoB,GAAiC;IAC1D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G,KAAK,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAChG,CAAC;AACH,CAAC","sourcesContent":["import { createHash } from \"node:crypto\";\nimport type { Api, Model } from \"@caupulican/pi-ai\";\nimport { resolveModelThinkingLevel } from \"@caupulican/pi-ai/models\";\nimport { mapToolNamesForPlatform, STABLE_SHELL_TOOL_NAME } from \"../default-tool-surface.ts\";\nimport type { ModelRegistry } from \"../model-registry.ts\";\nimport {\n\ttype HarnessCapability,\n\tORCHESTRATION_SCHEMA_VERSION,\n\ttype OrchestrationModelBinding,\n\ttype OrchestrationProfile,\n} from \"../orchestration/contracts.ts\";\nimport { CLASSIFIED_LANE_TOOL_NAMES } from \"../orchestration/lane-tool-manifests.ts\";\nimport { resolvePinnedOrchestrationModel } from \"../orchestration/model-binding.ts\";\nimport { getToolCapabilityPolicy } from \"../tool-capability-policy.ts\";\nimport type { WorkerDelegationAuthorityRequest } from \"./worker-delegation-request.ts\";\nimport { LEAN_WORKER_DELEGATION_LIMITS } from \"./worker-fleet-limits.ts\";\nimport type { ResolvedWorkerProfile } from \"./worker-profile-resolver.ts\";\n\n/**\n * Smallest token grant a worker can survive on. A worker's first response pays the full\n * uncached system prompt (~3.3k budgeted tokens in the field), so grants below this floor\n * starve mid-flight with every tool call denied `token_budget_exhausted` — reject them at\n * admission with an explicit reason instead (field session 019fd4dc: 8-9k grants died in\n * 2-3 responses under face-value cache-read counting; the floor plus discounted counting\n * makes small grants viable again).\n */\nexport const MIN_VIABLE_WORKER_TOKEN_BUDGET = 5_000;\n\nconst DEFAULT_TOOL_NAMES = [\n\t\"read\",\n\t\"grep\",\n\t\"find\",\n\t\"ls\",\n\t\"write\",\n\t\"edit\",\n\t\"memory\",\n\tSTABLE_SHELL_TOOL_NAME,\n\t\"delegate\",\n] as const;\nconst AVAILABLE_TOOL_NAMES: ReadonlySet<string> = new Set([...CLASSIFIED_LANE_TOOL_NAMES, \"delegate\"]);\nconst DEFAULT_CAPABILITIES: readonly HarnessCapability[] = [\n\t\"filesystem.read\",\n\t\"filesystem.write\",\n\t\"worktree.read\",\n\t\"worktree.mutate\",\n\t\"process.exec\",\n\t\"network.http\",\n\t\"service.mcp\",\n\t\"memory.query\",\n];\n\nexport interface WorkerAuthorityResolutionInput {\n\tauthority?: WorkerDelegationAuthorityRequest;\n\tbase?: ResolvedWorkerProfile;\n\tforegroundModel?: Model<Api>;\n\tmodelRegistry: ModelRegistry;\n\tisModelExhausted(model: Model<Api>): boolean;\n}\n\nexport type WorkerAuthorityResolution =\n\t| {\n\t\t\tok: true;\n\t\t\tshipment: ResolvedWorkerProfile;\n\t\t\trequestedReadPaths?: readonly string[];\n\t\t\trequestedWritePaths?: readonly string[];\n\t }\n\t| { ok: false; reason: string };\n\nfunction selectModelBinding(\n\tauthority: WorkerDelegationAuthorityRequest | undefined,\n\tbase: ResolvedWorkerProfile | undefined,\n\tforegroundModel: Model<Api> | undefined,\n\tmodelRegistry: ModelRegistry,\n): OrchestrationModelBinding | undefined {\n\tconst provider = authority?.model?.provider ?? base?.modelBinding.provider ?? foregroundModel?.provider;\n\tconst modelId = authority?.model?.modelId ?? base?.modelBinding.modelId ?? foregroundModel?.id;\n\tif (!provider || !modelId) return undefined;\n\tconst sameAsBase = provider === base?.modelBinding.provider && modelId === base.modelBinding.modelId;\n\tconst selectedModel = modelRegistry.find(provider, modelId);\n\tconst thinkingLevel =\n\t\tauthority?.thinkingLevel ??\n\t\t(sameAsBase\n\t\t\t? base.modelBinding.thinkingLevel\n\t\t\t: foregroundModel && provider === foregroundModel.provider && modelId === foregroundModel.id\n\t\t\t\t? resolveModelThinkingLevel(foregroundModel, undefined)\n\t\t\t\t: selectedModel\n\t\t\t\t\t? resolveModelThinkingLevel(selectedModel, undefined)\n\t\t\t\t\t: \"off\");\n\treturn { provider, modelId, thinkingLevel };\n}\n\nfunction adaptiveProfileId(value: object): string {\n\treturn `adaptive-${createHash(\"sha256\").update(JSON.stringify(value)).digest(\"hex\").slice(0, 32)}`;\n}\n\nfunction tokenBudgetFloorFailure(maxTokens: number | undefined): string | undefined {\n\treturn maxTokens !== undefined && maxTokens < MIN_VIABLE_WORKER_TOKEN_BUDGET\n\t\t? `token_budget_below_floor:requested=${maxTokens},min=${MIN_VIABLE_WORKER_TOKEN_BUDGET}`\n\t\t: undefined;\n}\n\n/** Materialize free-form model choices as one immutable profile-shaped execution snapshot. */\nexport function resolveWorkerAuthority(input: WorkerAuthorityResolutionInput): WorkerAuthorityResolution {\n\tif (!input.authority && input.base) {\n\t\tconst floorFailure = tokenBudgetFloorFailure(input.base.profile.budget.maxTokens);\n\t\treturn floorFailure ? { ok: false, reason: floorFailure } : { ok: true, shipment: input.base };\n\t}\n\tconst binding = selectModelBinding(input.authority, input.base, input.foregroundModel, input.modelRegistry);\n\tif (!binding) return { ok: false, reason: \"orchestration_model_required\" };\n\tconst resolvedModel = resolvePinnedOrchestrationModel(binding, input.modelRegistry, input.isModelExhausted);\n\tif (!resolvedModel) return { ok: false, reason: \"orchestration_model_unavailable\" };\n\n\tconst configuredToolNames = mapToolNamesForPlatform(\n\t\tinput.authority?.toolNames ?? input.base?.profile.toolNames ?? DEFAULT_TOOL_NAMES,\n\t);\n\tconst inheritsDelegation =\n\t\tinput.authority?.capabilities === undefined &&\n\t\t(input.base === undefined ||\n\t\t\t(input.base.profile.toolNames.includes(\"delegate\") &&\n\t\t\t\tinput.base.profile.capabilityCeiling.includes(\"workflow.delegate\")));\n\tconst requestedToolNames =\n\t\tinheritsDelegation && !configuredToolNames.includes(\"delegate\")\n\t\t\t? [...configuredToolNames, \"delegate\"]\n\t\t\t: configuredToolNames;\n\tconst uniqueToolNames = [...new Set(requestedToolNames)];\n\tconst unavailableTools = uniqueToolNames.filter((toolName) => !AVAILABLE_TOOL_NAMES.has(toolName));\n\tif (unavailableTools.length > 0) {\n\t\treturn { ok: false, reason: `orchestration_tool_unavailable:${unavailableTools.join(\",\")}` };\n\t}\n\tconst capabilities = new Set<HarnessCapability>(\n\t\tinput.authority?.capabilities ?? input.base?.profile.capabilityCeiling ?? DEFAULT_CAPABILITIES,\n\t);\n\tif (uniqueToolNames.includes(\"delegate\") && inheritsDelegation) {\n\t\tcapabilities.add(\"workflow.delegate\");\n\t}\n\tconst toolNames: string[] = [];\n\tfor (const toolName of uniqueToolNames) {\n\t\tconst policy = getToolCapabilityPolicy(toolName);\n\t\tif (!policy) return { ok: false, reason: `orchestration_tool_unclassified:${toolName}` };\n\t\tif (policy.capabilityCandidates.some((capability) => capabilities.has(capability))) {\n\t\t\ttoolNames.push(toolName);\n\t\t\tcontinue;\n\t\t}\n\t\tif (input.authority?.toolNames !== undefined) {\n\t\t\treturn { ok: false, reason: `orchestration_tool_capability_missing:${toolName}` };\n\t\t}\n\t}\n\tconst budget = structuredClone(input.authority?.budget ?? input.base?.profile.budget ?? {});\n\tconst floorFailure = tokenBudgetFloorFailure(budget.maxTokens);\n\tif (floorFailure) return { ok: false, reason: floorFailure };\n\tconst role = input.authority?.role ?? input.base?.profile.role ?? \"orchestrator\";\n\tconst delegationLimits = input.base\n\t\t? input.base.profile.delegationLimits\n\t\t: structuredClone(LEAN_WORKER_DELEGATION_LIMITS);\n\tconst now = new Date().toISOString();\n\tconst descriptor = {\n\t\trole,\n\t\tbinding: resolvedModel.binding,\n\t\tcapabilities: [...capabilities],\n\t\ttoolNames,\n\t\tbudget,\n\t\tdelegationLimits: delegationLimits ?? null,\n\t\tresourceProfileNames: input.base?.profile.resourceProfileNames ?? [],\n\t};\n\tconst maxWallClockMs = budget.maxWallClockMs ?? 0;\n\tconst wallClockLeaseTtlMs =\n\t\tmaxWallClockMs > Number.MAX_SAFE_INTEGER - 30_000 ? Number.MAX_SAFE_INTEGER : maxWallClockMs + 30_000;\n\tconst profile: OrchestrationProfile = {\n\t\tschemaVersion: ORCHESTRATION_SCHEMA_VERSION,\n\t\tprofileId: adaptiveProfileId(descriptor),\n\t\tdescription: \"Admission-time adaptive agent authority\",\n\t\trole,\n\t\tmodelPolicy: { mode: \"fixed\", candidates: [resolvedModel.binding] },\n\t\tcapabilityCeiling: [...capabilities],\n\t\ttoolNames,\n\t\tresourceProfileNames: [...(input.base?.profile.resourceProfileNames ?? [])],\n\t\tdispatchProfileIds: [],\n\t\t...(input.base?.profile.executionPolicy ? { executionPolicy: input.base.profile.executionPolicy } : {}),\n\t\t...(delegationLimits ? { delegationLimits: structuredClone(delegationLimits) } : {}),\n\t\tbudget,\n\t\tmaxConcurrent: Number.MAX_SAFE_INTEGER,\n\t\tleaseTtlMs: Math.max(input.base?.profile.leaseTtlMs ?? 0, wallClockLeaseTtlMs, 90_000),\n\t\trequireIndependentVerification: input.base?.profile.requireIndependentVerification ?? false,\n\t\t...(input.base?.profile.verificationProfileId\n\t\t\t? { verificationProfileId: input.base.profile.verificationProfileId }\n\t\t\t: {}),\n\t\tcreatedAt: now,\n\t\tupdatedAt: now,\n\t};\n\treturn {\n\t\tok: true,\n\t\tshipment: {\n\t\t\tmodel: resolvedModel.model,\n\t\t\tmodelBinding: resolvedModel.binding,\n\t\t\tprofile,\n\t\t\tresourcePointers: structuredClone(input.base?.resourcePointers ?? []),\n\t\t\t...(input.base?.soul ? { soul: input.base.soul } : {}),\n\t\t},\n\t\t...(input.authority?.readPaths ? { requestedReadPaths: [...input.authority.readPaths] } : {}),\n\t\t...(input.authority?.writePaths ? { requestedWritePaths: [...input.authority.writePaths] } : {}),\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"worker-authority-resolver.js","sourceRoot":"","sources":["../../../src/core/delegation/worker-authority-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AACrE,OAAO,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAE7F,OAAO,EAEN,4BAA4B,GAG5B,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,0BAA0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AAS,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAChG,CAAC;AACH,CAAC","sourcesContent":["import { createHash } from \"node:crypto\";\nimport type { Api, Model } from \"@caupulican/pi-ai\";\nimport { resolveModelThinkingLevel } from \"@caupulican/pi-ai/models\";\nimport { mapToolNamesForPlatform, STABLE_SHELL_TOOL_NAME } from \"../default-tool-surface.ts\";\nimport type { ModelRegistry } from \"../model-registry.ts\";\nimport {\n\ttype HarnessCapability,\n\tORCHESTRATION_SCHEMA_VERSION,\n\ttype OrchestrationModelBinding,\n\ttype OrchestrationProfile,\n} from \"../orchestration/contracts.ts\";\nimport { CLASSIFIED_LANE_TOOL_NAMES } from \"../orchestration/lane-tool-manifests.ts\";\nimport { resolvePinnedOrchestrationModel } from \"../orchestration/model-binding.ts\";\nimport { getToolCapabilityPolicy } from \"../tool-capability-policy.ts\";\nimport type { WorkerDelegationAuthorityRequest } from \"./worker-delegation-request.ts\";\nimport { LEAN_WORKER_DELEGATION_LIMITS } from \"./worker-fleet-limits.ts\";\nimport type { ResolvedWorkerProfile } from \"./worker-profile-resolver.ts\";\n\n/**\n * Smallest token grant a worker can survive on. A worker's first response pays the full\n * uncached system prompt (~3.3k budgeted tokens in the field), so grants below this floor\n * starve mid-flight with every tool call denied `token_budget_exhausted` — reject them at\n * admission with an explicit reason instead (field session 019fd4dc: 8-9k grants died in\n * 2-3 responses under face-value cache-read counting; the floor plus discounted counting\n * makes small grants viable again).\n */\nexport const MIN_VIABLE_WORKER_TOKEN_BUDGET = 5_000;\n\nconst DEFAULT_TOOL_NAMES = [\n\t\"read\",\n\t\"grep\",\n\t\"find\",\n\t\"ls\",\n\t\"write\",\n\t\"edit\",\n\t\"memory\",\n\tSTABLE_SHELL_TOOL_NAME,\n\t\"delegate\",\n] as const;\nconst AVAILABLE_TOOL_NAMES: ReadonlySet<string> = new Set([...CLASSIFIED_LANE_TOOL_NAMES, \"delegate\"]);\nconst DEFAULT_CAPABILITIES: readonly HarnessCapability[] = [\n\t\"filesystem.read\",\n\t\"filesystem.write\",\n\t\"worktree.read\",\n\t\"worktree.mutate\",\n\t\"process.exec\",\n\t\"network.http\",\n\t\"service.mcp\",\n\t\"memory.query\",\n];\n\nexport interface WorkerAuthorityResolutionInput {\n\tauthority?: WorkerDelegationAuthorityRequest;\n\tbase?: ResolvedWorkerProfile;\n\tmodelPin?: OrchestrationModelBinding;\n\tforegroundModel?: Model<Api>;\n\tmodelRegistry: ModelRegistry;\n\tisModelExhausted(model: Model<Api>): boolean;\n}\n\nexport type WorkerAuthorityResolution =\n\t| {\n\t\t\tok: true;\n\t\t\tshipment: ResolvedWorkerProfile;\n\t\t\trequestedReadPaths?: readonly string[];\n\t\t\trequestedWritePaths?: readonly string[];\n\t }\n\t| { ok: false; reason: string };\n\nfunction selectModelBinding(\n\tmodelPin: OrchestrationModelBinding | undefined,\n\tauthority: WorkerDelegationAuthorityRequest | undefined,\n\tbase: ResolvedWorkerProfile | undefined,\n\tforegroundModel: Model<Api> | undefined,\n\tmodelRegistry: ModelRegistry,\n): OrchestrationModelBinding | undefined {\n\tif (modelPin) return { ...modelPin };\n\tconst provider = authority?.model?.provider ?? base?.modelBinding.provider ?? foregroundModel?.provider;\n\tconst modelId = authority?.model?.modelId ?? base?.modelBinding.modelId ?? foregroundModel?.id;\n\tif (!provider || !modelId) return undefined;\n\tconst sameAsBase = provider === base?.modelBinding.provider && modelId === base.modelBinding.modelId;\n\tconst selectedModel = modelRegistry.find(provider, modelId);\n\tconst thinkingLevel =\n\t\tauthority?.thinkingLevel ??\n\t\t(sameAsBase\n\t\t\t? base.modelBinding.thinkingLevel\n\t\t\t: foregroundModel && provider === foregroundModel.provider && modelId === foregroundModel.id\n\t\t\t\t? resolveModelThinkingLevel(foregroundModel, undefined)\n\t\t\t\t: selectedModel\n\t\t\t\t\t? resolveModelThinkingLevel(selectedModel, undefined)\n\t\t\t\t\t: \"off\");\n\treturn { provider, modelId, thinkingLevel };\n}\n\nfunction adaptiveProfileId(value: object): string {\n\treturn `adaptive-${createHash(\"sha256\").update(JSON.stringify(value)).digest(\"hex\").slice(0, 32)}`;\n}\n\nfunction tokenBudgetFloorFailure(maxTokens: number | undefined): string | undefined {\n\treturn maxTokens !== undefined && maxTokens < MIN_VIABLE_WORKER_TOKEN_BUDGET\n\t\t? `token_budget_below_floor:requested=${maxTokens},min=${MIN_VIABLE_WORKER_TOKEN_BUDGET}`\n\t\t: undefined;\n}\n\n/** Materialize free-form model choices as one immutable profile-shaped execution snapshot. */\nexport function resolveWorkerAuthority(input: WorkerAuthorityResolutionInput): WorkerAuthorityResolution {\n\tif (!input.authority && input.base) {\n\t\tconst floorFailure = tokenBudgetFloorFailure(input.base.profile.budget.maxTokens);\n\t\tif (floorFailure) return { ok: false, reason: floorFailure };\n\t\tif (!input.modelPin) return { ok: true, shipment: input.base };\n\t\tconst resolvedModel = resolvePinnedOrchestrationModel(\n\t\t\tinput.modelPin,\n\t\t\tinput.modelRegistry,\n\t\t\tinput.isModelExhausted,\n\t\t);\n\t\tif (!resolvedModel) return { ok: false, reason: \"orchestration_model_unavailable\" };\n\t\treturn {\n\t\t\tok: true,\n\t\t\tshipment: {\n\t\t\t\t...input.base,\n\t\t\t\tmodel: resolvedModel.model,\n\t\t\t\tmodelBinding: resolvedModel.binding,\n\t\t\t\tprofile: {\n\t\t\t\t\t...input.base.profile,\n\t\t\t\t\tmodelPolicy: { mode: \"fixed\", candidates: [resolvedModel.binding] },\n\t\t\t\t},\n\t\t\t},\n\t\t};\n\t}\n\tconst binding = selectModelBinding(\n\t\tinput.modelPin,\n\t\tinput.authority,\n\t\tinput.base,\n\t\tinput.foregroundModel,\n\t\tinput.modelRegistry,\n\t);\n\tif (!binding) return { ok: false, reason: \"orchestration_model_required\" };\n\tconst resolvedModel = resolvePinnedOrchestrationModel(binding, input.modelRegistry, input.isModelExhausted);\n\tif (!resolvedModel) return { ok: false, reason: \"orchestration_model_unavailable\" };\n\n\tconst configuredToolNames = mapToolNamesForPlatform(\n\t\tinput.authority?.toolNames ?? input.base?.profile.toolNames ?? DEFAULT_TOOL_NAMES,\n\t);\n\tconst inheritsDelegation =\n\t\tinput.authority?.capabilities === undefined &&\n\t\t(input.base === undefined ||\n\t\t\t(input.base.profile.toolNames.includes(\"delegate\") &&\n\t\t\t\tinput.base.profile.capabilityCeiling.includes(\"workflow.delegate\")));\n\tconst requestedToolNames =\n\t\tinheritsDelegation && !configuredToolNames.includes(\"delegate\")\n\t\t\t? [...configuredToolNames, \"delegate\"]\n\t\t\t: configuredToolNames;\n\tconst uniqueToolNames = [...new Set(requestedToolNames)];\n\tconst unavailableTools = uniqueToolNames.filter((toolName) => !AVAILABLE_TOOL_NAMES.has(toolName));\n\tif (unavailableTools.length > 0) {\n\t\treturn { ok: false, reason: `orchestration_tool_unavailable:${unavailableTools.join(\",\")}` };\n\t}\n\tconst capabilities = new Set<HarnessCapability>(\n\t\tinput.authority?.capabilities ?? input.base?.profile.capabilityCeiling ?? DEFAULT_CAPABILITIES,\n\t);\n\tif (uniqueToolNames.includes(\"delegate\") && inheritsDelegation) {\n\t\tcapabilities.add(\"workflow.delegate\");\n\t}\n\tconst toolNames: string[] = [];\n\tfor (const toolName of uniqueToolNames) {\n\t\tconst policy = getToolCapabilityPolicy(toolName);\n\t\tif (!policy) return { ok: false, reason: `orchestration_tool_unclassified:${toolName}` };\n\t\tif (policy.capabilityCandidates.some((capability) => capabilities.has(capability))) {\n\t\t\ttoolNames.push(toolName);\n\t\t\tcontinue;\n\t\t}\n\t\tif (input.authority?.toolNames !== undefined) {\n\t\t\treturn { ok: false, reason: `orchestration_tool_capability_missing:${toolName}` };\n\t\t}\n\t}\n\tconst budget = structuredClone(input.authority?.budget ?? input.base?.profile.budget ?? {});\n\tconst floorFailure = tokenBudgetFloorFailure(budget.maxTokens);\n\tif (floorFailure) return { ok: false, reason: floorFailure };\n\tconst role = input.authority?.role ?? input.base?.profile.role ?? \"orchestrator\";\n\tconst delegationLimits = input.base\n\t\t? input.base.profile.delegationLimits\n\t\t: structuredClone(LEAN_WORKER_DELEGATION_LIMITS);\n\tconst now = new Date().toISOString();\n\tconst descriptor = {\n\t\trole,\n\t\tbinding: resolvedModel.binding,\n\t\tcapabilities: [...capabilities],\n\t\ttoolNames,\n\t\tbudget,\n\t\tdelegationLimits: delegationLimits ?? null,\n\t\tresourceProfileNames: input.base?.profile.resourceProfileNames ?? [],\n\t};\n\tconst maxWallClockMs = budget.maxWallClockMs ?? 0;\n\tconst wallClockLeaseTtlMs =\n\t\tmaxWallClockMs > Number.MAX_SAFE_INTEGER - 30_000 ? Number.MAX_SAFE_INTEGER : maxWallClockMs + 30_000;\n\tconst profile: OrchestrationProfile = {\n\t\tschemaVersion: ORCHESTRATION_SCHEMA_VERSION,\n\t\tprofileId: adaptiveProfileId(descriptor),\n\t\tdescription: \"Admission-time adaptive agent authority\",\n\t\trole,\n\t\tmodelPolicy: { mode: \"fixed\", candidates: [resolvedModel.binding] },\n\t\tcapabilityCeiling: [...capabilities],\n\t\ttoolNames,\n\t\tresourceProfileNames: [...(input.base?.profile.resourceProfileNames ?? [])],\n\t\tdispatchProfileIds: [],\n\t\t...(input.base?.profile.executionPolicy ? { executionPolicy: input.base.profile.executionPolicy } : {}),\n\t\t...(delegationLimits ? { delegationLimits: structuredClone(delegationLimits) } : {}),\n\t\tbudget,\n\t\tmaxConcurrent: Number.MAX_SAFE_INTEGER,\n\t\tleaseTtlMs: Math.max(input.base?.profile.leaseTtlMs ?? 0, wallClockLeaseTtlMs, 90_000),\n\t\trequireIndependentVerification: input.base?.profile.requireIndependentVerification ?? false,\n\t\t...(input.base?.profile.verificationProfileId\n\t\t\t? { verificationProfileId: input.base.profile.verificationProfileId }\n\t\t\t: {}),\n\t\tcreatedAt: now,\n\t\tupdatedAt: now,\n\t};\n\treturn {\n\t\tok: true,\n\t\tshipment: {\n\t\t\tmodel: resolvedModel.model,\n\t\t\tmodelBinding: resolvedModel.binding,\n\t\t\tprofile,\n\t\t\tresourcePointers: structuredClone(input.base?.resourcePointers ?? []),\n\t\t\t...(input.base?.soul ? { soul: input.base.soul } : {}),\n\t\t},\n\t\t...(input.authority?.readPaths ? { requestedReadPaths: [...input.authority.readPaths] } : {}),\n\t\t...(input.authority?.writePaths ? { requestedWritePaths: [...input.authority.writePaths] } : {}),\n\t};\n}\n"]}
|
|
@@ -107,7 +107,7 @@ export declare class WorkerDelegationController {
|
|
|
107
107
|
}>;
|
|
108
108
|
inspectTaskProfileOptions(): TaskProfileInspection;
|
|
109
109
|
createTaskProfile(input: TaskProfileCreateInput): TaskProfileCreateResult;
|
|
110
|
-
private
|
|
110
|
+
private resolveWorkerPreset;
|
|
111
111
|
private resolveRequiredVerifier;
|
|
112
112
|
/**
|
|
113
113
|
* A descendant may select a different routing profile, but that preset cannot introduce context or
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-delegation-controller.d.ts","sourceRoot":"","sources":["../../../src/core/delegation/worker-delegation-controller.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE3D,OAAO,KAAK,EACX,iBAAiB,EACjB,yBAAyB,EACzB,wBAAwB,EACxB,0BAA0B,EAC1B,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,kBAAkB,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAG/F,OAAO,EAAwB,KAAK,UAAU,EAAE,KAAK,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAE7G,OAAO,EAAkC,KAAK,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AAE9G,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAExD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAG1D,OAAO,EAIN,KAAK,oBAAoB,
|
|
1
|
+
{"version":3,"file":"worker-delegation-controller.d.ts","sourceRoot":"","sources":["../../../src/core/delegation/worker-delegation-controller.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE3D,OAAO,KAAK,EACX,iBAAiB,EACjB,yBAAyB,EACzB,wBAAwB,EACxB,0BAA0B,EAC1B,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,kBAAkB,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAG/F,OAAO,EAAwB,KAAK,UAAU,EAAE,KAAK,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAE7G,OAAO,EAAkC,KAAK,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AAE9G,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAExD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAG1D,OAAO,EAIN,KAAK,oBAAoB,EAIzB,MAAM,+BAA+B,CAAC;AAGvC,OAAO,EACN,KAAK,sBAAsB,EAC3B,KAAK,uBAAuB,EAC5B,KAAK,qBAAqB,EAE1B,MAAM,yCAAyC,CAAC;AACjD,OAAO,KAAK,EAAuB,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AAQnG,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,KAAK,EAAoC,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAMhG,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AAWxE,OAAO,EAAyC,KAAK,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAiBrH,OAAO,KAAK,EAA+B,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC1F,OAAO,KAAK,EAAE,6BA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SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,IAAI,EACxC,cAAc,CAAC,EAAE,UAAU,GACzB,OAAO,CAAC,0BAA0B,CAAC,CAErC;YAEa,oBAAoB;IAohBlC,mGAAmG;IACnG,KAAK,IAAI,IAAI,CAIZ;CACD"}
|
|
@@ -14,6 +14,7 @@ import { MAX_ORCHESTRATION_DISPATCH_INSTRUCTIONS_LENGTH, } from "../orchestratio
|
|
|
14
14
|
import { SessionTaskProfileStore } from "../orchestration/session-task-profile-store.js";
|
|
15
15
|
import { TaskProfileWriter, } from "../orchestration/task-profile-writer.js";
|
|
16
16
|
import { createWorkerExecutionContract, verifierWorkerExecutionContract, } from "../orchestration/worker-execution-contract.js";
|
|
17
|
+
import { resolveWorkerModelPin } from "../orchestration/worker-model-pins.js";
|
|
17
18
|
import { registerInFlightWork } from "../reload-blockers.js";
|
|
18
19
|
import { createDelegateToolDefinition } from "../tools/delegate.js";
|
|
19
20
|
import { disposePersistentShellSession } from "../tools/shell-session.js";
|
|
@@ -32,7 +33,7 @@ import { buildWorkerExecutionPlan, compileWorkerExecutionGrant, narrowWorkerExec
|
|
|
32
33
|
import { DEFAULT_WORKER_FLEET_LIMITS, evaluateNewWorkerAdmission, intersectWorkerDelegationLimits, pendingVerifierSubjectTaskIds, resolveWorkerFleetLimits, } from "./worker-fleet-limits.js";
|
|
33
34
|
import { WorkerLeaseHeartbeat } from "./worker-lease-heartbeat.js";
|
|
34
35
|
import { createLocalWorkerProcessOwnerId } from "./worker-process-owner.js";
|
|
35
|
-
import { WorkerProfileResolver } from "./worker-profile-resolver.js";
|
|
36
|
+
import { WorkerProfileResolver, } from "./worker-profile-resolver.js";
|
|
36
37
|
import { WorkerRecoveryCoordinator } from "./worker-recovery-coordinator.js";
|
|
37
38
|
import { selectWorkerResourcePointers } from "./worker-resource-catalog.js";
|
|
38
39
|
import { materializeWorkerResourceBundle } from "./worker-resource-materializer.js";
|
|
@@ -432,20 +433,27 @@ export class WorkerDelegationController {
|
|
|
432
433
|
createTaskProfile(input) {
|
|
433
434
|
return this.getTaskProfileWriter().createTaskProfile(input);
|
|
434
435
|
}
|
|
435
|
-
|
|
436
|
-
const resolved = this.getWorkerProfileResolver().
|
|
437
|
-
return resolved.ok ? { ok: true,
|
|
436
|
+
resolveWorkerPreset(request, settings) {
|
|
437
|
+
const resolved = this.getWorkerProfileResolver().resolvePreset(request, settings.orchestrationProfile);
|
|
438
|
+
return resolved.ok ? { ok: true, preset: resolved.resolved } : { ok: false, skipReason: resolved.reason };
|
|
438
439
|
}
|
|
439
|
-
resolveRequiredVerifier(profile) {
|
|
440
|
+
resolveRequiredVerifier(profile, modelPinPolicy) {
|
|
440
441
|
if (!profile.requireIndependentVerification)
|
|
441
442
|
return { ok: true };
|
|
442
|
-
const
|
|
443
|
-
if (!
|
|
444
|
-
return { ok: false, skipReason: `independent_verifier_unavailable:${
|
|
443
|
+
const preset = this.getWorkerProfileResolver().resolveVerifierPreset(profile);
|
|
444
|
+
if (!preset.ok)
|
|
445
|
+
return { ok: false, skipReason: `independent_verifier_unavailable:${preset.reason}` };
|
|
446
|
+
const modelPin = resolveWorkerModelPin(modelPinPolicy, "verifier");
|
|
447
|
+
const resolved = this.getWorkerProfileResolver().bindPreset(preset.resolved, modelPin?.binding);
|
|
448
|
+
if (!resolved.ok) {
|
|
449
|
+
const reason = modelPin ? "worker_model_pin_unavailable:verifier" : resolved.reason;
|
|
450
|
+
return { ok: false, skipReason: `independent_verifier_unavailable:${reason}` };
|
|
451
|
+
}
|
|
445
452
|
// Fresh verifier profiles pass through the same shipment admission owner as fresh workers.
|
|
446
453
|
// Recovery-pinned verifier contracts bypass this path and preserve their immutable grant.
|
|
447
454
|
const admitted = resolveWorkerAuthority({
|
|
448
455
|
base: resolved.resolved,
|
|
456
|
+
...(modelPin ? { modelPin: modelPin.binding } : {}),
|
|
449
457
|
modelRegistry: this.deps.getModelRegistry(),
|
|
450
458
|
isModelExhausted: (model) => this.deps.isModelExhausted(model),
|
|
451
459
|
});
|
|
@@ -530,6 +538,12 @@ export class WorkerDelegationController {
|
|
|
530
538
|
const settings = this.deps.getSettingsManager().getWorkerDelegationSettings();
|
|
531
539
|
if (!settings.enabled)
|
|
532
540
|
return { ok: false, skipReason: "worker_delegation_disabled" };
|
|
541
|
+
const modelPinPolicy = pinnedContract
|
|
542
|
+
? { status: "absent" }
|
|
543
|
+
: this.deps.getSettingsManager().getWorkerModelPinPolicy();
|
|
544
|
+
if (modelPinPolicy.status === "invalid") {
|
|
545
|
+
return { ok: false, skipReason: "worker_model_pins_invalid" };
|
|
546
|
+
}
|
|
533
547
|
const parentAgent = request.parentAgentId ? this.lifecycle.getAgent(request.parentAgentId) : undefined;
|
|
534
548
|
if (request.parentAgentId && !parentAgent) {
|
|
535
549
|
return { ok: false, skipReason: "orchestration_parent_agent_unknown" };
|
|
@@ -555,6 +569,7 @@ export class WorkerDelegationController {
|
|
|
555
569
|
}
|
|
556
570
|
}
|
|
557
571
|
let baseShipment;
|
|
572
|
+
let basePreset;
|
|
558
573
|
if (pinnedContract) {
|
|
559
574
|
const pinned = this.getWorkerProfileResolver().resolveContract(pinnedContract.worker);
|
|
560
575
|
if (!pinned.ok)
|
|
@@ -568,22 +583,41 @@ export class WorkerDelegationController {
|
|
|
568
583
|
baseShipment = inherited.resolved;
|
|
569
584
|
}
|
|
570
585
|
else if (request.profileId || settings.orchestrationProfile) {
|
|
571
|
-
const configured = this.
|
|
586
|
+
const configured = this.resolveWorkerPreset(request, settings);
|
|
572
587
|
if (!configured.ok)
|
|
573
588
|
return configured;
|
|
574
|
-
|
|
589
|
+
basePreset = configured.preset;
|
|
590
|
+
}
|
|
591
|
+
const effectiveRole = authority?.role ?? baseShipment?.profile.role ?? basePreset?.profile.role ?? "orchestrator";
|
|
592
|
+
const modelPin = resolveWorkerModelPin(modelPinPolicy, effectiveRole);
|
|
593
|
+
if (basePreset) {
|
|
594
|
+
const bound = this.getWorkerProfileResolver().bindPreset(basePreset, modelPin?.binding);
|
|
595
|
+
if (!bound.ok) {
|
|
596
|
+
return {
|
|
597
|
+
ok: false,
|
|
598
|
+
skipReason: modelPin ? `worker_model_pin_unavailable:${effectiveRole}` : bound.reason,
|
|
599
|
+
};
|
|
600
|
+
}
|
|
601
|
+
baseShipment = bound.resolved;
|
|
575
602
|
}
|
|
576
603
|
const adaptive = pinnedContract
|
|
577
604
|
? { ok: true, shipment: baseShipment }
|
|
578
605
|
: resolveWorkerAuthority({
|
|
579
606
|
authority,
|
|
580
607
|
...(baseShipment ? { base: baseShipment } : {}),
|
|
608
|
+
...(modelPin ? { modelPin: modelPin.binding } : {}),
|
|
581
609
|
...(this.deps.getModel() ? { foregroundModel: this.deps.getModel() } : {}),
|
|
582
610
|
modelRegistry: this.deps.getModelRegistry(),
|
|
583
611
|
isModelExhausted: (model) => this.deps.isModelExhausted(model),
|
|
584
612
|
});
|
|
585
|
-
if (!adaptive.ok)
|
|
586
|
-
return {
|
|
613
|
+
if (!adaptive.ok) {
|
|
614
|
+
return {
|
|
615
|
+
ok: false,
|
|
616
|
+
skipReason: modelPin && adaptive.reason === "orchestration_model_unavailable"
|
|
617
|
+
? `worker_model_pin_unavailable:${effectiveRole}`
|
|
618
|
+
: adaptive.reason,
|
|
619
|
+
};
|
|
620
|
+
}
|
|
587
621
|
let shipment = adaptive.shipment;
|
|
588
622
|
if (parentContract) {
|
|
589
623
|
const narrowed = this.narrowWorkerShipmentContext(shipment, parentContract.worker);
|
|
@@ -609,7 +643,7 @@ export class WorkerDelegationController {
|
|
|
609
643
|
verifierShipment = verifier.resolved;
|
|
610
644
|
}
|
|
611
645
|
else {
|
|
612
|
-
const verifier = this.resolveRequiredVerifier(shipment.profile);
|
|
646
|
+
const verifier = this.resolveRequiredVerifier(shipment.profile, modelPinPolicy);
|
|
613
647
|
if (!verifier.ok)
|
|
614
648
|
return verifier;
|
|
615
649
|
verifierShipment = verifier.shipment;
|
|
@@ -1480,6 +1514,7 @@ export class WorkerDelegationController {
|
|
|
1480
1514
|
startWorkerDelegation: (childRequest) => this.start({ ...childRequest, parentAgentId: agentId }),
|
|
1481
1515
|
runWorkerDelegation: (childRequest) => this.runOnce({ ...childRequest, parentAgentId: agentId }),
|
|
1482
1516
|
orchestrationProfiles: this.getProfileCatalog(),
|
|
1517
|
+
workerModelPinPolicy: this.deps.getSettingsManager().getWorkerModelPinPolicy(),
|
|
1483
1518
|
workerAgentControl: this.agentControl,
|
|
1484
1519
|
caller: { kind: "worker", agentId },
|
|
1485
1520
|
resolveMessageReplayScope: () => ({
|