opencode-work-context 0.11.2 → 0.12.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.
@@ -1,4 +1,5 @@
1
1
  import { Buffer } from "node:buffer";
2
+ import { createHash, randomUUID } from "node:crypto";
2
3
  import { ERROR_CODES, fail } from "./errors.js";
3
4
 
4
5
  export const EXECUTION_SECTIONS = Object.freeze([
@@ -17,27 +18,47 @@ export const EXECUTION_LIMITS = Object.freeze({
17
18
  bytes: 32768,
18
19
  });
19
20
 
21
+ const ITEM_ID = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|legacy-[0-9a-f]{24})$/;
20
22
  const exactKeys = (value, allowed) => Object.keys(value).every((key) => allowed.includes(key));
21
23
  const validTimestamp = (value) => typeof value === "string" && !Number.isNaN(Date.parse(value)) && new Date(value).toISOString() === value;
24
+ const legacyItemId = (section, index, text) => `legacy-${createHash("sha256").update(`${section}\u0000${index}\u0000${text}`).digest("hex").slice(0, 24)}`;
25
+
26
+ const normalizeText = (text, section, code = ERROR_CODES.INVALID_ARGUMENT) => {
27
+ if (typeof text !== "string" || !text.trim()) fail(code, `${section} must contain non-empty item text`);
28
+ const value = text.trim();
29
+ if (value.length > EXECUTION_LIMITS.itemLength) fail(code === ERROR_CODES.STORAGE_ERROR ? code : ERROR_CODES.EXECUTION_LIMIT_EXCEEDED, `Execution items cannot exceed ${EXECUTION_LIMITS.itemLength} characters`);
30
+ return value;
31
+ };
22
32
 
23
33
  const normalizeItems = (items, section) => {
24
34
  if (!Array.isArray(items)) fail(ERROR_CODES.INVALID_ARGUMENT, `${section} must be an array of strings`);
25
35
  if (items.length > EXECUTION_LIMITS.itemsPerSection) fail(ERROR_CODES.EXECUTION_LIMIT_EXCEEDED, `${section} cannot contain more than ${EXECUTION_LIMITS.itemsPerSection} items`);
26
36
  const normalized = [];
27
37
  for (const item of items) {
28
- if (typeof item !== "string" || !item.trim()) fail(ERROR_CODES.INVALID_ARGUMENT, `${section} must contain non-empty strings`);
29
- const value = item.trim();
30
- if (value.length > EXECUTION_LIMITS.itemLength) fail(ERROR_CODES.EXECUTION_LIMIT_EXCEEDED, `Execution items cannot exceed ${EXECUTION_LIMITS.itemLength} characters`);
38
+ if (typeof item !== "string") fail(ERROR_CODES.INVALID_ARGUMENT, `${section} must contain strings`);
39
+ const value = normalizeText(item, section);
31
40
  if (!normalized.includes(value)) normalized.push(value);
32
41
  }
33
42
  return normalized;
34
43
  };
35
44
 
45
+ const assertItemCounts = (items, code = ERROR_CODES.EXECUTION_LIMIT_EXCEEDED) => {
46
+ for (const section of EXECUTION_SECTIONS) {
47
+ if (items[section].length > EXECUTION_LIMITS.itemsPerSection) fail(code, `${section} cannot contain more than ${EXECUTION_LIMITS.itemsPerSection} items`);
48
+ }
49
+ const total = EXECUTION_SECTIONS.reduce((count, section) => count + items[section].length, 0);
50
+ if (total > EXECUTION_LIMITS.totalItems) fail(code, `Execution state cannot contain more than ${EXECUTION_LIMITS.totalItems} items`);
51
+ };
52
+
53
+ const assertUniqueIds = (items, code = ERROR_CODES.INVALID_ARGUMENT) => {
54
+ const ids = EXECUTION_SECTIONS.flatMap((section) => items[section].map((item) => item.id));
55
+ if (new Set(ids).size !== ids.length) fail(code, "Execution item IDs must be unique");
56
+ };
57
+
36
58
  export function normalizeExecutionState(input) {
37
59
  if (!input || typeof input !== "object" || Array.isArray(input) || !exactKeys(input, EXECUTION_SECTIONS)) fail(ERROR_CODES.INVALID_ARGUMENT, "Execution state contains unsupported fields");
38
60
  const state = Object.fromEntries(EXECUTION_SECTIONS.map((section) => [section, normalizeItems(input[section] ?? [], section)]));
39
- const total = EXECUTION_SECTIONS.reduce((count, section) => count + state[section].length, 0);
40
- if (total > EXECUTION_LIMITS.totalItems) fail(ERROR_CODES.EXECUTION_LIMIT_EXCEEDED, `Execution state cannot contain more than ${EXECUTION_LIMITS.totalItems} items`);
61
+ assertItemCounts(Object.fromEntries(EXECUTION_SECTIONS.map((section) => [section, state[section].map((text) => ({ text }))])));
41
62
  const remaining = new Set(state.remaining);
42
63
  const overlap = state.completed.find((item) => remaining.has(item));
43
64
  if (overlap) fail(ERROR_CODES.INVALID_ARGUMENT, "An item cannot be both completed and remaining", { item: overlap });
@@ -61,28 +82,214 @@ export function applyExecutionPatch(current, patch) {
61
82
  return normalizeExecutionState(next);
62
83
  }
63
84
 
85
+ const validateId = (id, code = ERROR_CODES.INVALID_ARGUMENT) => {
86
+ if (typeof id !== "string" || !ITEM_ID.test(id)) fail(code, "Execution item ID is invalid");
87
+ return id;
88
+ };
89
+
90
+ const normalizeStoredItems = (items) => {
91
+ if (!items || typeof items !== "object" || Array.isArray(items) || !exactKeys(items, EXECUTION_SECTIONS)) fail(ERROR_CODES.STORAGE_ERROR, "Invalid stage execution state");
92
+ const normalized = {};
93
+ for (const section of EXECUTION_SECTIONS) {
94
+ if (!Array.isArray(items[section])) fail(ERROR_CODES.STORAGE_ERROR, "Invalid stage execution state");
95
+ normalized[section] = items[section].map((item) => {
96
+ if (!item || typeof item !== "object" || Array.isArray(item) || !exactKeys(item, ["id", "text"])) fail(ERROR_CODES.STORAGE_ERROR, "Invalid stage execution state");
97
+ const text = normalizeText(item.text, section, ERROR_CODES.STORAGE_ERROR);
98
+ if (text !== item.text) fail(ERROR_CODES.STORAGE_ERROR, "Stage execution state is not normalized");
99
+ return { id: validateId(item.id, ERROR_CODES.STORAGE_ERROR), text };
100
+ });
101
+ }
102
+ assertItemCounts(normalized, ERROR_CODES.STORAGE_ERROR);
103
+ assertUniqueIds(normalized, ERROR_CODES.STORAGE_ERROR);
104
+ return normalized;
105
+ };
106
+
107
+ export function executionItems(record) {
108
+ if (record.schema === 2) return Object.fromEntries(EXECUTION_SECTIONS.map((section) => [section, record.items[section].map((item) => ({ ...item }))]));
109
+ return Object.fromEntries(EXECUTION_SECTIONS.map((section) => [section, record[section].map((text, index) => ({ id: legacyItemId(section, index, text), text }))]));
110
+ }
111
+
112
+ export function executionReadModel(record) {
113
+ const items = executionItems(record);
114
+ return {
115
+ schema: record.schema,
116
+ workspace: record.workspace,
117
+ stage: record.stage,
118
+ revision: record.revision,
119
+ created_at: record.created_at,
120
+ updated_at: record.updated_at,
121
+ updated_by: record.updated_by,
122
+ ...Object.fromEntries(EXECUTION_SECTIONS.map((section) => [section, items[section].map((item) => item.text)])),
123
+ items,
124
+ current: items.remaining[0] || null,
125
+ queued: items.remaining.slice(1),
126
+ };
127
+ }
128
+
129
+ export function executionState(record) {
130
+ return Object.fromEntries(EXECUTION_SECTIONS.map((section) => [section, executionItems(record)[section].map((item) => item.text)]));
131
+ }
132
+
133
+ export function executionItemsFromState(state, previous = null) {
134
+ const previousItems = previous ? executionItems(previous) : Object.fromEntries(EXECUTION_SECTIONS.map((section) => [section, []]));
135
+ const used = new Set();
136
+ const take = (section, text) => previousItems[section].find((item) => item.text === text && !used.has(item.id))
137
+ || EXECUTION_SECTIONS.flatMap((name) => previousItems[name]).find((item) => item.text === text && !used.has(item.id));
138
+ const items = Object.fromEntries(EXECUTION_SECTIONS.map((section) => [section, state[section].map((text) => {
139
+ const previousItem = take(section, text);
140
+ if (previousItem) used.add(previousItem.id);
141
+ return previousItem || { id: randomUUID(), text };
142
+ })]));
143
+ assertUniqueIds(items);
144
+ return items;
145
+ }
146
+
147
+ export function executionInputUsesItems(input) {
148
+ return EXECUTION_SECTIONS.some((section) => Array.isArray(input?.[section]) && input[section].some((item) => typeof item !== "string"));
149
+ }
150
+
151
+ export function executionPatchUsesItems(patch) {
152
+ return Boolean(patch?.edit) || [patch?.add, patch?.remove].some((changes) => EXECUTION_SECTIONS.some((section) => Array.isArray(changes?.[section]) && changes[section].some((item) => typeof item !== "string")));
153
+ }
154
+
155
+ export function applyExecutionTextPatchItems(current, patch) {
156
+ if (!patch || typeof patch !== "object" || Array.isArray(patch) || !exactKeys(patch, ["add", "remove"]) || (!patch.add && !patch.remove)) fail(ERROR_CODES.INVALID_ARGUMENT, "Execution update requires add or remove changes");
157
+ const validateChanges = (changes, operation) => {
158
+ if (changes === undefined) return {};
159
+ if (!changes || typeof changes !== "object" || Array.isArray(changes) || !exactKeys(changes, EXECUTION_SECTIONS)) fail(ERROR_CODES.INVALID_ARGUMENT, `Execution ${operation} changes contain unsupported fields`);
160
+ return Object.fromEntries(Object.entries(changes).map(([section, values]) => [section, normalizeItems(values, section)]));
161
+ };
162
+ const add = validateChanges(patch.add, "add");
163
+ const remove = validateChanges(patch.remove, "remove");
164
+ const items = executionItems(current);
165
+ const previousOverlap = new Set(items.completed.map((item) => item.text).filter((text) => items.remaining.some((item) => item.text === text)));
166
+ const removedByText = new Map();
167
+ for (const section of EXECUTION_SECTIONS) {
168
+ for (const text of remove[section] || []) {
169
+ const matches = items[section].filter((item) => item.text === text);
170
+ if (matches.length > 1) fail(ERROR_CODES.INVALID_ARGUMENT, "Text-only execution removal is ambiguous; use an item ID", { text, matches: matches.length });
171
+ if (matches[0]) removedByText.set(text, [...(removedByText.get(text) || []), matches[0]]);
172
+ items[section] = items[section].filter((item) => item.text !== text);
173
+ }
174
+ }
175
+ for (const section of EXECUTION_SECTIONS) {
176
+ for (const text of add[section] || []) {
177
+ if (items[section].some((item) => item.text === text)) continue;
178
+ const removed = removedByText.get(text) || [];
179
+ if (removed.length > 1) fail(ERROR_CODES.INVALID_ARGUMENT, "Text-only execution movement is ambiguous; use item IDs", { text, matches: removed.length });
180
+ items[section].push(removed.shift() || { id: randomUUID(), text });
181
+ }
182
+ }
183
+ const overlap = items.completed.map((item) => item.text).find((text) => items.remaining.some((item) => item.text === text) && !previousOverlap.has(text));
184
+ if (overlap) fail(ERROR_CODES.INVALID_ARGUMENT, "An item cannot be both completed and remaining", { item: overlap });
185
+ assertItemCounts(items);
186
+ assertUniqueIds(items);
187
+ return items;
188
+ }
189
+
190
+ export function normalizeExecutionItemState(input, previous = null) {
191
+ if (!input || typeof input !== "object" || Array.isArray(input) || !exactKeys(input, EXECUTION_SECTIONS)) fail(ERROR_CODES.INVALID_ARGUMENT, "Execution state contains unsupported fields");
192
+ const previousItems = previous ? executionItems(previous) : Object.fromEntries(EXECUTION_SECTIONS.map((section) => [section, []]));
193
+ const used = new Set();
194
+ const items = {};
195
+ for (const section of EXECUTION_SECTIONS) {
196
+ const sectionItems = input[section] ?? [];
197
+ if (!Array.isArray(sectionItems)) fail(ERROR_CODES.INVALID_ARGUMENT, `${section} must be an array`);
198
+ items[section] = sectionItems.map((item) => {
199
+ if (typeof item === "string") {
200
+ const text = normalizeText(item, section);
201
+ const previousItem = previousItems[section].find((candidate) => candidate.text === text && !used.has(candidate.id));
202
+ if (previousItem) used.add(previousItem.id);
203
+ return previousItem || { id: randomUUID(), text };
204
+ }
205
+ if (!item || typeof item !== "object" || Array.isArray(item) || !exactKeys(item, ["id", "text"]) || item.text === undefined) fail(ERROR_CODES.INVALID_ARGUMENT, `${section} contains an invalid execution item`);
206
+ const id = item.id === undefined ? randomUUID() : validateId(item.id);
207
+ used.add(id);
208
+ return { id, text: normalizeText(item.text, section) };
209
+ });
210
+ }
211
+ assertItemCounts(items);
212
+ assertUniqueIds(items);
213
+ return items;
214
+ }
215
+
216
+ const normalizeItemChanges = (changes, operation) => {
217
+ if (changes === undefined) return {};
218
+ if (!changes || typeof changes !== "object" || Array.isArray(changes) || !exactKeys(changes, EXECUTION_SECTIONS)) fail(ERROR_CODES.INVALID_ARGUMENT, `Execution ${operation} changes contain unsupported fields`);
219
+ const result = {};
220
+ for (const [section, sectionItems] of Object.entries(changes)) {
221
+ if (!Array.isArray(sectionItems)) fail(ERROR_CODES.INVALID_ARGUMENT, `Execution ${operation} ${section} changes must be an array`);
222
+ result[section] = sectionItems.map((item) => {
223
+ if (typeof item === "string") {
224
+ if (operation === "edit") fail(ERROR_CODES.INVALID_ARGUMENT, "Structured execution edits require item IDs and text");
225
+ const text = normalizeText(item, section);
226
+ return operation === "add" ? { id: randomUUID(), text } : { text };
227
+ }
228
+ if (operation === "remove") {
229
+ if (!item || typeof item !== "object" || Array.isArray(item) || !exactKeys(item, ["id"])) fail(ERROR_CODES.INVALID_ARGUMENT, "Structured execution removals require an item ID");
230
+ return { id: validateId(item.id) };
231
+ }
232
+ if (!item || typeof item !== "object" || Array.isArray(item) || !exactKeys(item, ["id", "text"]) || item.text === undefined) fail(ERROR_CODES.INVALID_ARGUMENT, `Structured execution ${operation} changes require item IDs and text`);
233
+ return { id: operation === "add" && item.id === undefined ? randomUUID() : validateId(item.id), text: normalizeText(item.text, section) };
234
+ });
235
+ }
236
+ return result;
237
+ };
238
+
239
+ export function applyExecutionItemPatch(current, patch) {
240
+ if (!patch || typeof patch !== "object" || Array.isArray(patch) || !exactKeys(patch, ["add", "remove", "edit"]) || (!patch.add && !patch.remove && !patch.edit)) fail(ERROR_CODES.INVALID_ARGUMENT, "Execution update requires add, remove, or edit changes");
241
+ const add = normalizeItemChanges(patch.add, "add");
242
+ const remove = normalizeItemChanges(patch.remove, "remove");
243
+ const edit = normalizeItemChanges(patch.edit, "edit");
244
+ const items = executionItems(current);
245
+ for (const section of EXECUTION_SECTIONS) {
246
+ const known = new Set(items[section].map((item) => item.id));
247
+ const removed = new Set((remove[section] || []).map((item) => {
248
+ if (item.id) return item.id;
249
+ const matches = items[section].filter((candidate) => candidate.text === item.text);
250
+ if (matches.length !== 1) fail(ERROR_CODES.INVALID_ARGUMENT, "Text-only execution removal is ambiguous; use an item ID", { text: item.text, matches: matches.length });
251
+ return matches[0].id;
252
+ }));
253
+ const edits = new Map((edit[section] || []).map((item) => [item.id, item.text]));
254
+ for (const id of [...removed, ...edits.keys()]) if (!known.has(id)) fail(ERROR_CODES.INVALID_ARGUMENT, "Execution item ID was not found", { id });
255
+ items[section] = items[section]
256
+ .filter((item) => !removed.has(item.id))
257
+ .map((item) => edits.has(item.id) ? { id: item.id, text: edits.get(item.id) } : item);
258
+ items[section].push(...(add[section] || []));
259
+ }
260
+ assertItemCounts(items);
261
+ assertUniqueIds(items);
262
+ return items;
263
+ }
264
+
64
265
  export function validateExecutionRecord(record, workspace, stage) {
65
- const allowed = ["schema", "workspace", "stage", "revision", "created_at", "updated_at", "updated_by", ...EXECUTION_SECTIONS];
66
- if (!record || typeof record !== "object" || Array.isArray(record) || !exactKeys(record, allowed)
67
- || record.schema !== 1 || record.workspace !== workspace || record.stage !== stage
266
+ const legacyAllowed = ["schema", "workspace", "stage", "revision", "created_at", "updated_at", "updated_by", ...EXECUTION_SECTIONS];
267
+ const currentAllowed = ["schema", "workspace", "stage", "revision", "created_at", "updated_at", "updated_by", "items"];
268
+ if (!record || typeof record !== "object" || Array.isArray(record)
269
+ || ![1, 2].includes(record.schema) || record.workspace !== workspace || record.stage !== stage
68
270
  || !Number.isInteger(record.revision) || record.revision < 1
69
271
  || !validTimestamp(record.created_at) || !validTimestamp(record.updated_at)
70
272
  || Date.parse(record.updated_at) < Date.parse(record.created_at)
71
273
  || typeof record.updated_by !== "string" || !record.updated_by.trim()) {
72
274
  fail(ERROR_CODES.STORAGE_ERROR, "Invalid stage execution state");
73
275
  }
74
- let state;
75
- try { state = normalizeExecutionState(Object.fromEntries(EXECUTION_SECTIONS.map((section) => [section, record[section]]))); }
76
- catch (error) { fail(ERROR_CODES.STORAGE_ERROR, "Invalid stage execution state", { cause: error.message }); }
77
- if (EXECUTION_SECTIONS.some((section) => JSON.stringify(state[section]) !== JSON.stringify(record[section]))) fail(ERROR_CODES.STORAGE_ERROR, "Stage execution state is not normalized");
276
+ try {
277
+ if (record.schema === 1) {
278
+ if (!exactKeys(record, legacyAllowed)) fail(ERROR_CODES.STORAGE_ERROR, "Invalid stage execution state");
279
+ const state = normalizeExecutionState(Object.fromEntries(EXECUTION_SECTIONS.map((section) => [section, record[section]])));
280
+ if (EXECUTION_SECTIONS.some((section) => JSON.stringify(state[section]) !== JSON.stringify(record[section]))) fail(ERROR_CODES.STORAGE_ERROR, "Stage execution state is not normalized");
281
+ } else {
282
+ if (!exactKeys(record, currentAllowed)) fail(ERROR_CODES.STORAGE_ERROR, "Invalid stage execution state");
283
+ normalizeStoredItems(record.items);
284
+ }
285
+ } catch (error) {
286
+ if (error.code === ERROR_CODES.STORAGE_ERROR) throw error;
287
+ fail(ERROR_CODES.STORAGE_ERROR, "Invalid stage execution state", { cause: error.message });
288
+ }
78
289
  if (Buffer.byteLength(JSON.stringify(record), "utf8") > EXECUTION_LIMITS.bytes) fail(ERROR_CODES.STORAGE_ERROR, "Stage execution state exceeds its storage limit");
79
290
  return record;
80
291
  }
81
292
 
82
- export function executionState(record) {
83
- return Object.fromEntries(EXECUTION_SECTIONS.map((section) => [section, record[section]]));
84
- }
85
-
86
293
  export function assertExecutionSize(record) {
87
294
  if (Buffer.byteLength(JSON.stringify(record), "utf8") > EXECUTION_LIMITS.bytes) fail(ERROR_CODES.EXECUTION_LIMIT_EXCEEDED, `Execution state cannot exceed ${EXECUTION_LIMITS.bytes} bytes`);
88
295
  }
@@ -46,14 +46,12 @@ const deliveryFinding = tool.schema.object({
46
46
  remediation_ids: tool.schema.array(tool.schema.string()).optional(),
47
47
  recommendation: tool.schema.string().optional(),
48
48
  }).strict();
49
- const executionSections = {
50
- scope: tool.schema.array(tool.schema.string()).optional(),
51
- completed: tool.schema.array(tool.schema.string()).optional(),
52
- remaining: tool.schema.array(tool.schema.string()).optional(),
53
- decisions: tool.schema.array(tool.schema.string()).optional(),
54
- blockers: tool.schema.array(tool.schema.string()).optional(),
55
- verification: tool.schema.array(tool.schema.string()).optional(),
56
- };
49
+ const executionItem = tool.schema.union([tool.schema.string(), tool.schema.object({ id: tool.schema.string().optional(), text: tool.schema.string() }).strict()]);
50
+ const executionRemoval = tool.schema.union([tool.schema.string(), tool.schema.object({ id: tool.schema.string() }).strict()]);
51
+ const executionEdit = tool.schema.object({ id: tool.schema.string(), text: tool.schema.string() }).strict();
52
+ const executionSections = Object.fromEntries(["scope", "completed", "remaining", "decisions", "blockers", "verification"].map((section) => [section, tool.schema.array(executionItem).optional()]));
53
+ const executionRemovalSections = Object.fromEntries(["scope", "completed", "remaining", "decisions", "blockers", "verification"].map((section) => [section, tool.schema.array(executionRemoval).optional()]));
54
+ const executionEditSections = Object.fromEntries(["scope", "completed", "remaining", "decisions", "blockers", "verification"].map((section) => [section, tool.schema.array(executionEdit).optional()]));
57
55
  const sessionFromContext = (ctx, workspace) => ctx.sessionByOpenCodeId(ctx.options.sessionId, workspace || null, null, null)
58
56
  || (!workspace ? ctx.sessionById(ctx.options.sessionId) : null);
59
57
  const workspaceFromSession = (ctx, workspace) => {
@@ -99,6 +97,8 @@ export const work_context_show_candidate = tool({ description: "Show local candi
99
97
  export const work_context_list_candidates = tool({ description: "List local commit candidates associated with a startup-mode workspace.", args: { workspace: tool.schema.string() }, execute: run((ctx, a) => ctx.listCandidates(a.workspace)) });
100
98
  export const work_context_ready_candidate = tool({ description: "Mark a captured draft candidate ready for a later explicit commit operation.", args: { workspace: tool.schema.string(), candidateId: tool.schema.string() }, execute: run((ctx, a) => ctx.readyCandidate(a.workspace, a.candidateId)) });
101
99
  export const work_context_commit_candidate = tool({ description: "Commit a ready candidate atomically without using the ordinary Git index. Uses its stored message unless message is provided.", args: { workspace: tool.schema.string(), candidateId: tool.schema.string(), message: tool.schema.string().optional() }, execute: run((ctx, a) => ctx.commitCandidate(a.workspace, a.candidateId, a.message)) });
100
+ export const work_context_inspect_commit_all = tool({ description: "Inspect a repository-local integration boundary and return a confirmation fingerprint without changing Git or candidate state.", args: { workspace: tool.schema.string(), relatedStages: tool.schema.array(tool.schema.string()).optional(), excludePaths: tool.schema.array(tool.schema.string()).optional(), message: tool.schema.string().optional() }, execute: run((ctx, a) => ctx.inspectCommitAll(a.workspace, { relatedStages: a.relatedStages, excludePaths: a.excludePaths, message: a.message })) });
101
+ export const work_context_commit_all = tool({ description: "Reproduce and atomically publish a previously inspected repository-local integration plan after exact explicit confirmation.", args: { workspace: tool.schema.string(), expectedFingerprint: tool.schema.string(), confirmation: tool.schema.string(), relatedStages: tool.schema.array(tool.schema.string()).optional(), excludePaths: tool.schema.array(tool.schema.string()).optional(), message: tool.schema.string().optional() }, execute: run((ctx, a) => ctx.commitAll(a.workspace, a.expectedFingerprint, a.confirmation, { relatedStages: a.relatedStages, excludePaths: a.excludePaths, message: a.message })) });
102
102
  export const work_context_discard_candidate = tool({ description: "Discard a local commit candidate without changing Git state.", args: { workspace: tool.schema.string(), candidateId: tool.schema.string() }, execute: run((ctx, a) => ctx.discardCandidate(a.workspace, a.candidateId)) });
103
103
  export const work_context_read_delivery = tool({ description: "Read workspace-level delivery context. Exact Git inspection runs only when both immutable from and to commit hashes are provided.", args: { workspace: tool.schema.string(), environment: tool.schema.string().optional(), from: tool.schema.string().optional(), to: tool.schema.string().optional() }, execute: run((ctx, a) => ctx.readDelivery(a.workspace, { environment: a.environment, from: a.from, to: a.to })) });
104
104
  export const work_context_explain_delivery = tool({ description: "Explain a bounded immutable delivery range with read-only Git evidence, findings, and traceability.", args: { workspace: tool.schema.string(), from: tool.schema.string(), to: tool.schema.string(), findings: tool.schema.array(deliveryFinding).optional() }, execute: run((ctx, a) => ctx.explainDelivery(a.workspace, a.from, a.to, a.findings) ) });
@@ -127,15 +127,16 @@ export const work_context_add_stage = tool({ description: "Add a stage with an o
127
127
  export const work_context_set_stage_profiles = tool({ description: "Explicitly set or clear a stage execution capability and depth. Omitted fields are unchanged; pass null for both execution fields to clear them. Review profile remains optional metadata.", args: { ...contextualStage, executionProfile: capabilityProfile.nullable().optional(), executionDepth: capabilityDepth.nullable().optional(), reviewProfile: capabilityProfile.nullable().optional() }, execute: run((ctx, a) => { const workspace = workspaceFromSession(ctx, a.workspace); return ctx.setStageProfiles(workspace, stageFromSession(ctx, workspace, a.stage), { ...(Object.hasOwn(a, "executionProfile") ? { executionProfile: a.executionProfile } : {}), ...(Object.hasOwn(a, "executionDepth") ? { executionDepth: a.executionDepth } : {}), ...(Object.hasOwn(a, "reviewProfile") ? { reviewProfile: a.reviewProfile } : {}) }); }) });
128
128
  export const work_context_refresh_stage_profiles = tool({ description: "Atomically apply agent-inferred execution capability and depth recommendations. Ordinary refresh preserves explicit classifications; includeExplicit permits an explicitly requested override.", args: { workspace: tool.schema.string(), recommendations: tool.schema.array(tool.schema.object({ stage: tool.schema.string(), executionProfile: capabilityProfile, executionDepth: capabilityDepth })), includeExplicit: tool.schema.boolean().optional() }, execute: run((ctx, a) => ctx.refreshStageProfiles(a.workspace, a.recommendations, { includeExplicit: a.includeExplicit })) });
129
129
  export const work_context_show_capability_profiles = tool({ description: "Show capability recommendation mode and validated user-local depth mappings.", args: {}, execute: run((ctx) => ctx.showCapabilityProfiles()) });
130
- export const work_context_configure_capability_profiles = tool({ description: "Atomically configure either capability recommendation mode or user-local light, standard, and deep model labels. Interactive setup calls it separately for mode and mappings after gathering preferences.", args: { mode: tool.schema.enum(["advisory", "off"]).optional(), mappings: tool.schema.object({ light: tool.schema.string().optional(), standard: tool.schema.string().optional(), deep: tool.schema.string().optional() }).strict().optional() }, execute: run((ctx, a) => ctx.configureCapabilityProfiles(a)) });
131
- export const work_context_reset_capability_profiles = tool({ description: "Remove all user-local model mappings after explicit RESET_PROFILES confirmation. Stage classifications and project mode remain unchanged.", args: { confirmation: tool.schema.string() }, execute: run((ctx, a) => ctx.resetCapabilityProfiles(a.confirmation)) });
130
+ export const work_context_configure_capability_profiles = tool({ description: "Atomically configure either capability recommendation mode or global/project light, standard, and deep advisory labels. Interactive setup calls it separately for mode and mappings after gathering preferences.", args: { mode: tool.schema.enum(["advisory", "off"]).optional(), mappings: tool.schema.object({ light: tool.schema.string().optional(), standard: tool.schema.string().optional(), deep: tool.schema.string().optional() }).strict().optional(), scope: tool.schema.enum(["global", "project"]).optional() }, execute: run((ctx, a) => ctx.configureCapabilityProfiles(a)) });
131
+ export const work_context_reset_capability_profiles = tool({ description: "Remove global or project advisory mappings after explicit RESET_PROFILES confirmation. Stage classifications and project mode remain unchanged.", args: { confirmation: tool.schema.string(), scope: tool.schema.enum(["global", "project"]).optional() }, execute: run((ctx, a) => ctx.resetCapabilityProfiles(a.confirmation, { scope: a.scope })) });
132
132
  export const work_context_rename_stage = tool({ description: "Rename a stage while preserving its ID and history; workspace and stage can be omitted in the current OpenCode session.", args: { ...contextualStage, title: tool.schema.string() }, execute: run((ctx, a) => { const workspace = workspaceFromSession(ctx, a.workspace); return ctx.renameStage(workspace, stageFromSession(ctx, workspace, a.stage), a.title); }) });
133
133
  export const work_context_update_stage = tool({ description: "Update an existing stage description; workspace and stage can be omitted in the current OpenCode session.", args: { ...contextualStage, description: tool.schema.string() }, execute: run((ctx, a) => { const workspace = workspaceFromSession(ctx, a.workspace); return ctx.updateStage(workspace, stageFromSession(ctx, workspace, a.stage), a.description); }) });
134
134
  export const work_context_update_stage_prompt = tool({ description: "Update the optional working prompt of an existing stage; workspace and stage can be omitted in the current OpenCode session.", args: { ...contextualStage, prompt: tool.schema.string() }, execute: run((ctx, a) => { const workspace = workspaceFromSession(ctx, a.workspace); return ctx.updateStagePrompt(workspace, stageFromSession(ctx, workspace, a.stage), a.prompt); }) });
135
135
  export const work_context_update_stage_result = tool({ description: "Update an existing stage result; workspace and stage can be omitted in the current OpenCode session.", args: { ...contextualStage, result: tool.schema.string() }, execute: run((ctx, a) => { const workspace = workspaceFromSession(ctx, a.workspace); return ctx.updateStageResult(workspace, stageFromSession(ctx, workspace, a.stage), a.result); }) });
136
136
  export const work_context_read_stage_execution = tool({ description: "Read the bounded stage-local execution state; workspace and stage can be omitted in the current OpenCode session.", args: contextualStage, execute: run((ctx, a) => { const workspace = workspaceFromSession(ctx, a.workspace); return ctx.readStageExecution(workspace, stageFromSession(ctx, workspace, a.stage)); }) });
137
137
  export const work_context_replace_stage_execution = tool({ description: "Replace all stage-local execution sections using an optimistic revision guard. Requires the active stage session.", args: { ...contextualStage, expectedRevision: tool.schema.number().int().nonnegative(), state: tool.schema.object(executionSections) }, execute: run((ctx, a, oc) => { const workspace = workspaceFromSession(ctx, a.workspace); const stage = stageFromSession(ctx, workspace, a.stage); return ctx.replaceStageExecution(workspace, stage, sessionFor(ctx, oc, workspace, stage), a.expectedRevision, a.state); }) });
138
- export const work_context_update_stage_execution = tool({ description: "Atomically add and remove stage-local execution items using an optimistic revision guard. Requires the active stage session.", args: { ...contextualStage, expectedRevision: tool.schema.number().int().nonnegative(), add: tool.schema.object(executionSections).optional(), remove: tool.schema.object(executionSections).optional() }, execute: run((ctx, a, oc) => { const workspace = workspaceFromSession(ctx, a.workspace); const stage = stageFromSession(ctx, workspace, a.stage); return ctx.updateStageExecution(workspace, stage, sessionFor(ctx, oc, workspace, stage), a.expectedRevision, { add: a.add, remove: a.remove }); }) });
138
+ export const work_context_update_stage_execution = tool({ description: "Atomically add, remove, or edit stage-local execution items using an optimistic revision guard. String changes retain compatibility; structured changes use stable item IDs. Requires the active stage session.", args: { ...contextualStage, expectedRevision: tool.schema.number().int().nonnegative(), add: tool.schema.object(executionSections).optional(), remove: tool.schema.object(executionRemovalSections).optional(), edit: tool.schema.object(executionEditSections).optional() }, execute: run((ctx, a, oc) => { const workspace = workspaceFromSession(ctx, a.workspace); const stage = stageFromSession(ctx, workspace, a.stage); return ctx.updateStageExecution(workspace, stage, sessionFor(ctx, oc, workspace, stage), a.expectedRevision, { ...(a.add ? { add: a.add } : {}), ...(a.remove ? { remove: a.remove } : {}), ...(a.edit ? { edit: a.edit } : {}) }); }) });
139
+ export const work_context_complete_current = tool({ description: "Atomically complete the current stage execution item using an optimistic revision guard. Requires the active stage session.", args: { ...contextualStage, expectedRevision: tool.schema.number().int().nonnegative() }, execute: run((ctx, a, oc) => { const workspace = workspaceFromSession(ctx, a.workspace); const stage = stageFromSession(ctx, workspace, a.stage); return ctx.completeCurrentExecution(workspace, stage, sessionFor(ctx, oc, workspace, stage), a.expectedRevision); }) });
139
140
  export const work_context_archive_stage = tool({ description: "Archive a stage while preserving its ID and history; workspace and stage can be omitted in the current OpenCode session.", args: contextualStage, execute: run((ctx, a) => { const workspace = workspaceFromSession(ctx, a.workspace); return ctx.archiveStage(workspace, stageFromSession(ctx, workspace, a.stage)); }) });
140
141
  export const work_context_reopen_stage = tool({ description: "Reopen a completed stage with a reason. This preserves completion history and requires explicit resume in a separate OpenCode session.", args: { ...common, reason: tool.schema.string() }, execute: run((ctx, a) => ctx.reopenStage(a.workspace, a.stage, a.reason)) });
141
142
  export const work_context_restore_stage = tool({ description: "Restore an archived stage to its saved pre-archive status with a required reason. Actionable stages require explicit resume in a separate OpenCode session.", args: { ...common, reason: tool.schema.string() }, execute: run((ctx, a) => ctx.restoreStage(a.workspace, a.stage, a.reason)) });
@@ -153,7 +154,7 @@ export const work_context_add_knowledge = tool({ description: "Add a durable kno
153
154
  export const work_context_update_knowledge = tool({ description: "Update a durable knowledge entry.", args: { workspace: tool.schema.string(), knowledgeId: tool.schema.string(), title: tool.schema.string().optional(), kind: tool.schema.string().optional(), status: tool.schema.string().optional(), text: tool.schema.string().optional(), sources: tool.schema.array(tool.schema.string()).optional(), replacement: tool.schema.string().optional() }, execute: run((ctx, a) => ctx.updateKnowledge(a.workspace, a.knowledgeId, a)) });
154
155
  export const work_context_supersede_knowledge = tool({ description: "Supersede a durable knowledge entry.", args: { workspace: tool.schema.string(), knowledgeId: tool.schema.string(), replacement: tool.schema.string() }, execute: run((ctx, a) => ctx.supersedeKnowledge(a.workspace, a.knowledgeId, a.replacement) ) });
155
156
 
156
- const defaultTools = { work_context_list_workspaces, work_context_workspace_list, work_context_rename_workspace, work_context_set_workspace_mode, work_context_create_candidate, work_context_capture_candidate, work_context_preview_candidate, work_context_show_candidate, work_context_list_candidates, work_context_ready_candidate, work_context_commit_candidate, work_context_discard_candidate, work_context_read_delivery, work_context_explain_delivery, work_context_doctor_delivery, work_context_mark_delivery, work_context_workspace_finish, work_context_reopen_workspace, work_context_create_workspace, work_context_start_session, work_context_acknowledge_commit, work_context_add_stage, work_context_set_stage_profiles, work_context_refresh_stage_profiles, work_context_show_capability_profiles, work_context_configure_capability_profiles, work_context_reset_capability_profiles, work_context_rename_stage, work_context_update_stage, work_context_update_stage_prompt, work_context_update_stage_result, work_context_read_stage_execution, work_context_replace_stage_execution, work_context_update_stage_execution, work_context_archive_stage, work_context_reopen_stage, work_context_restore_stage, work_context_link_issue, work_context_unlink_issue, work_context_rename_session, work_context_close_session, work_context_force_close_session, work_context_handoff_stage, work_context_abandon_stage, work_context_finish_stage, work_context_help, work_context_list_knowledge, work_context_add_knowledge, work_context_update_knowledge, work_context_supersede_knowledge };
157
+ const defaultTools = { work_context_list_workspaces, work_context_workspace_list, work_context_rename_workspace, work_context_set_workspace_mode, work_context_create_candidate, work_context_capture_candidate, work_context_preview_candidate, work_context_show_candidate, work_context_list_candidates, work_context_ready_candidate, work_context_commit_candidate, work_context_inspect_commit_all, work_context_commit_all, work_context_discard_candidate, work_context_read_delivery, work_context_explain_delivery, work_context_doctor_delivery, work_context_mark_delivery, work_context_workspace_finish, work_context_reopen_workspace, work_context_create_workspace, work_context_start_session, work_context_acknowledge_commit, work_context_add_stage, work_context_set_stage_profiles, work_context_refresh_stage_profiles, work_context_show_capability_profiles, work_context_configure_capability_profiles, work_context_reset_capability_profiles, work_context_rename_stage, work_context_update_stage, work_context_update_stage_prompt, work_context_update_stage_result, work_context_read_stage_execution, work_context_replace_stage_execution, work_context_update_stage_execution, work_context_complete_current, work_context_archive_stage, work_context_reopen_stage, work_context_restore_stage, work_context_link_issue, work_context_unlink_issue, work_context_rename_session, work_context_close_session, work_context_force_close_session, work_context_handoff_stage, work_context_abandon_stage, work_context_finish_stage, work_context_help, work_context_list_knowledge, work_context_add_knowledge, work_context_update_knowledge, work_context_supersede_knowledge };
157
158
 
158
159
  export function createToolDefinitions(options = {}) {
159
160
  return { ...defaultTools, work_context_doctor_delivery: createDoctorDeliveryTool(options) };
@@ -0,0 +1,3 @@
1
+ import { work_context_commit_all } from "../src/tool-definitions.js";
2
+
3
+ export default work_context_commit_all;
@@ -0,0 +1 @@
1
+ export { work_context_complete_current as default } from "../src/tool-definitions.js";
@@ -0,0 +1,3 @@
1
+ import { work_context_inspect_commit_all } from "../src/tool-definitions.js";
2
+
3
+ export default work_context_inspect_commit_all;