opencode-work-context 0.2.1 → 0.4.1
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 +44 -0
- package/commands/wc.md +6 -0
- package/package.json +1 -1
- package/plugin/attention.js +364 -0
- package/plugin/notifier.js +83 -0
- package/plugin/session-switcher.js +14 -7
- package/plugin/stage-switcher.js +27 -26
- package/plugin/stages-tui.js +22 -15
- package/plugin/tui-state.js +31 -0
- package/plugin/tui.js +2 -0
- package/plugin/work-context-modal.js +74 -31
- package/plugin/workspace-switcher.js +16 -7
- package/src/core.js +65 -12
- package/src/storage.js +25 -5
- package/src/tool-definitions.js +3 -1
- package/tools/work_context_reopen_workspace.js +3 -0
- package/tools/work_context_restore_stage.js +3 -0
package/src/core.js
CHANGED
|
@@ -15,11 +15,13 @@ const activeKnowledge = (records) => records
|
|
|
15
15
|
.map(({ id: knowledgeId, title, kind, text, sources }) => ({ id: knowledgeId, title, kind, text, sources }));
|
|
16
16
|
const body = (title, goal = "", prompt = "") => `# ${title}\n\n${goal ? `## Goal\n\n${goal}\n` : ""}${prompt ? `\n## Prompt\n\n${prompt}\n` : ""}`;
|
|
17
17
|
const stageBody = (record, title, goal, prompt = record.data.prompt || "") => {
|
|
18
|
-
const result = record.body.match(/\n## Result\s*\n[\s\S]*?(?=\n## Reopen History|$)/)?.[0] || "";
|
|
19
|
-
const
|
|
20
|
-
|
|
18
|
+
const result = record.body.match(/\n## Result\s*\n[\s\S]*?(?=\n## (?:Reopen|Archive) History|$)/)?.[0] || "";
|
|
19
|
+
const reopenHistory = record.body.match(/\n## Reopen History[\s\S]*?(?=\n## (?:Result|Archive History)|$)/)?.[0] || "";
|
|
20
|
+
const archiveHistory = record.body.match(/\n## Archive History[\s\S]*?(?=\n## (?:Result|Reopen History)|$)/)?.[0] || "";
|
|
21
|
+
return `${body(title, goal, prompt).trimEnd()}${result}${reopenHistory}${archiveHistory}`;
|
|
21
22
|
};
|
|
22
|
-
const stageResult = (record) => record.body.match(/\n## Result\s*\n([\s\S]*?)(?=\n## Reopen History|$)/)?.[1]?.trim() ?? null;
|
|
23
|
+
const stageResult = (record) => record.body.match(/\n## Result\s*\n([\s\S]*?)(?=\n## (?:Reopen|Archive) History|$)/)?.[1]?.trim() ?? null;
|
|
24
|
+
const appendHistory = (bodyText, heading, entry) => `${bodyText.trimEnd()}${bodyText.includes(`\n## ${heading}\n`) ? "" : `\n\n## ${heading}\n`}\n- ${entry}\n`;
|
|
23
25
|
const automaticFinishAllowed = (storage, workspace) => /(?:^|\n)AUTO_STAGE_FINISH:\s*allowed\s*$/mi.test(storage.readStage(workspace, "01").data.prompt || "");
|
|
24
26
|
const assertNoSymlinkPath = (file) => { let current = path.parse(file).root; for (const part of file.slice(current.length).split(path.sep).filter(Boolean)) { current = path.join(current, part); try { if (fs.lstatSync(current).isSymbolicLink()) fail(ERROR_CODES.STORAGE_ERROR, `Symlink path component is not supported: ${current}`); } catch (error) { if (error.code !== "ENOENT") throw error; break; } } };
|
|
25
27
|
|
|
@@ -138,6 +140,23 @@ export class WorkContext {
|
|
|
138
140
|
});
|
|
139
141
|
}
|
|
140
142
|
|
|
143
|
+
reopenWorkspace(workspace, reason) {
|
|
144
|
+
workspace = normalizeWorkspaceId(workspace);
|
|
145
|
+
if (!reason?.trim()) fail(ERROR_CODES.INVALID_ARGUMENT, "Reopen reason is required");
|
|
146
|
+
return this.transact(`workspace-${workspace}`, () => {
|
|
147
|
+
const record = this.storage.readWorkspace(workspace);
|
|
148
|
+
if (record.data.status !== "completed") fail(ERROR_CODES.INVALID_STATE, "Only completed workspaces can be reopened", { status: record.data.status });
|
|
149
|
+
const reopenedAt = new Date().toISOString();
|
|
150
|
+
const entry = { at: reopenedAt, reason: reason.trim(), actor: actor(this.options) };
|
|
151
|
+
record.data.status = "in_progress";
|
|
152
|
+
record.data.reopen_history = [...(record.data.reopen_history || []), entry];
|
|
153
|
+
record.data.updated_at = reopenedAt;
|
|
154
|
+
this.storage.writeMarkdown(this.storage.workspaceFile(workspace), record.data, appendHistory(record.body, "Reopen History", `${reopenedAt}: ${reason.trim()}`));
|
|
155
|
+
generateProjections(this.storage);
|
|
156
|
+
return this.result({ workspace, status: "in_progress", reopen: entry }, [workspace]);
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
|
|
141
160
|
sessionById(sessionId) {
|
|
142
161
|
return reduceSessions(this.storage.readEvents()).find((session) => session.session_id === sessionId) || null;
|
|
143
162
|
}
|
|
@@ -365,8 +384,9 @@ export class WorkContext {
|
|
|
365
384
|
const nextResult = result.trim();
|
|
366
385
|
if (currentResult === nextResult) return this.result({ workspace, stage, result: nextResult }, []);
|
|
367
386
|
record.data.updated_at = new Date().toISOString();
|
|
368
|
-
const history = record.body.match(/\n## Reopen History[\s\S]*?(?=\n## Result|$)/)?.[0] || "";
|
|
369
|
-
const
|
|
387
|
+
const history = record.body.match(/\n## Reopen History[\s\S]*?(?=\n## (?:Result|Archive History)|$)/)?.[0] || "";
|
|
388
|
+
const archiveHistory = record.body.match(/\n## Archive History[\s\S]*?(?=\n## (?:Result|Reopen History)|$)/)?.[0] || "";
|
|
389
|
+
const nextBody = `${body(record.data.title, record.data.goal, record.data.prompt).trimEnd()}\n\n## Result\n\n${nextResult}${history}${archiveHistory}`;
|
|
370
390
|
this.storage.writeMarkdown(this.storage.stageFile(workspace, stage), record.data, nextBody);
|
|
371
391
|
generateProjections(this.storage);
|
|
372
392
|
return this.result({ workspace, stage, result: nextResult }, [workspace, stage]);
|
|
@@ -380,14 +400,46 @@ export class WorkContext {
|
|
|
380
400
|
const record = this.storage.readStage(workspace, stage);
|
|
381
401
|
if (record.data.status === "archived") return this.result({ workspace, stage, status: "archived" }, []);
|
|
382
402
|
if (activeSession(this.storage.readEvents(), workspace, stage)) fail(ERROR_CODES.ACTIVE_SESSION_EXISTS, "Cannot archive a stage with an active session");
|
|
403
|
+
const archivedAt = new Date().toISOString();
|
|
404
|
+
const entry = { action: "archived", at: archivedAt, actor: actor(this.options), previous_status: record.data.status };
|
|
383
405
|
record.data.status = "archived";
|
|
384
|
-
record.data.
|
|
385
|
-
|
|
406
|
+
record.data.archive_history = [...(record.data.archive_history || []), entry];
|
|
407
|
+
record.data.updated_at = archivedAt;
|
|
408
|
+
this.storage.writeMarkdown(this.storage.stageFile(workspace, stage), record.data, appendHistory(record.body, "Archive History", `${archivedAt}: archived from ${entry.previous_status}`));
|
|
386
409
|
generateProjections(this.storage);
|
|
387
410
|
return this.result({ workspace, stage, status: "archived" }, [workspace, stage]);
|
|
388
411
|
});
|
|
389
412
|
}
|
|
390
413
|
|
|
414
|
+
restoreStage(workspace, stage, reason) {
|
|
415
|
+
workspace = normalizeWorkspaceId(workspace);
|
|
416
|
+
stage = normalizeStageId(stage);
|
|
417
|
+
if (!reason?.trim()) fail(ERROR_CODES.INVALID_ARGUMENT, "Restore reason is required");
|
|
418
|
+
return this.transact(`stage-${workspace}-${stage}`, () => {
|
|
419
|
+
const workspaceRecord = this.storage.readWorkspace(workspace);
|
|
420
|
+
if (workspaceRecord.data.status === "cancelled") fail(ERROR_CODES.INVALID_STATE, "Cannot restore a stage in a cancelled workspace");
|
|
421
|
+
const record = this.storage.readStage(workspace, stage);
|
|
422
|
+
const active = activeSession(this.storage.readEvents(), workspace, stage);
|
|
423
|
+
if (active) fail(ERROR_CODES.ACTIVE_SESSION_EXISTS, "Cannot restore a stage with an active session", { session_id: active.session_id });
|
|
424
|
+
if (record.data.status !== "archived") fail(ERROR_CODES.INVALID_STATE, "Only archived stages can be restored", { status: record.data.status });
|
|
425
|
+
const archived = [...(record.data.archive_history || [])].reverse().find((item) => item.action === "archived");
|
|
426
|
+
const restoredStatus = archived?.previous_status || "in_progress";
|
|
427
|
+
const restoredAt = new Date().toISOString();
|
|
428
|
+
const entry = { action: "restored", at: restoredAt, reason: reason.trim(), actor: actor(this.options), restored_status: restoredStatus };
|
|
429
|
+
record.data.status = restoredStatus;
|
|
430
|
+
record.data.archive_history = [...(record.data.archive_history || []), entry];
|
|
431
|
+
record.data.updated_at = restoredAt;
|
|
432
|
+
this.storage.writeMarkdown(this.storage.stageFile(workspace, stage), record.data, appendHistory(record.body, "Archive History", `${restoredAt}: restored to ${restoredStatus}; ${reason.trim()}`));
|
|
433
|
+
if (workspaceRecord.data.status === "completed" && ["planned", "in_progress"].includes(restoredStatus)) {
|
|
434
|
+
workspaceRecord.data.status = "in_progress";
|
|
435
|
+
workspaceRecord.data.updated_at = restoredAt;
|
|
436
|
+
this.storage.writeMarkdown(this.storage.workspaceFile(workspace), workspaceRecord.data, workspaceRecord.body);
|
|
437
|
+
}
|
|
438
|
+
generateProjections(this.storage);
|
|
439
|
+
return this.result({ workspace, stage, status: restoredStatus, restore: entry, session_started: false, resume_required: ["planned", "in_progress"].includes(restoredStatus) }, [workspace, stage]);
|
|
440
|
+
});
|
|
441
|
+
}
|
|
442
|
+
|
|
391
443
|
listKnowledge(workspace) {
|
|
392
444
|
workspace = normalizeWorkspaceId(workspace);
|
|
393
445
|
this.storage.assertNoSymlinks();
|
|
@@ -520,10 +572,11 @@ export class WorkContext {
|
|
|
520
572
|
record.data.status = "in_progress";
|
|
521
573
|
record.data.reopen_history = [...(record.data.reopen_history || []), entry];
|
|
522
574
|
record.data.updated_at = reopenedAt;
|
|
523
|
-
const history = record.body.match(/\n## Reopen History[\s\S]*?(?=\n## Result|$)/)?.[0]
|
|
575
|
+
const history = record.body.match(/\n## Reopen History[\s\S]*?(?=\n## (?:Result|Archive History)|$)/)?.[0]
|
|
524
576
|
|| "\n\n## Reopen History\n";
|
|
525
577
|
const priorResult = previousResult ? `\n Previous result: ${previousResult}` : "";
|
|
526
|
-
|
|
578
|
+
const archiveHistory = record.body.match(/\n## Archive History[\s\S]*?(?=\n## (?:Result|Reopen History)|$)/)?.[0] || "";
|
|
579
|
+
this.storage.writeMarkdown(this.storage.stageFile(workspace, stage), record.data, `${body(record.data.title, record.data.goal, record.data.prompt).trimEnd()}${history}\n- ${reopenedAt}: ${reason.trim()}${priorResult}\n${archiveHistory}`);
|
|
527
580
|
if (workspaceRecord.data.status === "completed") {
|
|
528
581
|
workspaceRecord.data.status = "in_progress";
|
|
529
582
|
workspaceRecord.data.updated_at = reopenedAt;
|
|
@@ -574,8 +627,8 @@ export class WorkContext {
|
|
|
574
627
|
help(command = "") {
|
|
575
628
|
return this.result({
|
|
576
629
|
command,
|
|
577
|
-
syntax: "/wc [create|list|workspace list|workspace rename|workspace finish|resume|stage add|stage reopen|stage rename|stage update|stage update-prompt|stage update-result|stage force-close|stage archive|stage handoff|stage abandon|stage finish|link-issue|session rename|knowledge list|knowledge add|knowledge update|knowledge supersede|help]",
|
|
578
|
-
note: "stage finish requires an explicit user lifecycle request unless the Planning-stage prompt contains the exact line AUTO_STAGE_FINISH: allowed; stage reopen requires a completed stage and a reason
|
|
630
|
+
syntax: "/wc [create|list|workspace list|workspace rename|workspace finish|workspace reopen|resume|stage add|stage reopen|stage restore|stage rename|stage update|stage update-prompt|stage update-result|stage force-close|stage archive|stage handoff|stage abandon|stage finish|link-issue|session rename|knowledge list|knowledge add|knowledge update|knowledge supersede|help]",
|
|
631
|
+
note: "stage finish requires an explicit user lifecycle request unless the Planning-stage prompt contains the exact line AUTO_STAGE_FINISH: allowed; stage reopen requires a completed stage and a reason; stage restore requires an archived stage and a reason, returns its saved pre-archive status (or in_progress for legacy archives), and requires explicit separate-session resume when actionable; workspace reopen requires a completed workspace and a reason.",
|
|
579
632
|
}, []);
|
|
580
633
|
return this.result({ command, syntax: "/wc [create|list|workspace list|workspace rename|workspace finish|resume|stage add|stage rename|stage update|stage update-prompt|stage update-result|stage force-close|stage archive|stage handoff|stage abandon|stage finish|link-issue|session rename|knowledge list|knowledge add|knowledge update|knowledge supersede|help]", note: "workspace and stage are optional for stage rename/update/update-prompt/update-result/archive/handoff/abandon/finish and session rename/close when the current session identifies them; explicit workspace and stage positions accept padded or unpadded positive integer IDs and structured results remain canonical; zero, signs, decimals, whitespace, and overlong identifiers are invalid; stage update-result requires an existing stage result; finish <stage> is a shortcut for stage finish <stage>; when only one numeric identifier is supplied, six digits mean workspace and one or two digits mean stage; stage add accepts an optional local prompt; from an unassociated OpenCode session it also enters the new stage immediately, while an associated session remains on its current stage; resume returns resume.next_action, resume.instruction, and active shared entries in resume.context.workspace_knowledge; implementation may begin only with a non-empty prompt and no unanswered questions; ask focused questions and do not modify application code when next_action is ask_questions; force-close requires a session ID, reason, and exact confirmation FORCE_CLOSE; before stage finish, add, update, or supersede durable findings, or explicitly declare none; stage finish closes only the current stage session and returns downstream stages for informational prompt review without starting one; workspace finish requires all non-archived stages to be completed; archived stages retain their IDs and history and are hidden from the TUI by default; mutating commands call structured tools; only explicit lifecycle operations change storage." }, []);
|
|
581
634
|
}
|
package/src/storage.js
CHANGED
|
@@ -40,6 +40,17 @@ const validReopenHistory = (history) => Array.isArray(history) && history.every(
|
|
|
40
40
|
&& requiredString(item, "reason")
|
|
41
41
|
&& requiredString(item, "actor")
|
|
42
42
|
&& (item.previous_result === undefined || requiredString(item, "previous_result")));
|
|
43
|
+
const validArchiveHistory = (history) => Array.isArray(history) && history.every((item) => item
|
|
44
|
+
&& typeof item === "object"
|
|
45
|
+
&& !Array.isArray(item)
|
|
46
|
+
&& Object.keys(item).every((key) => ["action", "at", "reason", "actor", "previous_status", "restored_status"].includes(key))
|
|
47
|
+
&& ["archived", "restored"].includes(item.action)
|
|
48
|
+
&& validTimestamp(item.at)
|
|
49
|
+
&& requiredString(item, "actor")
|
|
50
|
+
&& (item.reason === undefined || requiredString(item, "reason"))
|
|
51
|
+
&& (item.previous_status === undefined || ["planned", "in_progress", "completed", "cancelled"].includes(item.previous_status))
|
|
52
|
+
&& (item.restored_status === undefined || ["planned", "in_progress", "completed", "cancelled"].includes(item.restored_status))
|
|
53
|
+
&& (item.action === "archived" ? item.previous_status !== undefined && item.reason === undefined && item.restored_status === undefined : requiredString(item, "reason") && item.restored_status !== undefined && item.previous_status === undefined));
|
|
43
54
|
const validEvents = new Set(["session.started", "session.renamed", "session.handed_off", "session.closed", "session.abandoned"]);
|
|
44
55
|
const validateEvent = (item) => {
|
|
45
56
|
if (!item || item.schema !== 1 || Object.keys(item).some((key) => !["schema", "event_id", "event", "occurred_at", "session_id", "workspace", "stage", "ordinal", "actor", "data"].includes(key)) || !validEvents.has(item.event) || typeof item.event_id !== "string" || !item.event_id.trim() || !validTimestamp(item.occurred_at) || typeof item.session_id !== "string" || !item.session_id.trim() || !/^\d{6}$/.test(item.workspace) || !/^\d{2}$/.test(item.stage) || !Number.isInteger(item.ordinal) || item.ordinal < 1 || typeof item.actor !== "string" || !item.actor.trim() || !item.data || typeof item.data !== "object" || Array.isArray(item.data)) fail(ERROR_CODES.STORAGE_ERROR, "Invalid session event");
|
|
@@ -77,13 +88,22 @@ const validateEventStream = (events) => {
|
|
|
77
88
|
}
|
|
78
89
|
};
|
|
79
90
|
function validateMetadata(data, kind, workspace, stage = null) {
|
|
80
|
-
const allowed = kind === "workspace" ? ["schema", "workspace", "title", "status", "created_at", "updated_at", "tracker_links"] : ["schema", "workspace", "stage", "title", "status", "goal", "prompt", "depends_on", "owner", "created_at", "updated_at", "tracker_links", "reopen_history"];
|
|
91
|
+
const allowed = kind === "workspace" ? ["schema", "workspace", "title", "status", "created_at", "updated_at", "tracker_links", "reopen_history"] : ["schema", "workspace", "stage", "title", "status", "goal", "prompt", "depends_on", "owner", "created_at", "updated_at", "tracker_links", "reopen_history", "archive_history"];
|
|
81
92
|
if (Object.keys(data).some((key) => !allowed.includes(key)) || data.schema !== 1 || !requiredString(data, "workspace") || !/^\d{6}$/.test(data.workspace) || data.workspace !== workspace) fail(ERROR_CODES.STORAGE_ERROR, `Invalid ${kind} metadata`);
|
|
82
93
|
if (!requiredString(data, "title") || !validTimestamp(data.created_at) || !validTimestamp(data.updated_at) || Date.parse(data.updated_at) < Date.parse(data.created_at) || !Array.isArray(data.tracker_links)) fail(ERROR_CODES.STORAGE_ERROR, `Invalid ${kind} metadata`);
|
|
83
94
|
if (!validTrackerLinks(data.tracker_links) || data.tracker_links.some((link) => !link.provider.trim() || !link.project.trim() || ((link.provider === "gitlab" || link.provider === "github") ? (!Number.isInteger(link.iid) || link.iid < 1) : !link.key?.trim()))) fail(ERROR_CODES.STORAGE_ERROR, `Invalid ${kind} tracker links`);
|
|
84
95
|
const statuses = kind === "workspace" ? ["in_progress", "completed", "cancelled"] : ["planned", "in_progress", "completed", "cancelled", "archived"];
|
|
85
96
|
if (!statuses.includes(data.status)) fail(ERROR_CODES.STORAGE_ERROR, `Invalid ${kind} status`);
|
|
86
|
-
|
|
97
|
+
const invalidWorkspaceHistory = kind === "workspace" && data.reopen_history !== undefined && !validReopenHistory(data.reopen_history);
|
|
98
|
+
const invalidStageMetadata = kind === "stage" && (
|
|
99
|
+
data.stage !== stage || !/^\d{2}$/.test(data.stage) || !requiredString(data, "goal")
|
|
100
|
+
|| (data.prompt !== undefined && !requiredString(data, "prompt")) || !requiredString(data, "owner")
|
|
101
|
+
|| !Array.isArray(data.depends_on) || new Set(data.depends_on).size !== data.depends_on.length
|
|
102
|
+
|| data.depends_on.includes(data.stage) || data.depends_on.some((item) => typeof item !== "string" || !/^\d{2}$/.test(item))
|
|
103
|
+
|| (data.reopen_history !== undefined && !validReopenHistory(data.reopen_history))
|
|
104
|
+
|| (data.archive_history !== undefined && !validArchiveHistory(data.archive_history))
|
|
105
|
+
);
|
|
106
|
+
if (invalidWorkspaceHistory || invalidStageMetadata) fail(ERROR_CODES.STORAGE_ERROR, `Invalid ${kind} metadata`);
|
|
87
107
|
}
|
|
88
108
|
export function atomicWrite(file, content) {
|
|
89
109
|
ensure(path.dirname(file));
|
|
@@ -268,7 +288,7 @@ export class FileStorage {
|
|
|
268
288
|
|
|
269
289
|
export function loadConfig(projectRoot, configFile = path.resolve(projectRoot, ".work-context", "config.yaml")) {
|
|
270
290
|
if (!fs.existsSync(configFile)) return {};
|
|
271
|
-
const data = Object.assign(Object.create(null), { storage: Object.create(null), title: Object.create(null), tracker: Object.create(null) });
|
|
291
|
+
const data = Object.assign(Object.create(null), { storage: Object.create(null), title: Object.create(null), tracker: Object.create(null), notifications: Object.create(null) });
|
|
272
292
|
let section = null;
|
|
273
293
|
for (const line of fs.readFileSync(configFile, "utf8").split("\n")) {
|
|
274
294
|
if (!line.trim() || line.trim().startsWith("#")) continue;
|
|
@@ -276,8 +296,8 @@ export function loadConfig(projectRoot, configFile = path.resolve(projectRoot, "
|
|
|
276
296
|
if (!match[1]) { section = match[3] ? null : match[2]; if (match[3]) data[match[2]] = scalarConfig(match[3]); else if (!data[match[2]] || typeof data[match[2]] !== "object") data[match[2]] = Object.create(null); continue; }
|
|
277
297
|
if (section && data[section] && typeof data[section] === "object") data[section][match[2]] = scalarConfig(match[3]);
|
|
278
298
|
}
|
|
279
|
-
if (Object.keys(data).some((key) => !["schema", "storage", "title", "tracker"].includes(key)) || Object.keys(data.storage).some((key) => !["mode", "root", "personal_root"].includes(key)) || Object.keys(data.title).some((key) => key !== "issue_prefix") || Object.keys(data.tracker).some((key) => key !== "provider") || data.schema !== 1 || !data.storage || !["personal", "shared-git", "hybrid"].includes(data.storage.mode) || typeof data.storage.root !== "string" || typeof data.storage.personal_root !== "string" || !data.title || !["none", "short", "full"].includes(data.title.issue_prefix) || !data.tracker || (data.tracker.provider !== null && typeof data.tracker.provider !== "string")) fail(ERROR_CODES.STORAGE_ERROR, "Invalid work-context config");
|
|
299
|
+
if (Object.keys(data).some((key) => !["schema", "storage", "title", "tracker", "notifications"].includes(key)) || Object.keys(data.storage).some((key) => !["mode", "root", "personal_root"].includes(key)) || Object.keys(data.title).some((key) => key !== "issue_prefix") || Object.keys(data.tracker).some((key) => key !== "provider") || !data.notifications || typeof data.notifications !== "object" || Array.isArray(data.notifications) || Object.keys(data.notifications).some((key) => key !== "desktop") || data.schema !== 1 || !data.storage || !["personal", "shared-git", "hybrid"].includes(data.storage.mode) || typeof data.storage.root !== "string" || typeof data.storage.personal_root !== "string" || !data.title || !["none", "short", "full"].includes(data.title.issue_prefix) || !data.tracker || (data.tracker.provider !== null && typeof data.tracker.provider !== "string") || (data.notifications.desktop !== undefined && typeof data.notifications.desktop !== "boolean")) fail(ERROR_CODES.STORAGE_ERROR, "Invalid work-context config");
|
|
280
300
|
return data;
|
|
281
301
|
}
|
|
282
302
|
const scalarConfig = (value) => value === "null" ? null : value === "[]" ? [] : value === "{}" ? {} : /^(true|false)$/.test(value) ? value === "true" : /^-?\d+(\.\d+)?$/.test(value) ? Number(value) : value;
|
|
283
|
-
export const defaultConfig = () => `schema: 1\nstorage:\n mode: hybrid\n root: .work-context\n personal_root: .work-context/local\ntitle:\n issue_prefix: short\ntracker:\n provider: null\n`;
|
|
303
|
+
export const defaultConfig = () => `schema: 1\nstorage:\n mode: hybrid\n root: .work-context\n personal_root: .work-context/local\ntitle:\n issue_prefix: short\ntracker:\n provider: null\nnotifications:\n desktop: true\n`;
|
package/src/tool-definitions.js
CHANGED
|
@@ -53,6 +53,7 @@ export const work_context_list_workspaces = tool({ description: "List work-conte
|
|
|
53
53
|
export const work_context_workspace_list = tool({ description: "List a workspace with stage descriptions and sessions.", args: { workspace: tool.schema.string() }, execute: run((ctx, a) => ctx.listStages(a.workspace)) });
|
|
54
54
|
export const work_context_rename_workspace = tool({ description: "Rename a workspace.", args: { workspace: tool.schema.string(), title: tool.schema.string() }, execute: run((ctx, a) => ctx.renameWorkspace(a.workspace, a.title)) });
|
|
55
55
|
export const work_context_workspace_finish = tool({ description: "Finish a workspace after all stages are completed.", args: { workspace: tool.schema.string() }, execute: run((ctx, a) => ctx.finishWorkspace(a.workspace)) });
|
|
56
|
+
export const work_context_reopen_workspace = tool({ description: "Reopen a completed workspace with a required reason and durable history.", args: { workspace: tool.schema.string(), reason: tool.schema.string() }, execute: run((ctx, a) => ctx.reopenWorkspace(a.workspace, a.reason)) });
|
|
56
57
|
export const work_context_create_workspace = tool({ description: "Create a workspace; enter its planning stage only when the current OpenCode session is not associated with a workspace.", args: { title: tool.schema.string() }, execute: run((ctx, a, oc) => {
|
|
57
58
|
const currentSession = ctx.sessionByOpenCodeId(oc.sessionID);
|
|
58
59
|
return ctx.createWorkspace(a.title, { sessionId: randomUUID(), ...(currentSession ? {} : { opencodeSessionId: oc.sessionID }) });
|
|
@@ -65,6 +66,7 @@ export const work_context_update_stage_prompt = tool({ description: "Update the
|
|
|
65
66
|
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); }) });
|
|
66
67
|
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)); }) });
|
|
67
68
|
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)) });
|
|
69
|
+
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)) });
|
|
68
70
|
export const work_context_link_issue = tool({ description: "Link a GitLab issue URL to workspace or stage.", args: { workspace: tool.schema.string(), url: tool.schema.string(), stage: tool.schema.string().optional() }, execute: run((ctx, a) => ctx.linkIssue(a.workspace, a.url, a.stage)) });
|
|
69
71
|
export const work_context_rename_session = tool({ description: "Rename the current active session summary; workspace and stage can be omitted in the current OpenCode session.", args: { ...contextualStage, summary: tool.schema.string() }, execute: run((ctx, a, oc) => { const workspace = workspaceFromSession(ctx, a.workspace); const stage = stageFromSession(ctx, workspace, a.stage); return ctx.renameSession(workspace, stage, sessionFor(ctx, oc, workspace, stage), a.summary); }) });
|
|
70
72
|
export const work_context_close_session = tool({ description: "Close the current session without finishing its stage; workspace and stage can be omitted in the current OpenCode session.", args: { ...contextualStage }, execute: run((ctx, a, oc) => { const workspace = workspaceFromSession(ctx, a.workspace); const stage = stageFromSession(ctx, workspace, a.stage); return ctx.closeSession(workspace, stage, sessionFor(ctx, oc, workspace, stage)); }) });
|
|
@@ -78,4 +80,4 @@ export const work_context_add_knowledge = tool({ description: "Add a durable kno
|
|
|
78
80
|
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)) });
|
|
79
81
|
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) ) });
|
|
80
82
|
|
|
81
|
-
export default { work_context_list_workspaces, work_context_workspace_list, work_context_rename_workspace, work_context_workspace_finish, work_context_create_workspace, work_context_start_session, work_context_add_stage, work_context_rename_stage, work_context_update_stage, work_context_update_stage_prompt, work_context_update_stage_result, work_context_archive_stage, work_context_reopen_stage, work_context_link_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 };
|
|
83
|
+
export default { work_context_list_workspaces, work_context_workspace_list, work_context_rename_workspace, work_context_workspace_finish, work_context_reopen_workspace, work_context_create_workspace, work_context_start_session, work_context_add_stage, work_context_rename_stage, work_context_update_stage, work_context_update_stage_prompt, work_context_update_stage_result, work_context_archive_stage, work_context_reopen_stage, work_context_restore_stage, work_context_link_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 };
|