opencode-work-context 0.12.0 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -196,17 +196,26 @@ returned revision as an optimistic concurrency guard:
196
196
  /wc stage execution read 000001 02
197
197
  /wc stage execution replace 000001 02 0 "{\"scope\":[\"Add CSV export\"],\"remaining\":[\"Implement endpoint\",\"Add tests\"]}"
198
198
  /wc stage execution update 000001 02 1 "{\"add\":{\"completed\":[\"Implement endpoint\"]},\"remove\":{\"remaining\":[\"Implement endpoint\"]}}"
199
+ /wc stage execution update 000001 02 2 "{\"edit\":{\"remaining\":[{\"id\":\"item-id\",\"details\":\"Handle authorization and return a paginated response.\"}]}}"
199
200
  ```
200
201
 
201
202
  `replace` replaces the complete logical state; any omitted section becomes empty. `update`
202
203
  atomically adds and removes exact normalized items. Mutations require the active
203
204
  stage session. A stale revision fails with `EXECUTION_REVISION_CONFLICT` rather
204
205
  than overwriting newer work. Each section is limited to 50 items, the complete
205
- state to 200 items and 32,768 serialized bytes, and each item to 500 characters.
206
+ state to 200 items and 32,768 serialized bytes, and each item label to 500 characters.
206
207
  The first Remaining item is `Current`; later items are `Queued`. Agents work only
207
208
  on Current by default and do not combine Queued work into the same change set
208
209
  unless the user explicitly requests it. The read model includes stable item IDs,
209
210
  so Current and Queued remain unambiguous even when text is duplicated or revised.
211
+ Structured items may also carry optional `details` (up to 4,000 characters) for
212
+ self-contained intent and completion guidance. Details are returned on the
213
+ structured item, shown explicitly for Current on resume, and available from the
214
+ read-only checklist dialog without expanding the sidebar or queued labels.
215
+ Schema 1 string arrays and schema 2 `{ id, text }` records remain readable.
216
+ Schema 3 is selected when details first appear and remains the record version if
217
+ the final detail is later cleared. Set structured edit `details` to `null` to
218
+ clear it.
210
219
  After completing Current, read the latest revision and use `complete-current` to
211
220
  move it to Completed and promote the next Queued item. Update the ledger at
212
221
  meaningful boundaries, not after every edit. Checklist state never completes a
@@ -299,9 +308,9 @@ For an existing JSONC configuration, add the equivalent entry manually:
299
308
  }
300
309
  ```
301
310
 
302
- Re-running `activate` also migrates work-context entries previously generated
303
- under the unsupported legacy `plugins` field. Unrelated legacy entries are
304
- preserved rather than activated or removed implicitly.
311
+ Re-running `activate` or `deactivate` migrates every entry from the unsupported
312
+ legacy `plugins` field into the canonical `plugin` array, preserves entry order,
313
+ removes exact duplicates, and deletes `plugins`.
305
314
 
306
315
  Update managed activation from one activated project with an exact version:
307
316
 
@@ -197,11 +197,17 @@ function activate(enabled, force) {
197
197
  || item.startsWith(`${packageManifest.name}@`)
198
198
  || item === "-work-context"
199
199
  );
200
- config.plugin = [...(config.plugin || []).filter((item) => !isWorkContextEntry(item)), entry];
201
- if (config.plugins) {
202
- config.plugins = config.plugins.filter((item) => !isWorkContextEntry(item));
203
- if (config.plugins.length === 0) delete config.plugins;
204
- }
200
+ const seenPluginEntries = new Set();
201
+ config.plugin = [...(config.plugin || []), ...(config.plugins || [])]
202
+ .filter((item) => !isWorkContextEntry(item))
203
+ .filter((item) => {
204
+ const key = JSON.stringify(item);
205
+ if (seenPluginEntries.has(key)) return false;
206
+ seenPluginEntries.add(key);
207
+ return true;
208
+ });
209
+ config.plugin.push(entry);
210
+ delete config.plugins;
205
211
  managedTuiConfig.plugin = [...(managedTuiConfig.plugin || []).filter((item) => !isWorkContextEntry(item)), entry];
