@caupulican/pi-adaptative 0.84.1 → 0.85.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/CHANGELOG.md +28 -0
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.d.ts.map +1 -1
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.js +14 -8
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.js.map +1 -1
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.ts +14 -8
- package/dist/bundled-resources/skills/deduplicate-by-evidence/SKILL.md +7 -5
- package/dist/bundled-resources/skills/worker-profile-writer/SKILL.md +63 -0
- package/dist/core/autonomy/lane-tool-surface.d.ts.map +1 -1
- package/dist/core/autonomy/lane-tool-surface.js +4 -2
- package/dist/core/autonomy/lane-tool-surface.js.map +1 -1
- package/dist/core/background-lane-controller.d.ts +3 -0
- package/dist/core/background-lane-controller.d.ts.map +1 -1
- package/dist/core/background-lane-controller.js +6 -0
- package/dist/core/background-lane-controller.js.map +1 -1
- package/dist/core/default-tool-surface.d.ts.map +1 -1
- package/dist/core/default-tool-surface.js +1 -0
- package/dist/core/default-tool-surface.js.map +1 -1
- package/dist/core/delegation/worker-delegation-controller.d.ts +7 -0
- package/dist/core/delegation/worker-delegation-controller.d.ts.map +1 -1
- package/dist/core/delegation/worker-delegation-controller.js +28 -0
- package/dist/core/delegation/worker-delegation-controller.js.map +1 -1
- package/dist/core/delegation/worker-profile-resolver.d.ts +2 -0
- package/dist/core/delegation/worker-profile-resolver.d.ts.map +1 -1
- package/dist/core/delegation/worker-profile-resolver.js +46 -11
- package/dist/core/delegation/worker-profile-resolver.js.map +1 -1
- package/dist/core/doctor.d.ts +1 -1
- package/dist/core/doctor.d.ts.map +1 -1
- package/dist/core/doctor.js +5 -4
- package/dist/core/doctor.js.map +1 -1
- package/dist/core/model-capability.d.ts.map +1 -1
- package/dist/core/model-capability.js +1 -0
- package/dist/core/model-capability.js.map +1 -1
- package/dist/core/orchestration/lane-tool-manifests.d.ts +1 -1
- package/dist/core/orchestration/lane-tool-manifests.d.ts.map +1 -1
- package/dist/core/orchestration/lane-tool-manifests.js +6 -1
- package/dist/core/orchestration/lane-tool-manifests.js.map +1 -1
- package/dist/core/orchestration/session-task-profile-store.d.ts +31 -0
- package/dist/core/orchestration/session-task-profile-store.d.ts.map +1 -0
- package/dist/core/orchestration/session-task-profile-store.js +138 -0
- package/dist/core/orchestration/session-task-profile-store.js.map +1 -0
- package/dist/core/orchestration/task-profile-writer.d.ts +58 -0
- package/dist/core/orchestration/task-profile-writer.d.ts.map +1 -0
- package/dist/core/orchestration/task-profile-writer.js +165 -0
- package/dist/core/orchestration/task-profile-writer.js.map +1 -0
- package/dist/core/runtime-builder.d.ts +3 -1
- package/dist/core/runtime-builder.d.ts.map +1 -1
- package/dist/core/runtime-builder.js +14 -0
- package/dist/core/runtime-builder.js.map +1 -1
- package/dist/core/security/untrusted-boundary.d.ts.map +1 -1
- package/dist/core/security/untrusted-boundary.js +4 -6
- package/dist/core/security/untrusted-boundary.js.map +1 -1
- package/dist/core/session-role.d.ts.map +1 -1
- package/dist/core/session-role.js +1 -0
- package/dist/core/session-role.js.map +1 -1
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +21 -23
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/tool-capability-policy.js +1 -1
- package/dist/core/tool-capability-policy.js.map +1 -1
- package/dist/core/tools/bash.d.ts +1 -6
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +2 -26
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/delegate.js +4 -4
- package/dist/core/tools/delegate.js.map +1 -1
- package/dist/core/tools/edit-diff.d.ts +32 -5
- package/dist/core/tools/edit-diff.d.ts.map +1 -1
- package/dist/core/tools/edit-diff.js +137 -69
- package/dist/core/tools/edit-diff.js.map +1 -1
- package/dist/core/tools/edit.d.ts +22 -7
- package/dist/core/tools/edit.d.ts.map +1 -1
- package/dist/core/tools/edit.js +128 -55
- package/dist/core/tools/edit.js.map +1 -1
- package/dist/core/tools/file-mutation-intent.d.ts +70 -0
- package/dist/core/tools/file-mutation-intent.d.ts.map +1 -0
- package/dist/core/tools/file-mutation-intent.js +325 -0
- package/dist/core/tools/file-mutation-intent.js.map +1 -0
- package/dist/core/tools/goal.d.ts.map +1 -1
- package/dist/core/tools/goal.js +41 -18
- package/dist/core/tools/goal.js.map +1 -1
- package/dist/core/tools/index.d.ts +3 -1
- package/dist/core/tools/index.d.ts.map +1 -1
- package/dist/core/tools/index.js +31 -8
- package/dist/core/tools/index.js.map +1 -1
- package/dist/core/tools/profile-writer.d.ts +33 -0
- package/dist/core/tools/profile-writer.d.ts.map +1 -0
- package/dist/core/tools/profile-writer.js +67 -0
- package/dist/core/tools/profile-writer.js.map +1 -0
- package/dist/core/tools/task-steps.d.ts.map +1 -1
- package/dist/core/tools/task-steps.js +6 -11
- package/dist/core/tools/task-steps.js.map +1 -1
- package/dist/core/tools/tmux-dispatch.d.ts +2 -0
- package/dist/core/tools/tmux-dispatch.d.ts.map +1 -1
- package/dist/core/tools/tmux-dispatch.js +16 -2
- package/dist/core/tools/tmux-dispatch.js.map +1 -1
- package/dist/core/tools/write.d.ts +24 -7
- package/dist/core/tools/write.d.ts.map +1 -1
- package/dist/core/tools/write.js +182 -107
- package/dist/core/tools/write.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/jscpd-cli.d.ts +3 -0
- package/dist/jscpd-cli.d.ts.map +1 -0
- package/dist/jscpd-cli.js +22 -0
- package/dist/jscpd-cli.js.map +1 -0
- package/dist/modes/interactive/components/profile-resource-editor.js +2 -2
- package/dist/modes/interactive/components/profile-resource-editor.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts +1 -0
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +85 -3
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +1 -1
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/utils/bundled-jscpd.d.ts +20 -0
- package/dist/utils/bundled-jscpd.d.ts.map +1 -0
- package/dist/utils/bundled-jscpd.js +154 -0
- package/dist/utils/bundled-jscpd.js.map +1 -0
- package/dist/utils/shell.d.ts.map +1 -1
- package/dist/utils/shell.js +11 -0
- package/dist/utils/shell.js.map +1 -1
- package/dist/utils/tools-manager.d.ts +1 -1
- package/dist/utils/tools-manager.d.ts.map +1 -1
- package/dist/utils/tools-manager.js +22 -0
- package/dist/utils/tools-manager.js.map +1 -1
- package/docs/index.md +3 -0
- package/docs/managed-data-tools.md +15 -0
- package/docs/quickstart.md +2 -2
- package/docs/tool-boundary-performance-roadmap-2026-08-02.md +166 -0
- package/docs/tool-repair.md +1 -1
- package/docs/worker-profiles.md +16 -0
- package/examples/extensions/built-in-tool-renderer.ts +12 -5
- 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/minimal-mode.ts +8 -7
- package/examples/extensions/prompt-customizer.ts +4 -2
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/ssh.ts +113 -24
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/npm-shrinkwrap.json +112 -12
- package/package.json +7 -5
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { parseOrchestrationProfile } from "./profile-registry.js";
|
|
2
|
+
export const SESSION_TASK_PROFILE_CUSTOM_TYPE = "session_task_profile";
|
|
3
|
+
export const MAX_SESSION_TASK_PROFILES = 32;
|
|
4
|
+
const BRANCH_STORAGE_REQUIRED = "session task profiles require branch-aware session storage";
|
|
5
|
+
function parseRecord(value) {
|
|
6
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
7
|
+
throw new Error("session task profile record must be an object");
|
|
8
|
+
}
|
|
9
|
+
const candidate = value;
|
|
10
|
+
const keys = Object.keys(candidate);
|
|
11
|
+
if (candidate.version !== 1 ||
|
|
12
|
+
keys.some((key) => !["version", "baseProfileId", "authorProfileId", "profile"].includes(key)) ||
|
|
13
|
+
typeof candidate.baseProfileId !== "string" ||
|
|
14
|
+
candidate.baseProfileId.length === 0 ||
|
|
15
|
+
(candidate.authorProfileId !== undefined &&
|
|
16
|
+
(typeof candidate.authorProfileId !== "string" || candidate.authorProfileId.length === 0))) {
|
|
17
|
+
throw new Error("session task profile record is invalid");
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
baseProfileId: candidate.baseProfileId,
|
|
21
|
+
...(candidate.authorProfileId ? { authorProfileId: candidate.authorProfileId } : {}),
|
|
22
|
+
profile: parseOrchestrationProfile(candidate.profile),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function cloneRecord(record) {
|
|
26
|
+
return structuredClone(record);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Append-only task-profile storage on the active session branch.
|
|
30
|
+
*
|
|
31
|
+
* The common append path walks only entries added since the cached leaf. Branching away from the
|
|
32
|
+
* cached leaf deliberately rebuilds from parent links so abandoned task profiles cannot leak into
|
|
33
|
+
* the active branch.
|
|
34
|
+
*/
|
|
35
|
+
export class SessionTaskProfileStore {
|
|
36
|
+
constructor(sessionManager) {
|
|
37
|
+
this.cachedResult = {
|
|
38
|
+
records: [],
|
|
39
|
+
registry: new Map(),
|
|
40
|
+
diagnostics: [],
|
|
41
|
+
};
|
|
42
|
+
this.sessionManager = sessionManager;
|
|
43
|
+
}
|
|
44
|
+
load() {
|
|
45
|
+
if (typeof this.sessionManager.getLeafId !== "function" || typeof this.sessionManager.getEntry !== "function") {
|
|
46
|
+
this.cachedLeafId = undefined;
|
|
47
|
+
this.cachedResult = {
|
|
48
|
+
records: [],
|
|
49
|
+
registry: new Map(),
|
|
50
|
+
diagnostics: [BRANCH_STORAGE_REQUIRED],
|
|
51
|
+
};
|
|
52
|
+
return this.cloneResult(this.cachedResult);
|
|
53
|
+
}
|
|
54
|
+
const leafId = this.sessionManager.getLeafId();
|
|
55
|
+
if (this.cachedLeafId === leafId)
|
|
56
|
+
return this.cloneResult(this.cachedResult);
|
|
57
|
+
const appended = [];
|
|
58
|
+
let cursor = leafId;
|
|
59
|
+
while (cursor !== null && cursor !== this.cachedLeafId) {
|
|
60
|
+
const entry = this.sessionManager.getEntry(cursor);
|
|
61
|
+
if (!entry) {
|
|
62
|
+
cursor = null;
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
appended.push(entry);
|
|
66
|
+
cursor = entry.parentId;
|
|
67
|
+
}
|
|
68
|
+
const extendsCache = this.cachedLeafId !== undefined && cursor === this.cachedLeafId;
|
|
69
|
+
const records = extendsCache ? this.cachedResult.records.map(cloneRecord) : [];
|
|
70
|
+
const diagnostics = extendsCache ? [...this.cachedResult.diagnostics] : [];
|
|
71
|
+
const registry = new Map(records.map((record) => [record.profile.profileId, record]));
|
|
72
|
+
for (let index = appended.length - 1; index >= 0; index--) {
|
|
73
|
+
const entry = appended[index];
|
|
74
|
+
if (entry.type !== "custom" || entry.customType !== SESSION_TASK_PROFILE_CUSTOM_TYPE)
|
|
75
|
+
continue;
|
|
76
|
+
try {
|
|
77
|
+
const record = parseRecord(entry.data);
|
|
78
|
+
if (records.length >= MAX_SESSION_TASK_PROFILES) {
|
|
79
|
+
diagnostics.push(`ignored ${record.profile.profileId}: session task profile limit exceeded`);
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
if (registry.has(record.profile.profileId)) {
|
|
83
|
+
diagnostics.push(`ignored duplicate session task profile ${record.profile.profileId}`);
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
records.push(record);
|
|
87
|
+
registry.set(record.profile.profileId, record);
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
diagnostics.push(error instanceof Error ? error.message : String(error));
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
this.cachedLeafId = leafId;
|
|
94
|
+
this.cachedResult = { records, registry, diagnostics };
|
|
95
|
+
return this.cloneResult(this.cachedResult);
|
|
96
|
+
}
|
|
97
|
+
append(input) {
|
|
98
|
+
if (typeof this.sessionManager.getLeafId !== "function" ||
|
|
99
|
+
typeof this.sessionManager.getEntry !== "function" ||
|
|
100
|
+
typeof this.sessionManager.appendCustomEntry !== "function") {
|
|
101
|
+
throw new Error(BRANCH_STORAGE_REQUIRED);
|
|
102
|
+
}
|
|
103
|
+
const loaded = this.load();
|
|
104
|
+
if (loaded.records.length >= MAX_SESSION_TASK_PROFILES) {
|
|
105
|
+
throw new Error(`session task profile limit (${MAX_SESSION_TASK_PROFILES}) reached`);
|
|
106
|
+
}
|
|
107
|
+
if (loaded.registry.has(input.profile.profileId)) {
|
|
108
|
+
throw new Error(`session task profile '${input.profile.profileId}' already exists`);
|
|
109
|
+
}
|
|
110
|
+
const record = cloneRecord(input);
|
|
111
|
+
parseOrchestrationProfile(record.profile);
|
|
112
|
+
const persisted = {
|
|
113
|
+
version: 1,
|
|
114
|
+
baseProfileId: record.baseProfileId,
|
|
115
|
+
...(record.authorProfileId ? { authorProfileId: record.authorProfileId } : {}),
|
|
116
|
+
profile: record.profile,
|
|
117
|
+
};
|
|
118
|
+
this.sessionManager.appendCustomEntry(SESSION_TASK_PROFILE_CUSTOM_TYPE, persisted);
|
|
119
|
+
const registry = new Map(loaded.registry);
|
|
120
|
+
registry.set(record.profile.profileId, record);
|
|
121
|
+
this.cachedLeafId = this.sessionManager.getLeafId();
|
|
122
|
+
this.cachedResult = {
|
|
123
|
+
records: [...loaded.records, record],
|
|
124
|
+
registry,
|
|
125
|
+
diagnostics: loaded.diagnostics,
|
|
126
|
+
};
|
|
127
|
+
return cloneRecord(record);
|
|
128
|
+
}
|
|
129
|
+
cloneResult(result) {
|
|
130
|
+
const records = result.records.map(cloneRecord);
|
|
131
|
+
return {
|
|
132
|
+
records,
|
|
133
|
+
registry: new Map(records.map((record) => [record.profile.profileId, record])),
|
|
134
|
+
diagnostics: [...result.diagnostics],
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
//# sourceMappingURL=session-task-profile-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-task-profile-store.js","sourceRoot":"","sources":["../../../src/core/orchestration/session-task-profile-store.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AAElE,MAAM,CAAC,MAAM,gCAAgC,GAAG,sBAAsB,CAAC;AACvE,MAAM,CAAC,MAAM,yBAAyB,GAAG,EAAE,CAAC;AAC5C,MAAM,uBAAuB,GAAG,4DAA4D,CAAC;AAqB7F,SAAS,WAAW,CAAC,KAAc;IAClC,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACjE,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;IAClE,CAAC;IACD,MAAM,SAAS,GAAG,KAAmD,CAAC;IACtE,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACpC,IACC,SAAS,CAAC,OAAO,KAAK,CAAC;QACvB,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,EAAE,eAAe,EAAE,iBAAiB,EAAE,SAAS,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;QAC7F,OAAO,SAAS,CAAC,aAAa,KAAK,QAAQ;QAC3C,SAAS,CAAC,aAAa,CAAC,MAAM,KAAK,CAAC;QACpC,CAAC,SAAS,CAAC,eAAe,KAAK,SAAS;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AG;YACnB,OAAO,EAAE,CAAC,GAAG,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC;YACpC,QAAQ;YACR,WAAW,EAAE,MAAM,CAAC,WAAW;SAC/B,CAAC;QACF,OAAO,WAAW,CAAC,MAAM,CAAC,CAAC;IAC5B,CAAC;IAEO,WAAW,CAAC,MAAoC;QACvD,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;QAChD,OAAO;YACN,OAAO;YACP,QAAQ,EAAE,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC,CAAC;YAC9E,WAAW,EAAE,CAAC,GAAG,MAAM,CAAC,WAAW,CAAC;SACpC,CAAC;IACH,CAAC;CACD","sourcesContent":["import type { SessionEntry, SessionManager } from \"@caupulican/pi-agent-core/node\";\nimport type { OrchestrationProfile } from \"./contracts.ts\";\nimport { parseOrchestrationProfile } from \"./profile-registry.ts\";\n\nexport const SESSION_TASK_PROFILE_CUSTOM_TYPE = \"session_task_profile\";\nexport const MAX_SESSION_TASK_PROFILES = 32;\nconst BRANCH_STORAGE_REQUIRED = \"session task profiles require branch-aware session storage\";\n\nexport interface SessionTaskProfileRecord {\n\tbaseProfileId: string;\n\tauthorProfileId?: string;\n\tprofile: OrchestrationProfile;\n}\n\nexport interface SessionTaskProfileLoadResult {\n\trecords: SessionTaskProfileRecord[];\n\tregistry: ReadonlyMap<string, SessionTaskProfileRecord>;\n\tdiagnostics: string[];\n}\n\ninterface PersistedSessionTaskProfileRecord {\n\tversion: 1;\n\tbaseProfileId: string;\n\tauthorProfileId?: string;\n\tprofile: OrchestrationProfile;\n}\n\nfunction parseRecord(value: unknown): SessionTaskProfileRecord {\n\tif (!value || typeof value !== \"object\" || Array.isArray(value)) {\n\t\tthrow new Error(\"session task profile record must be an object\");\n\t}\n\tconst candidate = value as Partial<PersistedSessionTaskProfileRecord>;\n\tconst keys = Object.keys(candidate);\n\tif (\n\t\tcandidate.version !== 1 ||\n\t\tkeys.some((key) => ![\"version\", \"baseProfileId\", \"authorProfileId\", \"profile\"].includes(key)) ||\n\t\ttypeof candidate.baseProfileId !== \"string\" ||\n\t\tcandidate.baseProfileId.length === 0 ||\n\t\t(candidate.authorProfileId !== undefined &&\n\t\t\t(typeof candidate.authorProfileId !== \"string\" || candidate.authorProfileId.length === 0))\n\t) {\n\t\tthrow new Error(\"session task profile record is invalid\");\n\t}\n\treturn {\n\t\tbaseProfileId: candidate.baseProfileId,\n\t\t...(candidate.authorProfileId ? { authorProfileId: candidate.authorProfileId } : {}),\n\t\tprofile: parseOrchestrationProfile(candidate.profile),\n\t};\n}\n\nfunction cloneRecord(record: SessionTaskProfileRecord): SessionTaskProfileRecord {\n\treturn structuredClone(record);\n}\n\n/**\n * Append-only task-profile storage on the active session branch.\n *\n * The common append path walks only entries added since the cached leaf. Branching away from the\n * cached leaf deliberately rebuilds from parent links so abandoned task profiles cannot leak into\n * the active branch.\n */\nexport class SessionTaskProfileStore {\n\tprivate readonly sessionManager: SessionManager;\n\tprivate cachedLeafId: string | null | undefined;\n\tprivate cachedResult: SessionTaskProfileLoadResult = {\n\t\trecords: [],\n\t\tregistry: new Map(),\n\t\tdiagnostics: [],\n\t};\n\n\tconstructor(sessionManager: SessionManager) {\n\t\tthis.sessionManager = sessionManager;\n\t}\n\n\tload(): SessionTaskProfileLoadResult {\n\t\tif (typeof this.sessionManager.getLeafId !== \"function\" || typeof this.sessionManager.getEntry !== \"function\") {\n\t\t\tthis.cachedLeafId = undefined;\n\t\t\tthis.cachedResult = {\n\t\t\t\trecords: [],\n\t\t\t\tregistry: new Map(),\n\t\t\t\tdiagnostics: [BRANCH_STORAGE_REQUIRED],\n\t\t\t};\n\t\t\treturn this.cloneResult(this.cachedResult);\n\t\t}\n\t\tconst leafId = this.sessionManager.getLeafId();\n\t\tif (this.cachedLeafId === leafId) return this.cloneResult(this.cachedResult);\n\n\t\tconst appended: SessionEntry[] = [];\n\t\tlet cursor = leafId;\n\t\twhile (cursor !== null && cursor !== this.cachedLeafId) {\n\t\t\tconst entry = this.sessionManager.getEntry(cursor);\n\t\t\tif (!entry) {\n\t\t\t\tcursor = null;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tappended.push(entry);\n\t\t\tcursor = entry.parentId;\n\t\t}\n\n\t\tconst extendsCache = this.cachedLeafId !== undefined && cursor === this.cachedLeafId;\n\t\tconst records = extendsCache ? this.cachedResult.records.map(cloneRecord) : [];\n\t\tconst diagnostics = extendsCache ? [...this.cachedResult.diagnostics] : [];\n\t\tconst registry = new Map(records.map((record) => [record.profile.profileId, record]));\n\n\t\tfor (let index = appended.length - 1; index >= 0; index--) {\n\t\t\tconst entry = appended[index];\n\t\t\tif (entry.type !== \"custom\" || entry.customType !== SESSION_TASK_PROFILE_CUSTOM_TYPE) continue;\n\t\t\ttry {\n\t\t\t\tconst record = parseRecord(entry.data);\n\t\t\t\tif (records.length >= MAX_SESSION_TASK_PROFILES) {\n\t\t\t\t\tdiagnostics.push(`ignored ${record.profile.profileId}: session task profile limit exceeded`);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (registry.has(record.profile.profileId)) {\n\t\t\t\t\tdiagnostics.push(`ignored duplicate session task profile ${record.profile.profileId}`);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\trecords.push(record);\n\t\t\t\tregistry.set(record.profile.profileId, record);\n\t\t\t} catch (error) {\n\t\t\t\tdiagnostics.push(error instanceof Error ? error.message : String(error));\n\t\t\t}\n\t\t}\n\n\t\tthis.cachedLeafId = leafId;\n\t\tthis.cachedResult = { records, registry, diagnostics };\n\t\treturn this.cloneResult(this.cachedResult);\n\t}\n\n\tappend(input: SessionTaskProfileRecord): SessionTaskProfileRecord {\n\t\tif (\n\t\t\ttypeof this.sessionManager.getLeafId !== \"function\" ||\n\t\t\ttypeof this.sessionManager.getEntry !== \"function\" ||\n\t\t\ttypeof this.sessionManager.appendCustomEntry !== \"function\"\n\t\t) {\n\t\t\tthrow new Error(BRANCH_STORAGE_REQUIRED);\n\t\t}\n\t\tconst loaded = this.load();\n\t\tif (loaded.records.length >= MAX_SESSION_TASK_PROFILES) {\n\t\t\tthrow new Error(`session task profile limit (${MAX_SESSION_TASK_PROFILES}) reached`);\n\t\t}\n\t\tif (loaded.registry.has(input.profile.profileId)) {\n\t\t\tthrow new Error(`session task profile '${input.profile.profileId}' already exists`);\n\t\t}\n\t\tconst record = cloneRecord(input);\n\t\tparseOrchestrationProfile(record.profile);\n\t\tconst persisted: PersistedSessionTaskProfileRecord = {\n\t\t\tversion: 1,\n\t\t\tbaseProfileId: record.baseProfileId,\n\t\t\t...(record.authorProfileId ? { authorProfileId: record.authorProfileId } : {}),\n\t\t\tprofile: record.profile,\n\t\t};\n\t\tthis.sessionManager.appendCustomEntry(SESSION_TASK_PROFILE_CUSTOM_TYPE, persisted);\n\t\tconst registry = new Map(loaded.registry);\n\t\tregistry.set(record.profile.profileId, record);\n\t\tthis.cachedLeafId = this.sessionManager.getLeafId();\n\t\tthis.cachedResult = {\n\t\t\trecords: [...loaded.records, record],\n\t\t\tregistry,\n\t\t\tdiagnostics: loaded.diagnostics,\n\t\t};\n\t\treturn cloneRecord(record);\n\t}\n\n\tprivate cloneResult(result: SessionTaskProfileLoadResult): SessionTaskProfileLoadResult {\n\t\tconst records = result.records.map(cloneRecord);\n\t\treturn {\n\t\t\trecords,\n\t\t\tregistry: new Map(records.map((record) => [record.profile.profileId, record])),\n\t\t\tdiagnostics: [...result.diagnostics],\n\t\t};\n\t}\n}\n"]}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { ModelRegistry } from "../model-registry.ts";
|
|
2
|
+
import type { SettingsManager } from "../settings-manager.ts";
|
|
3
|
+
import type { OrchestrationProfile, OrchestrationThinkingLevel, RiskBudget } from "./contracts.ts";
|
|
4
|
+
import type { SessionTaskProfileStore } from "./session-task-profile-store.ts";
|
|
5
|
+
export interface TaskProfileModelSelection {
|
|
6
|
+
provider: string;
|
|
7
|
+
modelId: string;
|
|
8
|
+
thinkingLevel: OrchestrationThinkingLevel;
|
|
9
|
+
}
|
|
10
|
+
export interface TaskProfileCreateInput {
|
|
11
|
+
task: string;
|
|
12
|
+
baseProfileId?: string;
|
|
13
|
+
model?: TaskProfileModelSelection;
|
|
14
|
+
toolNames?: readonly string[];
|
|
15
|
+
resourceProfileNames?: readonly string[];
|
|
16
|
+
budget?: RiskBudget;
|
|
17
|
+
}
|
|
18
|
+
export interface TaskProfileInspection {
|
|
19
|
+
baseProfiles: Array<{
|
|
20
|
+
profileId: string;
|
|
21
|
+
role: string;
|
|
22
|
+
description: string;
|
|
23
|
+
}>;
|
|
24
|
+
models: Array<{
|
|
25
|
+
provider: string;
|
|
26
|
+
modelId: string;
|
|
27
|
+
thinkingLevels: readonly OrchestrationThinkingLevel[];
|
|
28
|
+
}>;
|
|
29
|
+
}
|
|
30
|
+
export interface TaskProfileCreateResult {
|
|
31
|
+
created: boolean;
|
|
32
|
+
reason?: string;
|
|
33
|
+
profileId?: string;
|
|
34
|
+
baseProfileId?: string;
|
|
35
|
+
changedFields?: string[];
|
|
36
|
+
}
|
|
37
|
+
export interface TaskProfileWriterPort {
|
|
38
|
+
inspectTaskProfileOptions(): TaskProfileInspection;
|
|
39
|
+
createTaskProfile(input: TaskProfileCreateInput): TaskProfileCreateResult;
|
|
40
|
+
}
|
|
41
|
+
export interface TaskProfileWriterOptions {
|
|
42
|
+
agentDir: string;
|
|
43
|
+
cwd: string;
|
|
44
|
+
store: SessionTaskProfileStore;
|
|
45
|
+
getSettingsManager(): SettingsManager;
|
|
46
|
+
getModelRegistry(): ModelRegistry;
|
|
47
|
+
isModelExhausted(provider: string, modelId: string): boolean;
|
|
48
|
+
getActiveOrchestrationProfile(): OrchestrationProfile | undefined;
|
|
49
|
+
}
|
|
50
|
+
export declare class TaskProfileWriter implements TaskProfileWriterPort {
|
|
51
|
+
private readonly options;
|
|
52
|
+
constructor(options: TaskProfileWriterOptions);
|
|
53
|
+
inspectTaskProfileOptions(): TaskProfileInspection;
|
|
54
|
+
createTaskProfile(input: TaskProfileCreateInput): TaskProfileCreateResult;
|
|
55
|
+
private authorizedBaseProfiles;
|
|
56
|
+
private loadOwnerProfiles;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=task-profile-writer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"task-profile-writer.d.ts","sourceRoot":"","sources":["../../../src/core/orchestration/task-profile-writer.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,KAAK,EAGX,oBAAoB,EACpB,0BAA0B,EAC1B,UAAU,EACV,MAAM,gBAAgB,CAAC;AAKxB,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAE/E,MAAM,WAAW,yBAAyB;IACzC,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,0BAA0B,CAAC;CAC1C;AAED,MAAM,WAAW,sBAAsB;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,KAAK,CAAC,EAAE,yBAAyB,CAAC;IAClC,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC9B,oBAAoB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACzC,MAAM,CAAC,EAAE,UAAU,CAAC;CACpB;AAED,MAAM,WAAW,qBAAqB;IACrC,YAAY,EAAE,KAAK,CAAC;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IA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HESTRATION_DESCRIPTION_LENGTH } from "./contracts.js";
|
|
4
|
+
import { resolvePinnedOrchestrationModel } from "./model-binding.js";
|
|
5
|
+
import { validateOrchestrationProfile } from "./profile-registry.js";
|
|
6
|
+
import { OrchestrationProfileStore } from "./profile-store.js";
|
|
7
|
+
const MAX_INSPECTED_MODELS = 64;
|
|
8
|
+
const MAX_TASK_DESCRIPTION_LENGTH = 3_500;
|
|
9
|
+
const MAX_BUDGET_KEYS = ["maxTokens", "maxWallClockMs", "maxCostUsd", "maxAttempts", "maxToolCalls"];
|
|
10
|
+
function sameStrings(left, right) {
|
|
11
|
+
return left.length === right.length && left.every((value, index) => value === right[index]);
|
|
12
|
+
}
|
|
13
|
+
function isExactSubset(candidate, ceiling) {
|
|
14
|
+
const allowed = new Set(ceiling);
|
|
15
|
+
const unique = new Set(candidate);
|
|
16
|
+
return unique.size === candidate.length && candidate.every((value) => allowed.has(value));
|
|
17
|
+
}
|
|
18
|
+
function narrowBudget(base, patch) {
|
|
19
|
+
if (!patch)
|
|
20
|
+
return structuredClone(base);
|
|
21
|
+
const narrowed = { ...base };
|
|
22
|
+
for (const key of MAX_BUDGET_KEYS) {
|
|
23
|
+
const requested = patch[key];
|
|
24
|
+
if (requested === undefined)
|
|
25
|
+
continue;
|
|
26
|
+
const ceiling = base[key];
|
|
27
|
+
if (ceiling !== undefined && requested > ceiling)
|
|
28
|
+
return undefined;
|
|
29
|
+
narrowed[key] = requested;
|
|
30
|
+
}
|
|
31
|
+
if (patch.requireApprovalAboveCostUsd !== undefined) {
|
|
32
|
+
const ceiling = base.requireApprovalAboveCostUsd;
|
|
33
|
+
if (ceiling !== undefined && patch.requireApprovalAboveCostUsd > ceiling)
|
|
34
|
+
return undefined;
|
|
35
|
+
narrowed.requireApprovalAboveCostUsd = patch.requireApprovalAboveCostUsd;
|
|
36
|
+
}
|
|
37
|
+
return narrowed;
|
|
38
|
+
}
|
|
39
|
+
function sameBudget(left, right) {
|
|
40
|
+
return (MAX_BUDGET_KEYS.every((key) => left[key] === right[key]) &&
|
|
41
|
+
left.requireApprovalAboveCostUsd === right.requireApprovalAboveCostUsd);
|
|
42
|
+
}
|
|
43
|
+
function sameModelPolicy(left, right) {
|
|
44
|
+
return (left.mode === right.mode &&
|
|
45
|
+
left.candidates.length === right.candidates.length &&
|
|
46
|
+
left.candidates.every((candidate, index) => {
|
|
47
|
+
const other = right.candidates[index];
|
|
48
|
+
return (other !== undefined &&
|
|
49
|
+
candidate.provider === other.provider &&
|
|
50
|
+
candidate.modelId === other.modelId &&
|
|
51
|
+
candidate.thinkingLevel === other.thinkingLevel);
|
|
52
|
+
}));
|
|
53
|
+
}
|
|
54
|
+
export class TaskProfileWriter {
|
|
55
|
+
constructor(options) {
|
|
56
|
+
this.options = options;
|
|
57
|
+
}
|
|
58
|
+
inspectTaskProfileOptions() {
|
|
59
|
+
const baseProfiles = this.authorizedBaseProfiles().map((profile) => ({
|
|
60
|
+
profileId: profile.profileId,
|
|
61
|
+
role: profile.role,
|
|
62
|
+
description: profile.description,
|
|
63
|
+
}));
|
|
64
|
+
const models = this.options
|
|
65
|
+
.getModelRegistry()
|
|
66
|
+
.getAvailable()
|
|
67
|
+
.filter((model) => !this.options.isModelExhausted(model.provider, model.id))
|
|
68
|
+
.sort((left, right) => `${left.provider}/${left.id}`.localeCompare(`${right.provider}/${right.id}`))
|
|
69
|
+
.slice(0, MAX_INSPECTED_MODELS)
|
|
70
|
+
.map((model) => ({
|
|
71
|
+
provider: model.provider,
|
|
72
|
+
modelId: model.id,
|
|
73
|
+
thinkingLevels: getSupportedThinkingLevels(model),
|
|
74
|
+
}));
|
|
75
|
+
return { baseProfiles, models };
|
|
76
|
+
}
|
|
77
|
+
createTaskProfile(input) {
|
|
78
|
+
try {
|
|
79
|
+
const task = input.task.trim();
|
|
80
|
+
if (!task || task.length > MAX_TASK_DESCRIPTION_LENGTH) {
|
|
81
|
+
return { created: false, reason: "task_profile_description_invalid" };
|
|
82
|
+
}
|
|
83
|
+
const bases = this.authorizedBaseProfiles();
|
|
84
|
+
const baseProfileId = input.baseProfileId?.trim() || (bases.length === 1 ? bases[0].profileId : undefined);
|
|
85
|
+
if (!baseProfileId)
|
|
86
|
+
return { created: false, reason: "task_profile_base_required" };
|
|
87
|
+
const ownerProfiles = this.loadOwnerProfiles();
|
|
88
|
+
const base = ownerProfiles.get(baseProfileId);
|
|
89
|
+
if (!base || base.role === "orchestrator") {
|
|
90
|
+
return { created: false, reason: "task_profile_base_not_found" };
|
|
91
|
+
}
|
|
92
|
+
if (!bases.some((candidate) => candidate.profileId === baseProfileId)) {
|
|
93
|
+
return { created: false, reason: "task_profile_base_not_authorized" };
|
|
94
|
+
}
|
|
95
|
+
const toolNames = input.toolNames ? [...input.toolNames] : [...base.toolNames];
|
|
96
|
+
if (!isExactSubset(toolNames, base.toolNames)) {
|
|
97
|
+
return { created: false, reason: "task_profile_tool_authority_expansion" };
|
|
98
|
+
}
|
|
99
|
+
const resourceProfileNames = input.resourceProfileNames
|
|
100
|
+
? [...input.resourceProfileNames]
|
|
101
|
+
: [...base.resourceProfileNames];
|
|
102
|
+
if (!isExactSubset(resourceProfileNames, base.resourceProfileNames)) {
|
|
103
|
+
return { created: false, reason: "task_profile_resource_authority_expansion" };
|
|
104
|
+
}
|
|
105
|
+
const budget = narrowBudget(base.budget, input.budget);
|
|
106
|
+
if (!budget)
|
|
107
|
+
return { created: false, reason: "task_profile_budget_expansion" };
|
|
108
|
+
let modelPolicy = structuredClone(base.modelPolicy);
|
|
109
|
+
if (input.model) {
|
|
110
|
+
const binding = { ...input.model };
|
|
111
|
+
const resolved = resolvePinnedOrchestrationModel(binding, this.options.getModelRegistry(), (model) => this.options.isModelExhausted(model.provider, model.id));
|
|
112
|
+
if (!resolved)
|
|
113
|
+
return { created: false, reason: "task_profile_model_unavailable" };
|
|
114
|
+
modelPolicy = { mode: "fixed", candidates: [binding] };
|
|
115
|
+
}
|
|
116
|
+
const now = new Date().toISOString();
|
|
117
|
+
const profile = structuredClone(base);
|
|
118
|
+
delete profile.sourcePath;
|
|
119
|
+
profile.profileId = `task-${randomUUID()}`;
|
|
120
|
+
profile.description = `Task-scoped worker: ${task}`.slice(0, MAX_ORCHESTRATION_DESCRIPTION_LENGTH);
|
|
121
|
+
profile.modelPolicy = modelPolicy;
|
|
122
|
+
profile.toolNames = toolNames;
|
|
123
|
+
profile.resourceProfileNames = resourceProfileNames;
|
|
124
|
+
profile.budget = budget;
|
|
125
|
+
profile.createdAt = now;
|
|
126
|
+
profile.updatedAt = now;
|
|
127
|
+
validateOrchestrationProfile(profile);
|
|
128
|
+
const activeProfile = this.options.getActiveOrchestrationProfile();
|
|
129
|
+
this.options.store.append({
|
|
130
|
+
baseProfileId,
|
|
131
|
+
...(activeProfile ? { authorProfileId: activeProfile.profileId } : {}),
|
|
132
|
+
profile,
|
|
133
|
+
});
|
|
134
|
+
const changedFields = ["description"];
|
|
135
|
+
if (input.model && !sameModelPolicy(modelPolicy, base.modelPolicy))
|
|
136
|
+
changedFields.push("model");
|
|
137
|
+
if (!sameStrings(toolNames, base.toolNames))
|
|
138
|
+
changedFields.push("tools");
|
|
139
|
+
if (!sameStrings(resourceProfileNames, base.resourceProfileNames))
|
|
140
|
+
changedFields.push("resources");
|
|
141
|
+
if (!sameBudget(budget, base.budget))
|
|
142
|
+
changedFields.push("budget");
|
|
143
|
+
return { created: true, profileId: profile.profileId, baseProfileId, changedFields };
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
return { created: false, reason: error instanceof Error ? error.message : String(error) };
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
authorizedBaseProfiles() {
|
|
150
|
+
const active = this.options.getActiveOrchestrationProfile();
|
|
151
|
+
if (active && active.role !== "orchestrator")
|
|
152
|
+
return [];
|
|
153
|
+
const allowed = active ? new Set(active.dispatchProfileIds) : undefined;
|
|
154
|
+
return [...this.loadOwnerProfiles().values()].filter((profile) => profile.role !== "orchestrator" && (!allowed || allowed.has(profile.profileId)));
|
|
155
|
+
}
|
|
156
|
+
loadOwnerProfiles() {
|
|
157
|
+
const profiles = new OrchestrationProfileStore({
|
|
158
|
+
agentDir: this.options.agentDir,
|
|
159
|
+
cwd: this.options.cwd,
|
|
160
|
+
projectTrusted: this.options.getSettingsManager().isProjectTrusted(),
|
|
161
|
+
}).load().profiles;
|
|
162
|
+
return new Map(profiles.map((profile) => [profile.profileId, profile]));
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
//# sourceMappingURL=task-profile-writer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"task-profile-writer.js","sourceRoot":"","sources":["../../../src/core/orchestration/task-profile-writer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,0BAA0B,EAAE,MAAM,mBAAmB,CAAC;AAU/D,OAAO,EAAE,oCAAoC,EAAE,MAAM,gBAAgB,CAAC;AACtE,OAAO,EAAE,+BAA+B,EAAE,MAAM,oBAAoB,CAAC;AACrE,OAAO,EAAE,4BAA4B,EAAE,MAAM,uBAAuB,CAAC;AACrE,OAAO,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AAkD/D,MAAM,oBAAoB,GAAG,EAAE,CAAC;AAChC,MAAM,2BAA2B,GAAG,KAAK,CAAC;AAC1C,MAAM,eAAe,GAAG,CAAC,WAAW,EAAE,gBAAgB,EAAE,YAAY,EAAE,aAAa,EAAE,cAAc,CAAU,CAAC;AAE9G,SAAS,WAAW,CAAC,IAAuB,EAAE,KAAwB;IACrE,OAAO,IAAI,CAAC,MAAM,KAAK,KAAK,CAAC,MAAM,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;AAC7F,CAAC;AAED,SAAS,aAAa,CAAC,SAA4B,EAAE,OAA0B;IAC9E,MAAM,OAAO,GAAG,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,CAAC,6BAA6B,EAAE,CAAC;QAC5D,IAAI,MAAM,IAAI,MAAM,CAAC,IAAI,KAAK,cAAc;YAAE,OAAO,EAAE,CAAC;QACxD,MAAM,OAAO,GAAG,MAAM,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QACxE,OAAO,CAAC,GAAG,IAAI,CAAC,iBAAiB,EAAE,CAAC,MAAM,EAAE,CAAC,CAAC,MAAM,CACnD,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,KAAK,cAAc,IAAI,CAAC,CAAC,OAAO,IAAI,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAC5F,CAAC;IACH,CAAC;IAEO,iBAAiB;QACxB,MAAM,QAAQ,GAAG,IAAI,yBAAyB,CAAC;YAC9C,QAAQ,EAAE,IAAI,CAAC,OAAO,CAAC,QAAQ;YAC/B,GAAG,EAAE,IAAI,CAAC,OAAO,CAAC,GAAG;YACrB,cAAc,EAAE,IAAI,CAAC,OAAO,CAAC,kBAAkB,EAAE,CAAC,gBAAgB,EAAE;SACpE,CAAC,CAAC,IAAI,EAAE,CAAC,QAAQ,CAAC;QACnB,OAAO,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IACzE,CAAC;CACD","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport { getSupportedThinkingLevels } from \"@caupulican/pi-ai\";\nimport type { ModelRegistry } from \"../model-registry.ts\";\nimport type { SettingsManager } from \"../settings-manager.ts\";\nimport type {\n\tOrchestrationModelBinding,\n\tOrchestrationModelPolicy,\n\tOrchestrationProfile,\n\tOrchestrationThinkingLevel,\n\tRiskBudget,\n} from \"./contracts.ts\";\nimport { MAX_ORCHESTRATION_DESCRIPTION_LENGTH } from \"./contracts.ts\";\nimport { resolvePinnedOrchestrationModel } from \"./model-binding.ts\";\nimport { validateOrchestrationProfile } from \"./profile-registry.ts\";\nimport { OrchestrationProfileStore } from \"./profile-store.ts\";\nimport type { SessionTaskProfileStore } from \"./session-task-profile-store.ts\";\n\nexport interface TaskProfileModelSelection {\n\tprovider: string;\n\tmodelId: string;\n\tthinkingLevel: OrchestrationThinkingLevel;\n}\n\nexport interface TaskProfileCreateInput {\n\ttask: string;\n\tbaseProfileId?: string;\n\tmodel?: TaskProfileModelSelection;\n\ttoolNames?: readonly string[];\n\tresourceProfileNames?: readonly string[];\n\tbudget?: RiskBudget;\n}\n\nexport interface TaskProfileInspection {\n\tbaseProfiles: Array<{ profileId: string; role: string; description: string }>;\n\tmodels: Array<{\n\t\tprovider: string;\n\t\tmodelId: string;\n\t\tthinkingLevels: readonly OrchestrationThinkingLevel[];\n\t}>;\n}\n\nexport interface TaskProfileCreateResult {\n\tcreated: boolean;\n\treason?: string;\n\tprofileId?: string;\n\tbaseProfileId?: string;\n\tchangedFields?: string[];\n}\n\nexport interface TaskProfileWriterPort {\n\tinspectTaskProfileOptions(): TaskProfileInspection;\n\tcreateTaskProfile(input: TaskProfileCreateInput): TaskProfileCreateResult;\n}\n\nexport interface TaskProfileWriterOptions {\n\tagentDir: string;\n\tcwd: string;\n\tstore: SessionTaskProfileStore;\n\tgetSettingsManager(): SettingsManager;\n\tgetModelRegistry(): ModelRegistry;\n\tisModelExhausted(provider: string, modelId: string): boolean;\n\tgetActiveOrchestrationProfile(): OrchestrationProfile | undefined;\n}\n\nconst MAX_INSPECTED_MODELS = 64;\nconst MAX_TASK_DESCRIPTION_LENGTH = 3_500;\nconst MAX_BUDGET_KEYS = [\"maxTokens\", \"maxWallClockMs\", \"maxCostUsd\", \"maxAttempts\", \"maxToolCalls\"] as const;\n\nfunction sameStrings(left: readonly string[], right: readonly string[]): boolean {\n\treturn left.length === right.length && left.every((value, index) => value === right[index]);\n}\n\nfunction isExactSubset(candidate: readonly string[], ceiling: readonly string[]): boolean {\n\tconst allowed = new Set(ceiling);\n\tconst unique = new Set(candidate);\n\treturn unique.size === candidate.length && candidate.every((value) => allowed.has(value));\n}\n\nfunction narrowBudget(base: RiskBudget, patch: RiskBudget | undefined): RiskBudget | undefined {\n\tif (!patch) return structuredClone(base);\n\tconst narrowed: RiskBudget = { ...base };\n\tfor (const key of MAX_BUDGET_KEYS) {\n\t\tconst requested = patch[key];\n\t\tif (requested === undefined) continue;\n\t\tconst ceiling = base[key];\n\t\tif (ceiling !== undefined && requested > ceiling) return undefined;\n\t\tnarrowed[key] = requested;\n\t}\n\tif (patch.requireApprovalAboveCostUsd !== undefined) {\n\t\tconst ceiling = base.requireApprovalAboveCostUsd;\n\t\tif (ceiling !== undefined && patch.requireApprovalAboveCostUsd > ceiling) return undefined;\n\t\tnarrowed.requireApprovalAboveCostUsd = patch.requireApprovalAboveCostUsd;\n\t}\n\treturn narrowed;\n}\n\nfunction sameBudget(left: RiskBudget, right: RiskBudget): boolean {\n\treturn (\n\t\tMAX_BUDGET_KEYS.every((key) => left[key] === right[key]) &&\n\t\tleft.requireApprovalAboveCostUsd === right.requireApprovalAboveCostUsd\n\t);\n}\n\nfunction sameModelPolicy(left: OrchestrationModelPolicy, right: OrchestrationModelPolicy): boolean {\n\treturn (\n\t\tleft.mode === right.mode &&\n\t\tleft.candidates.length === right.candidates.length &&\n\t\tleft.candidates.every((candidate, index) => {\n\t\t\tconst other = right.candidates[index];\n\t\t\treturn (\n\t\t\t\tother !== undefined &&\n\t\t\t\tcandidate.provider === other.provider &&\n\t\t\t\tcandidate.modelId === other.modelId &&\n\t\t\t\tcandidate.thinkingLevel === other.thinkingLevel\n\t\t\t);\n\t\t})\n\t);\n}\n\nexport class TaskProfileWriter implements TaskProfileWriterPort {\n\tprivate readonly options: TaskProfileWriterOptions;\n\n\tconstructor(options: TaskProfileWriterOptions) {\n\t\tthis.options = options;\n\t}\n\n\tinspectTaskProfileOptions(): TaskProfileInspection {\n\t\tconst baseProfiles = this.authorizedBaseProfiles().map((profile) => ({\n\t\t\tprofileId: profile.profileId,\n\t\t\trole: profile.role,\n\t\t\tdescription: profile.description,\n\t\t}));\n\t\tconst models = this.options\n\t\t\t.getModelRegistry()\n\t\t\t.getAvailable()\n\t\t\t.filter((model) => !this.options.isModelExhausted(model.provider, model.id))\n\t\t\t.sort((left, right) => `${left.provider}/${left.id}`.localeCompare(`${right.provider}/${right.id}`))\n\t\t\t.slice(0, MAX_INSPECTED_MODELS)\n\t\t\t.map((model) => ({\n\t\t\t\tprovider: model.provider,\n\t\t\t\tmodelId: model.id,\n\t\t\t\tthinkingLevels: getSupportedThinkingLevels(model),\n\t\t\t}));\n\t\treturn { baseProfiles, models };\n\t}\n\n\tcreateTaskProfile(input: TaskProfileCreateInput): TaskProfileCreateResult {\n\t\ttry {\n\t\t\tconst task = input.task.trim();\n\t\t\tif (!task || task.length > MAX_TASK_DESCRIPTION_LENGTH) {\n\t\t\t\treturn { created: false, reason: \"task_profile_description_invalid\" };\n\t\t\t}\n\t\t\tconst bases = this.authorizedBaseProfiles();\n\t\t\tconst baseProfileId = input.baseProfileId?.trim() || (bases.length === 1 ? bases[0].profileId : undefined);\n\t\t\tif (!baseProfileId) return { created: false, reason: \"task_profile_base_required\" };\n\t\t\tconst ownerProfiles = this.loadOwnerProfiles();\n\t\t\tconst base = ownerProfiles.get(baseProfileId);\n\t\t\tif (!base || base.role === \"orchestrator\") {\n\t\t\t\treturn { created: false, reason: \"task_profile_base_not_found\" };\n\t\t\t}\n\t\t\tif (!bases.some((candidate) => candidate.profileId === baseProfileId)) {\n\t\t\t\treturn { created: false, reason: \"task_profile_base_not_authorized\" };\n\t\t\t}\n\n\t\t\tconst toolNames = input.toolNames ? [...input.toolNames] : [...base.toolNames];\n\t\t\tif (!isExactSubset(toolNames, base.toolNames)) {\n\t\t\t\treturn { created: false, reason: \"task_profile_tool_authority_expansion\" };\n\t\t\t}\n\t\t\tconst resourceProfileNames = input.resourceProfileNames\n\t\t\t\t? [...input.resourceProfileNames]\n\t\t\t\t: [...base.resourceProfileNames];\n\t\t\tif (!isExactSubset(resourceProfileNames, base.resourceProfileNames)) {\n\t\t\t\treturn { created: false, reason: \"task_profile_resource_authority_expansion\" };\n\t\t\t}\n\t\t\tconst budget = narrowBudget(base.budget, input.budget);\n\t\t\tif (!budget) return { created: false, reason: \"task_profile_budget_expansion\" };\n\n\t\t\tlet modelPolicy = structuredClone(base.modelPolicy);\n\t\t\tif (input.model) {\n\t\t\t\tconst binding: OrchestrationModelBinding = { ...input.model };\n\t\t\t\tconst resolved = resolvePinnedOrchestrationModel(binding, this.options.getModelRegistry(), (model) =>\n\t\t\t\t\tthis.options.isModelExhausted(model.provider, model.id),\n\t\t\t\t);\n\t\t\t\tif (!resolved) return { created: false, reason: \"task_profile_model_unavailable\" };\n\t\t\t\tmodelPolicy = { mode: \"fixed\", candidates: [binding] };\n\t\t\t}\n\n\t\t\tconst now = new Date().toISOString();\n\t\t\tconst profile = structuredClone(base);\n\t\t\tdelete profile.sourcePath;\n\t\t\tprofile.profileId = `task-${randomUUID()}`;\n\t\t\tprofile.description = `Task-scoped worker: ${task}`.slice(0, MAX_ORCHESTRATION_DESCRIPTION_LENGTH);\n\t\t\tprofile.modelPolicy = modelPolicy;\n\t\t\tprofile.toolNames = toolNames;\n\t\t\tprofile.resourceProfileNames = resourceProfileNames;\n\t\t\tprofile.budget = budget;\n\t\t\tprofile.createdAt = now;\n\t\t\tprofile.updatedAt = now;\n\t\t\tvalidateOrchestrationProfile(profile);\n\n\t\t\tconst activeProfile = this.options.getActiveOrchestrationProfile();\n\t\t\tthis.options.store.append({\n\t\t\t\tbaseProfileId,\n\t\t\t\t...(activeProfile ? { authorProfileId: activeProfile.profileId } : {}),\n\t\t\t\tprofile,\n\t\t\t});\n\t\t\tconst changedFields = [\"description\"];\n\t\t\tif (input.model && !sameModelPolicy(modelPolicy, base.modelPolicy)) changedFields.push(\"model\");\n\t\t\tif (!sameStrings(toolNames, base.toolNames)) changedFields.push(\"tools\");\n\t\t\tif (!sameStrings(resourceProfileNames, base.resourceProfileNames)) changedFields.push(\"resources\");\n\t\t\tif (!sameBudget(budget, base.budget)) changedFields.push(\"budget\");\n\t\t\treturn { created: true, profileId: profile.profileId, baseProfileId, changedFields };\n\t\t} catch (error) {\n\t\t\treturn { created: false, reason: error instanceof Error ? error.message : String(error) };\n\t\t}\n\t}\n\n\tprivate authorizedBaseProfiles(): OrchestrationProfile[] {\n\t\tconst active = this.options.getActiveOrchestrationProfile();\n\t\tif (active && active.role !== \"orchestrator\") return [];\n\t\tconst allowed = active ? new Set(active.dispatchProfileIds) : undefined;\n\t\treturn [...this.loadOwnerProfiles().values()].filter(\n\t\t\t(profile) => profile.role !== \"orchestrator\" && (!allowed || allowed.has(profile.profileId)),\n\t\t);\n\t}\n\n\tprivate loadOwnerProfiles(): ReadonlyMap<string, OrchestrationProfile> {\n\t\tconst profiles = new OrchestrationProfileStore({\n\t\t\tagentDir: this.options.agentDir,\n\t\t\tcwd: this.options.cwd,\n\t\t\tprojectTrusted: this.options.getSettingsManager().isProjectTrusted(),\n\t\t}).load().profiles;\n\t\treturn new Map(profiles.map((profile) => [profile.profileId, profile]));\n\t}\n}\n"]}
|
|
@@ -53,6 +53,7 @@ import type { MemoryControllerReloadSnapshot } from "./memory-controller.ts";
|
|
|
53
53
|
import type { LaneWorkerRefusal } from "./model-capability.ts";
|
|
54
54
|
import type { ModelRegistry } from "./model-registry.ts";
|
|
55
55
|
import type { OrchestrationProfile } from "./orchestration/contracts.ts";
|
|
56
|
+
import type { TaskProfileWriterPort } from "./orchestration/task-profile-writer.ts";
|
|
56
57
|
import type { ProfileFilterReloadSnapshot } from "./profile-filter-controller.ts";
|
|
57
58
|
import type { ModelFitnessReport } from "./research/model-fitness.ts";
|
|
58
59
|
import type { ResourceLoader } from "./resource-loader.ts";
|
|
@@ -184,7 +185,7 @@ export interface RuntimeBuilderDeps {
|
|
|
184
185
|
started: true;
|
|
185
186
|
record: LaneRecord;
|
|
186
187
|
};
|
|
187
|
-
workerAgentControl?: WorkerAgentControlPort
|
|
188
|
+
workerAgentControl?: WorkerAgentControlPort & Partial<TaskProfileWriterPort>;
|
|
188
189
|
getOrchestrationProfileCatalog(): Array<{
|
|
189
190
|
profileId: string;
|
|
190
191
|
role: string;
|
|
@@ -265,6 +266,7 @@ export declare class RuntimeBuilder {
|
|
|
265
266
|
private _reloadPromise;
|
|
266
267
|
private _reloadRequested;
|
|
267
268
|
private readonly _secretVault;
|
|
269
|
+
private readonly _fileMutationIntents;
|
|
268
270
|
private readonly deps;
|
|
269
271
|
constructor(deps: RuntimeBuilderDeps);
|
|
270
272
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime-builder.d.ts","sourceRoot":"","sources":["../../src/core/runtime-builder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAIH,OAAO,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,SAAS,EAAiB,MAAM,2BAA2B,CAAC;AAC7G,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,KAAK,EACX,yBAAyB,EACzB,wBAAwB,EACxB,0BAA0B,EAC1B,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AACpE,OAAO,KAAK,EAAE,2BAA2B,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AAC/G,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAGvD,OAAO,KAAK,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AAO,CAAC,IAAI,CAAC,CA+C/C;CACD;AAED,wBAAsB,iBAAiB,CACtC,aAAa,EAAE,aAAa,EAC5B,YAAY,EAAE,MAAM,EACpB,QAAQ,EAAE,MAAM,EAChB,gBAAgB,GAAE,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,KAAK,OAAqB;;;;;;;;;;GA6B9D"}
|
|
@@ -57,12 +57,14 @@ import { createAskQuestionToolDefinition } from "./tools/ask-question.js";
|
|
|
57
57
|
import { createContextScoutToolDefinition } from "./tools/context-scout.js";
|
|
58
58
|
import { createDelegateToolDefinition } from "./tools/delegate.js";
|
|
59
59
|
import { createDelegateStatusToolDefinition } from "./tools/delegate-status.js";
|
|
60
|
+
import { FileMutationIntentController } from "./tools/file-mutation-intent.js";
|
|
60
61
|
import { createFindTool } from "./tools/find.js";
|
|
61
62
|
import { createGoalToolDefinition } from "./tools/goal.js";
|
|
62
63
|
import { createGrepTool } from "./tools/grep.js";
|
|
63
64
|
import { allToolNames, createToolDefinition } from "./tools/index.js";
|
|
64
65
|
import { createModelFitnessToolDefinition } from "./tools/model-fitness.js";
|
|
65
66
|
import { resolveToCwd } from "./tools/path-utils.js";
|
|
67
|
+
import { createProfileWriterToolDefinition } from "./tools/profile-writer.js";
|
|
66
68
|
import { createReadTool } from "./tools/read.js";
|
|
67
69
|
import { createRunProcessToolDefinition } from "./tools/run-process.js";
|
|
68
70
|
import { createRunToolkitScriptToolDefinition } from "./tools/run-toolkit-script.js";
|
|
@@ -135,6 +137,7 @@ export class RuntimeBuilder {
|
|
|
135
137
|
disposeShellExecutionSession(sessionKey);
|
|
136
138
|
},
|
|
137
139
|
});
|
|
140
|
+
this._fileMutationIntents = new FileMutationIntentController();
|
|
138
141
|
}
|
|
139
142
|
/**
|
|
140
143
|
* Resolve the construction and activation policy once for a runtime generation. This is the
|
|
@@ -476,6 +479,8 @@ export class RuntimeBuilder {
|
|
|
476
479
|
}),
|
|
477
480
|
},
|
|
478
481
|
python: { environment: (cwd) => this._secretVault.getEnvironmentForCwd(cwd) },
|
|
482
|
+
write: { intentController: this._fileMutationIntents },
|
|
483
|
+
edit: { intentController: this._fileMutationIntents },
|
|
479
484
|
grep: { artifactStore: toolArtifactStore },
|
|
480
485
|
find: { artifactStore: toolArtifactStore },
|
|
481
486
|
artifact_retrieve: { artifactStore: toolArtifactStore },
|
|
@@ -615,6 +620,15 @@ export class RuntimeBuilder {
|
|
|
615
620
|
});
|
|
616
621
|
this._baseToolDefinitions.set(delegateStatusToolDefinition.name, delegateStatusToolDefinition);
|
|
617
622
|
}
|
|
623
|
+
if (toolAccess.allows("profile_writer") &&
|
|
624
|
+
this.deps.workerAgentControl?.inspectTaskProfileOptions &&
|
|
625
|
+
this.deps.workerAgentControl.createTaskProfile) {
|
|
626
|
+
const writer = this.deps.workerAgentControl;
|
|
627
|
+
this._baseToolDefinitions.set("profile_writer", createProfileWriterToolDefinition({
|
|
628
|
+
inspectTaskProfileOptions: () => writer.inspectTaskProfileOptions(),
|
|
629
|
+
createTaskProfile: (input) => writer.createTaskProfile(input),
|
|
630
|
+
}));
|
|
631
|
+
}
|
|
618
632
|
// Registered but not default-active: probes spend tokens on the probed model, so
|
|
619
633
|
// activation is an explicit choice (settings/profile/setActiveTools or /autonomy fitness).
|
|
620
634
|
if (toolAccess.allows("model_fitness")) {
|