206
212
  const files = new Map([
207
213
  [configRelative, JSON.stringify(config, null, 2) + "\n"],
package/commands/wc.md CHANGED
@@ -141,7 +141,7 @@ Supported syntax:
141
141
  - `profiles setup` must use interactive questions for mode and light/standard/deep labels, apply mode and mappings in separate atomic structured calls, then offer to refresh unfinished stages; `profiles reset` requires explicit confirmation and removes mappings without changing stage metadata or mode
142
142
  - expanded stage details show one unlabeled line `<capability> · <depth> · <model>`; review metadata is not displayed as a model recommendation
143
143
  - capability recommendations never select a model or agent, create a replacement session, block resume, or persist mapping targets in tracked workspace data
144
- - stage execution state preserves string-array section compatibility while exposing stable `{ id, text }` identities in `items`; `current` is the first remaining item and `queued` contains later remaining items in order. `replace` accepts strings or structured items, while `update` accepts `add`, `remove`, and `edit` changes; use IDs for duplicate or reworded text
144
+ - stage execution state preserves string-array section compatibility while exposing stable `{ id, text, details? }` identities in `items`; `text` is the compact label and optional `details` contains self-contained guidance. `current` is the first remaining item and `queued` contains later remaining items in order. `replace` accepts strings or structured items, while `update` accepts `add`, `remove`, and `edit` changes; use IDs for duplicate or reworded text, and set an edit's `details` to `null` to clear it
145
145
  - read stage execution state first and pass its revision as `expectedRevision`; absent legacy state has revision `0`, and a stale mutation returns `EXECUTION_REVISION_CONFLICT` without changing newer state
146
146
  - execution mutations require the active stage session, trim and deduplicate items, reject overlap between `completed` and `remaining`, and enforce bounded item counts, lengths, and serialized size
147
147
  - update execution state after meaningful scope changes, decisions, substantial work, blockers, or verification changes and before handoff; do not update it for every trivial edit or tool call
@@ -151,7 +151,7 @@ Supported syntax:
151
151
  - when the saved prompt contains several clear deliverables, add `In this stage we will` with 2-5 short outcome-oriented bullets derived only from the prompt, previous result, and workspace knowledge; do not invent scope, and omit this block for a small stage
152
152
  - do not expose raw workspace/stage/session identifiers, ordinals, `ok` flags, or absent error codes in the user-facing resume summary
153
153
  - `resume.context.workspace_knowledge` contains every active durable knowledge entry for the workspace; treat it as established shared context, and do not repeat earlier analysis unless an entry is incomplete, contradicted, or needs verification
154
- - when stage execution state exists, `resume.context.execution_state` is the current stage-local operational checkpoint. Its structured `current` and `queued` fields identify the active item and its ordered backlog; continue from it without rewriting the original prompt, and never copy it automatically into workspace knowledge or unrelated stages
154
+ - when stage execution state exists, `resume.context.execution_state` is the current stage-local operational checkpoint. Its structured `current` and `queued` fields identify the active item and its ordered backlog; Current details are explicit on resume while queued presentation remains compact. Continue from it without rewriting the original prompt, and never copy it automatically into workspace knowledge or unrelated stages
155
155
  - Planning-stage resume may include `resume.context.delivery_context`, a bounded workspace-level summary of committed candidates and environment checkpoints; it is release coordination context, not stage ownership
156
156
  - when the user asks how to deploy from Planning, inspect the exact commit range and the repository's own deployment documentation, scripts, infrastructure, migrations, container definitions, configuration examples, and CI; produce ordered prerequisites, deployment, verification, rollback, and unresolved blockers instead of assuming that push or one generic command is sufficient
157
157
  - delivery planning must never persist secret values; mention only required secret or configuration names, ask one focused question when environment or baseline is ambiguous, and never mark delivery merely because commit, push, or CI succeeded
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "opencode-work-context",
3
3
  "type": "module",
4
- "version": "0.12.0",
4
+ "version": "0.13.0",
5
5
  "description": "Filesystem work-context core and OpenCode adapter",
6
6
  "license": "MIT",
7
7
  "author": {
@@ -381,7 +381,7 @@ export const checklistOptions = (execution, width = 80) => {
381
381
  : value;
382
382
  const option = (value, section, index, title, category) => {
383
383
  const entry = item(value, section, index);
384
- return { title: title(entry.text), value: `execution-${entry.id}`, category };
384
+ return { title: title(entry.text), value: `execution-${entry.id}`, category, ...(entry.details ? { details: entry.details } : {}) };
385
385
  };
386
386
  const options = [];
387
387
  const current = execution.current || structuredItems("remaining")[0];
@@ -396,6 +396,29 @@ export const checklistOptions = (execution, width = 80) => {
396
396
  return options.length ? [{ title: "Close", value: "close", category: "Checklist" }, ...options] : [{ title: "Checklist is empty.", value: "empty", disabled: true }];
397
397
  };
398
398
 
399
+ export const checklistDetailsOptions = (details, width = 80) => {
400
+ const limit = Math.max(20, width - 12);
401
+ const lines = [];
402
+ for (const paragraph of details.split(/\r?\n/)) {
403
+ if (!paragraph) {
404
+ lines.push(" ");
405
+ continue;
406
+ }
407
+ let rest = paragraph;
408
+ while (rest.length > limit) {
409
+ let split = rest.lastIndexOf(" ", limit);
410
+ if (split < 1) split = limit;
411
+ lines.push(rest.slice(0, split));
412
+ rest = rest.slice(split).trimStart();
413
+ }
414
+ if (rest) lines.push(rest);
415
+ }
416
+ return [
417
+ { title: "Back", value: "back", category: "Checklist" },
418
+ ...lines.map((title, index) => ({ title, value: `details-${index}`, category: "Details" })),
419
+ ];
420
+ };
421
+
399
422
  export const openChecklistDialog = (api, result) => {
400
423
  if (typeof api?.ui?.DialogSelect !== "function" || typeof api?.ui?.dialog?.replace !== "function") return false;
401
424
  const current = result?.data?.stages?.find((stage) => stage.current || stage.id === result.data.currentStage);
@@ -405,12 +428,21 @@ export const openChecklistDialog = (api, result) => {
405
428
  }
406
429
  const width = api.renderer?.width || 80;
407
430
  api.ui.dialog.setSize?.(width < 50 ? "small" : "large");
408
- api.ui.dialog.replace(() => api.ui.DialogSelect({
431
+ const showChecklist = () => api.ui.dialog.replace(() => api.ui.DialogSelect({
409
432
  title: `Checklist · ${current.title}`,
410
433
  placeholder: "Checklist",
411
434
  options: checklistOptions(current.execution, width),
412
- onSelect: (option) => { if (option.value === "close") api.ui.dialog.clear?.(); },
435
+ onSelect: (option) => {
436
+ if (option.value === "close") api.ui.dialog.clear?.();
437
+ else if (option.details) api.ui.dialog.replace(() => api.ui.DialogSelect({
438
+ title: `Checklist details · ${option.title}`,
439
+ placeholder: "Details",
440
+ options: checklistDetailsOptions(option.details, width),
441
+ onSelect: (detailOption) => { if (detailOption.value === "back") showChecklist(); },
442
+ }));
443
+ },
413
444
  }));
445
+ showChecklist();
414
446
  return true;
415
447
  };
416
448
 
package/src/core.js CHANGED
@@ -11,7 +11,7 @@ import { isDependencySatisfied } from "./stage-status.js";
11
11
  import { CandidateStore } from "./candidates.js";
12
12
  import { DeliveryStore } from "./delivery.js";
13
13
  import { doctorDelivery as runDeliveryDoctor } from "./delivery-doctor.js";
14
- import { applyExecutionItemPatch, applyExecutionTextPatchItems, assertExecutionSize, EXECUTION_SECTIONS, executionInputUsesItems, executionItems, executionItemsFromState, executionPatchUsesItems, executionReadModel, normalizeExecutionItemState, normalizeExecutionState } from "./stage-execution.js";
14
+ import { applyExecutionItemPatch, applyExecutionTextPatchItems, assertExecutionSize, EXECUTION_SECTIONS, executionInputUsesItems, executionItems, executionItemsFromState, executionPatchUsesItems, executionReadModel, executionSchemaFor, normalizeExecutionItemState, normalizeExecutionState } from "./stage-execution.js";
15
15
  import { CAPABILITY_CLASSIFICATIONS, CAPABILITY_DEPTHS, CAPABILITY_PROFILES, capabilityProfileMode, capabilityRecommendations, configureCapabilityMappings, readCapabilityMappings, resetCapabilityMappings, validateCapabilityMappings } from "./capability-profiles.js";
16
16
  import { acknowledgeGitCommit, initializeGitCheckpoint } from "./git-acknowledgement.js";
17
17
  import { rollbackCommitRef } from "./git-candidates.js";
@@ -69,7 +69,7 @@ ${confirmationRequired ? "- Ask for the explicitly required confirmation and wai
69
69
  const executionInstruction = (record) => {
70
70
  if (!record) return "";
71
71
  const execution = executionReadModel(record);
72
- const current = execution.current ? `\nCurrent checklist item: ${execution.current.text}` : "\nCurrent checklist item: none";
72
+ const current = execution.current ? `\nCurrent checklist item: ${execution.current.text}${execution.current.details ? `\nCurrent checklist details: ${execution.current.details}` : ""}` : "\nCurrent checklist item: none";
73
73
  const queued = execution.queued.length
74
74
  ? `\nQueued checklist items: ${execution.queued.map((item) => item.text).join(" | ")}`
75
75
  : "\nQueued checklist items: none";
@@ -736,7 +736,7 @@ export class WorkContext {
736
736
  const items = structured ? normalizeExecutionItemState(input, current) : executionItemsFromState(state, current);
737
737
  if (current && JSON.stringify(executionItems(current)) === JSON.stringify(items)) return this.result(executionReadModel(current), []);
738
738
  const timestamp = new Date().toISOString();
739
- const record = { schema: 2, workspace, stage, revision: revision + 1, created_at: current?.created_at || timestamp, updated_at: timestamp, updated_by: actor(this.options), items };
739
+ const record = { schema: executionSchemaFor(items, current), workspace, stage, revision: revision + 1, created_at: current?.created_at || timestamp, updated_at: timestamp, updated_by: actor(this.options), items };
740
740
  assertExecutionSize(record);
741
741
  this.storage.writeStageExecution(workspace, stage, record);
742
742
  return this.result(executionReadModel(record), [this.storage.stageExecutionFile(workspace, stage)]);
@@ -759,7 +759,7 @@ export class WorkContext {
759
759
  const items = structured ? applyExecutionItemPatch(current || empty, patch) : applyExecutionTextPatchItems(current || empty, patch);
760
760
  if (current && JSON.stringify(executionItems(current)) === JSON.stringify(items)) return this.result(executionReadModel(current), []);
761
761
  const timestamp = new Date().toISOString();
762
- const record = { schema: 2, workspace, stage, revision: revision + 1, created_at: current?.created_at || timestamp, updated_at: timestamp, updated_by: actor(this.options), items };
762
+ const record = { schema: executionSchemaFor(items, current), workspace, stage, revision: revision + 1, created_at: current?.created_at || timestamp, updated_at: timestamp, updated_by: actor(this.options), items };
763
763
  assertExecutionSize(record);
764
764
  this.storage.writeStageExecution(workspace, stage, record);
765
765
  return this.result(executionReadModel(record), [this.storage.stageExecutionFile(workspace, stage)]);
@@ -783,7 +783,7 @@ export class WorkContext {
783
783
  items.completed.push(currentItem);
784
784
  const nextItems = normalizeExecutionItemState(items, current);
785
785
  const timestamp = new Date().toISOString();
786
- const record = { schema: 2, workspace, stage, revision: revision + 1, created_at: current.created_at, updated_at: timestamp, updated_by: actor(this.options), items: nextItems };
786
+ const record = { schema: executionSchemaFor(nextItems, current), workspace, stage, revision: revision + 1, created_at: current.created_at, updated_at: timestamp, updated_by: actor(this.options), items: nextItems };
787
787
  assertExecutionSize(record);
788
788
  this.storage.writeStageExecution(workspace, stage, record);
789
789
  return this.result(executionReadModel(record), [this.storage.stageExecutionFile(workspace, stage)]);
@@ -15,6 +15,7 @@ export const EXECUTION_LIMITS = Object.freeze({
15
15
  itemsPerSection: 50,
16
16
  totalItems: 200,
17
17
  itemLength: 500,
18
+ detailsLength: 4000,
18
19
  bytes: 32768,
19
20
  });
20
21
 
@@ -30,6 +31,13 @@ const normalizeText = (text, section, code = ERROR_CODES.INVALID_ARGUMENT) => {
30
31
  return value;
31
32
  };
32
33
 
34
+ const normalizeDetails = (details, section, code = ERROR_CODES.INVALID_ARGUMENT) => {
35
+ if (typeof details !== "string" || !details.trim()) fail(code, `${section} details must be non-empty text`);
36
+ const value = details.trim();
37
+ if (value.length > EXECUTION_LIMITS.detailsLength) fail(code === ERROR_CODES.STORAGE_ERROR ? code : ERROR_CODES.EXECUTION_LIMIT_EXCEEDED, `Execution item details cannot exceed ${EXECUTION_LIMITS.detailsLength} characters`);
38
+ return value;
39
+ };
40
+
33
41
  const normalizeItems = (items, section) => {
34
42
  if (!Array.isArray(items)) fail(ERROR_CODES.INVALID_ARGUMENT, `${section} must be an array of strings`);
35
43
  if (items.length > EXECUTION_LIMITS.itemsPerSection) fail(ERROR_CODES.EXECUTION_LIMIT_EXCEEDED, `${section} cannot contain more than ${EXECUTION_LIMITS.itemsPerSection} items`);
@@ -87,16 +95,18 @@ const validateId = (id, code = ERROR_CODES.INVALID_ARGUMENT) => {
87
95
  return id;
88
96
  };
89
97
 
90
- const normalizeStoredItems = (items) => {
98
+ const normalizeStoredItems = (items, allowDetails = false) => {
91
99
  if (!items || typeof items !== "object" || Array.isArray(items) || !exactKeys(items, EXECUTION_SECTIONS)) fail(ERROR_CODES.STORAGE_ERROR, "Invalid stage execution state");
92
100
  const normalized = {};
93
101
  for (const section of EXECUTION_SECTIONS) {
94
102
  if (!Array.isArray(items[section])) fail(ERROR_CODES.STORAGE_ERROR, "Invalid stage execution state");
95
103
  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");
104
+ if (!item || typeof item !== "object" || Array.isArray(item) || !exactKeys(item, allowDetails ? ["id", "text", "details"] : ["id", "text"])) fail(ERROR_CODES.STORAGE_ERROR, "Invalid stage execution state");
97
105
  const text = normalizeText(item.text, section, ERROR_CODES.STORAGE_ERROR);
98
106
  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 };
107
+ const details = Object.hasOwn(item, "details") ? normalizeDetails(item.details, section, ERROR_CODES.STORAGE_ERROR) : undefined;
108
+ if (details !== undefined && details !== item.details) fail(ERROR_CODES.STORAGE_ERROR, "Stage execution state is not normalized");
109
+ return { id: validateId(item.id, ERROR_CODES.STORAGE_ERROR), text, ...(details === undefined ? {} : { details }) };
100
110
  });
101
111
  }
102
112
  assertItemCounts(normalized, ERROR_CODES.STORAGE_ERROR);
@@ -105,7 +115,7 @@ const normalizeStoredItems = (items) => {
105
115
  };
106
116
 
107
117
  export function executionItems(record) {
108
- if (record.schema === 2) return Object.fromEntries(EXECUTION_SECTIONS.map((section) => [section, record.items[section].map((item) => ({ ...item }))]));
118
+ if (record.schema >= 2) return Object.fromEntries(EXECUTION_SECTIONS.map((section) => [section, record.items[section].map((item) => ({ ...item }))]));
109
119
  return Object.fromEntries(EXECUTION_SECTIONS.map((section) => [section, record[section].map((text, index) => ({ id: legacyItemId(section, index, text), text }))]));
110
120
  }
111
121
 
@@ -130,13 +140,20 @@ export function executionState(record) {
130
140
  return Object.fromEntries(EXECUTION_SECTIONS.map((section) => [section, executionItems(record)[section].map((item) => item.text)]));
131
141
  }
132
142
 
143
+ const takePreviousItem = (previousItems, used, section, text) => {
144
+ const local = previousItems[section].filter((item) => item.text === text && !used.has(item.id));
145
+ if (local.length > 1) fail(ERROR_CODES.INVALID_ARGUMENT, "Text-only execution replacement is ambiguous; use item IDs", { text, matches: local.length });
146
+ if (local.length === 1) return local[0];
147
+ const acrossSections = EXECUTION_SECTIONS.flatMap((name) => previousItems[name]).filter((item) => item.text === text && !used.has(item.id));
148
+ if (acrossSections.length > 1) fail(ERROR_CODES.INVALID_ARGUMENT, "Text-only execution replacement is ambiguous; use item IDs", { text, matches: acrossSections.length });
149
+ return acrossSections[0];
150
+ };
151
+
133
152
  export function executionItemsFromState(state, previous = null) {
134
153
  const previousItems = previous ? executionItems(previous) : Object.fromEntries(EXECUTION_SECTIONS.map((section) => [section, []]));
135
154
  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
155
  const items = Object.fromEntries(EXECUTION_SECTIONS.map((section) => [section, state[section].map((text) => {
139
- const previousItem = take(section, text);
156
+ const previousItem = takePreviousItem(previousItems, used, section, text);
140
157
  if (previousItem) used.add(previousItem.id);
141
158
  return previousItem || { id: randomUUID(), text };
142
159
  })]));
@@ -148,6 +165,10 @@ export function executionInputUsesItems(input) {
148
165
  return EXECUTION_SECTIONS.some((section) => Array.isArray(input?.[section]) && input[section].some((item) => typeof item !== "string"));
149
166
  }
150
167
 
168
+ export function executionSchemaFor(items, previous = null) {
169
+ return previous?.schema === 3 || EXECUTION_SECTIONS.some((section) => items[section].some((item) => Object.hasOwn(item, "details"))) ? 3 : 2;
170
+ }
171
+
151
172
  export function executionPatchUsesItems(patch) {
152
173
  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
174
  }
@@ -198,14 +219,15 @@ export function normalizeExecutionItemState(input, previous = null) {
198
219
  items[section] = sectionItems.map((item) => {
199
220
  if (typeof item === "string") {
200
221
  const text = normalizeText(item, section);
201
- const previousItem = previousItems[section].find((candidate) => candidate.text === text && !used.has(candidate.id));
222
+ const previousItem = takePreviousItem(previousItems, used, section, text);
202
223
  if (previousItem) used.add(previousItem.id);
203
224
  return previousItem || { id: randomUUID(), text };
204
225
  }
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`);
226
+ if (!item || typeof item !== "object" || Array.isArray(item) || !exactKeys(item, ["id", "text", "details"]) || item.text === undefined) fail(ERROR_CODES.INVALID_ARGUMENT, `${section} contains an invalid execution item`);
206
227
  const id = item.id === undefined ? randomUUID() : validateId(item.id);
207
228
  used.add(id);
208
- return { id, text: normalizeText(item.text, section) };
229
+ const details = Object.hasOwn(item, "details") ? normalizeDetails(item.details, section) : undefined;
230
+ return { id, text: normalizeText(item.text, section), ...(details === undefined ? {} : { details }) };
209
231
  });
210
232
  }
211
233
  assertItemCounts(items);
@@ -229,8 +251,17 @@ const normalizeItemChanges = (changes, operation) => {
229
251
  if (!item || typeof item !== "object" || Array.isArray(item) || !exactKeys(item, ["id"])) fail(ERROR_CODES.INVALID_ARGUMENT, "Structured execution removals require an item ID");
230
252
  return { id: validateId(item.id) };
231
253
  }
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) };
254
+ if (!item || typeof item !== "object" || Array.isArray(item) || !exactKeys(item, ["id", "text", "details"])) fail(ERROR_CODES.INVALID_ARGUMENT, `Structured execution ${operation} changes contain an invalid item`);
255
+ if (operation === "add" && item.text === undefined) fail(ERROR_CODES.INVALID_ARGUMENT, "Structured execution additions require text");
256
+ if (operation === "edit" && item.id === undefined) fail(ERROR_CODES.INVALID_ARGUMENT, "Structured execution edits require an item ID");
257
+ if (operation === "edit" && item.text === undefined && !Object.hasOwn(item, "details")) fail(ERROR_CODES.INVALID_ARGUMENT, "Structured execution edits require text or details");
258
+ const result = { id: operation === "add" && item.id === undefined ? randomUUID() : validateId(item.id) };
259
+ if (item.text !== undefined) result.text = normalizeText(item.text, section);
260
+ if (Object.hasOwn(item, "details")) {
261
+ if (operation === "add" && item.details === null) fail(ERROR_CODES.INVALID_ARGUMENT, "Structured execution additions cannot clear details");
262
+ result.details = item.details === null ? null : normalizeDetails(item.details, section);
263
+ }
264
+ return result;
234
265
  });
235
266
  }
236
267
  return result;
@@ -250,11 +281,20 @@ export function applyExecutionItemPatch(current, patch) {
250
281
  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
282
  return matches[0].id;
252
283
  }));
253
- const edits = new Map((edit[section] || []).map((item) => [item.id, item.text]));
284
+ const edits = new Map((edit[section] || []).map((item) => [item.id, item]));
254
285
  for (const id of [...removed, ...edits.keys()]) if (!known.has(id)) fail(ERROR_CODES.INVALID_ARGUMENT, "Execution item ID was not found", { id });
255
286
  items[section] = items[section]
256
287
  .filter((item) => !removed.has(item.id))
257
- .map((item) => edits.has(item.id) ? { id: item.id, text: edits.get(item.id) } : item);
288
+ .map((item) => {
289
+ const change = edits.get(item.id);
290
+ if (!change) return item;
291
+ const next = { ...item, ...(change.text === undefined ? {} : { text: change.text }) };
292
+ if (Object.hasOwn(change, "details")) {
293
+ if (change.details === null) delete next.details;
294
+ else next.details = change.details;
295
+ }
296
+ return next;
297
+ });
258
298
  items[section].push(...(add[section] || []));
259
299
  }
260
300
  assertItemCounts(items);
@@ -266,7 +306,7 @@ export function validateExecutionRecord(record, workspace, stage) {
266
306
  const legacyAllowed = ["schema", "workspace", "stage", "revision", "created_at", "updated_at", "updated_by", ...EXECUTION_SECTIONS];
267
307
  const currentAllowed = ["schema", "workspace", "stage", "revision", "created_at", "updated_at", "updated_by", "items"];
268
308
  if (!record || typeof record !== "object" || Array.isArray(record)
269
- || ![1, 2].includes(record.schema) || record.workspace !== workspace || record.stage !== stage
309
+ || ![1, 2, 3].includes(record.schema) || record.workspace !== workspace || record.stage !== stage
270
310
  || !Number.isInteger(record.revision) || record.revision < 1
271
311
  || !validTimestamp(record.created_at) || !validTimestamp(record.updated_at)
272
312
  || Date.parse(record.updated_at) < Date.parse(record.created_at)
@@ -280,7 +320,7 @@ export function validateExecutionRecord(record, workspace, stage) {
280
320
  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
321
  } else {
282
322
  if (!exactKeys(record, currentAllowed)) fail(ERROR_CODES.STORAGE_ERROR, "Invalid stage execution state");
283
- normalizeStoredItems(record.items);
323
+ normalizeStoredItems(record.items, record.schema === 3);
284
324
  }
285
325
  } catch (error) {
286
326
  if (error.code === ERROR_CODES.STORAGE_ERROR) throw error;
@@ -46,9 +46,9 @@ 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 executionItem = tool.schema.union([tool.schema.string(), tool.schema.object({ id: tool.schema.string().optional(), text: tool.schema.string() }).strict()]);
49
+ const executionItem = tool.schema.union([tool.schema.string(), tool.schema.object({ id: tool.schema.string().optional(), text: tool.schema.string(), details: tool.schema.string().optional() }).strict()]);
50
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();
51
+ const executionEdit = tool.schema.object({ id: tool.schema.string(), text: tool.schema.string().optional(), details: tool.schema.string().nullable().optional() }).strict().refine((item) => item.text !== undefined || item.details !== undefined, { message: "Structured execution edits require text or details" });
52
52
  const executionSections = Object.fromEntries(["scope", "completed", "remaining", "decisions", "blockers", "verification"].map((section) => [section, tool.schema.array(executionItem).optional()]));
53
53
  const executionRemovalSections = Object.fromEntries(["scope", "completed", "remaining", "decisions", "blockers", "verification"].map((section) => [section, tool.schema.array(executionRemoval).optional()]));
54
54
  const executionEditSections = Object.fromEntries(["scope", "completed", "remaining", "decisions", "blockers", "verification"].map((section) => [section, tool.schema.array(executionEdit).optional()]));