opencode-work-context 0.4.14 → 0.4.16
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 +4 -4
- package/commands/wc.md +2 -0
- package/package.json +1 -1
- package/plugin/stages-tui.js +38 -4
- package/plugin/work-context-modal.js +2 -68
- package/plugin/work-context.js +2 -1
- package/src/core.js +20 -2
- package/src/opencode-adapter.js +7 -2
- package/src/stages-snapshot.js +1 -0
- package/src/storage.js +1 -1
- package/src/title.js +12 -3
- package/src/tool-definitions.js +4 -2
- package/src/work-context-snapshot.js +1 -0
- package/tools/work_context_unlink_issue.js +2 -0
package/README.md
CHANGED
|
@@ -367,10 +367,10 @@ Tools are registered by the installed server export and are not copied into the
|
|
|
367
367
|
project. Core and storage remain in the installed package; projects should not
|
|
368
368
|
copy `src/` or `tools/`. `.work-context` Markdown, JSONL, `INDEX.md`, and
|
|
369
369
|
`SESSIONS.md` are generated projections and must never be edited manually.
|
|
370
|
-
Tracker links support GitLab issues (`/-/issues/<number>`)
|
|
371
|
-
(
|
|
372
|
-
references only; the plugin does not
|
|
373
|
-
metadata.
|
|
370
|
+
Tracker links support GitLab issues (`/-/issues/<number>`) and work items
|
|
371
|
+
(`/-/work_items/<number>`), GitHub issues (`/issues/<number>`), and Jira issues
|
|
372
|
+
(`/browse/KEY-123`). They are URL-based references only; the plugin does not
|
|
373
|
+
call provider APIs or synchronize issue metadata.
|
|
374
374
|
Knowledge operations are explicit: list, add, update, and supersede. Finishing a
|
|
375
375
|
stage always validates the Knowledge Base and reports its total and active entry
|
|
376
376
|
counts. Before finishing, persist new durable findings, update changed entries,
|
package/commands/wc.md
CHANGED
|
@@ -34,6 +34,7 @@ Use these exact tool mappings; do not invent shortened tool names:
|
|
|
34
34
|
- `stage handoff [<workspace>] [<stage>]` -> `work_context_handoff_stage`
|
|
35
35
|
- `stage abandon [<workspace>] [<stage>]` -> `work_context_abandon_stage`
|
|
36
36
|
- `stage finish [<workspace>] [<stage>]` -> `work_context_finish_stage`
|
|
37
|
+
- `<workspace> [<stage>] unlink-issue <URL>` -> `work_context_unlink_issue`
|
|
37
38
|
|
|
38
39
|
Supported syntax:
|
|
39
40
|
|
|
@@ -58,6 +59,7 @@ Supported syntax:
|
|
|
58
59
|
- `stage abandon [<workspace>] [<stage>]`
|
|
59
60
|
- `stage finish [<workspace>] [<stage>]`
|
|
60
61
|
- `<workspace> [<stage>] link-issue <URL>`
|
|
62
|
+
- `<workspace> [<stage>] unlink-issue <URL>`
|
|
61
63
|
- `session rename "summary"`
|
|
62
64
|
- `stage handoff [<workspace>] <stage>`
|
|
63
65
|
- `stage abandon [<workspace>] <stage>`
|
package/package.json
CHANGED
package/plugin/stages-tui.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { readStagesSnapshot } from "../src/stages-snapshot.js";
|
|
4
|
+
import { contextFor, titleFor } from "../src/opencode-adapter.js";
|
|
4
5
|
import { renderDependencyTree, renderStagesPanel } from "../src/stages-renderer.js";
|
|
5
6
|
import { jsx } from "@opentui/solid/jsx-runtime";
|
|
6
7
|
import { createSignal } from "solid-js";
|
|
@@ -26,6 +27,12 @@ const statusMarker = (status) => ({
|
|
|
26
27
|
cancelled: "[!]",
|
|
27
28
|
archived: "[-]",
|
|
28
29
|
}[status] || "[?]");
|
|
30
|
+
const trackerLinkText = (link) => {
|
|
31
|
+
const identifier = link.key || link.iid;
|
|
32
|
+
if (link.provider === "gitlab") return `GL#${identifier}`;
|
|
33
|
+
if (link.provider === "github") return `GH#${identifier}`;
|
|
34
|
+
return `JIRA ${identifier}`;
|
|
35
|
+
};
|
|
29
36
|
|
|
30
37
|
export { readStagesSnapshot, renderStagesPanel };
|
|
31
38
|
|
|
@@ -56,7 +63,16 @@ const renderStagesContent = (result, theme, runtime = defaultRuntime, attention,
|
|
|
56
63
|
}),
|
|
57
64
|
...result.data.stages.map((stage) => {
|
|
58
65
|
const unread = attention?.attentionForStage?.(result.data.workspace.id, stage.id);
|
|
59
|
-
const
|
|
66
|
+
const metadata = showDependencies ? [
|
|
67
|
+
stage.tracker_links?.length && `Tasks: ${stage.tracker_links.map(trackerLinkText).join(", ")}`,
|
|
68
|
+
stage.depends_on?.length && `Deps: ${stage.depends_on.join(", ")}`,
|
|
69
|
+
].filter(Boolean).join(" · ") : "";
|
|
70
|
+
const attentionText = unread ? `[ATTN: ${attentionReasonText(unread.reason)}${unread.count > 1 ? ` x${unread.count}` : ""}]` : "";
|
|
71
|
+
const stageText = [
|
|
72
|
+
`${stage.id}. ${stage.title}`,
|
|
73
|
+
metadata,
|
|
74
|
+
attentionText,
|
|
75
|
+
].filter(Boolean).join("\n");
|
|
60
76
|
return runtime.jsx("box", {
|
|
61
77
|
flexDirection: "row",
|
|
62
78
|
onMouseDown: (event) => {
|
|
@@ -227,7 +243,21 @@ const renderStagesSlot = (controller, theme, sessionId, runtime = defaultRuntime
|
|
|
227
243
|
children: renderStagesElement(() => controller.resultFor(sessionId), theme, runtime, attention, controller.showDependencies, onStageSelect),
|
|
228
244
|
});
|
|
229
245
|
|
|
230
|
-
const
|
|
246
|
+
const updateSessionTitle = async (api, projectRoot) => {
|
|
247
|
+
const sessionId = api?.route?.current?.params?.sessionID
|
|
248
|
+
|| api?.route?.current?.params?.sessionId
|
|
249
|
+
|| api?.route?.current?.params?.session_id;
|
|
250
|
+
if (!sessionId || typeof api?.client?.session?.update !== "function") return;
|
|
251
|
+
try {
|
|
252
|
+
const context = contextFor(projectRoot, sessionId);
|
|
253
|
+
const session = context.sessionById(sessionId) || context.sessionByOpenCodeId(sessionId, null, null, null);
|
|
254
|
+
if (!session) return;
|
|
255
|
+
const title = titleFor(context, session.workspace, session.stage, sessionId, session, readTuiState(projectRoot).sidebar_dependencies === true);
|
|
256
|
+
await api.client.session.update({ path: { id: sessionId }, query: { directory: projectRoot }, body: { title } });
|
|
257
|
+
} catch {}
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
const registerDependencyToggle = (api, controller, projectRoot) => {
|
|
231
261
|
if (typeof api?.keymap?.registerLayer !== "function") return () => {};
|
|
232
262
|
const command = {
|
|
233
263
|
name: DEPENDENCIES_COMMAND,
|
|
@@ -235,7 +265,11 @@ const registerDependencyToggle = (api, controller) => {
|
|
|
235
265
|
desc: "Show or hide dependency IDs in the stages sidebar",
|
|
236
266
|
category: "Work Context",
|
|
237
267
|
namespace: "palette",
|
|
238
|
-
run: () =>
|
|
268
|
+
run: () => {
|
|
269
|
+
const visible = controller.toggleDependencies();
|
|
270
|
+
void updateSessionTitle(api, projectRoot);
|
|
271
|
+
return visible;
|
|
272
|
+
},
|
|
239
273
|
};
|
|
240
274
|
return api.keymap.registerLayer({
|
|
241
275
|
commands: [command],
|
|
@@ -312,7 +346,7 @@ export const tui = async (api, options = {}) => {
|
|
|
312
346
|
attention: api.workContextAttention,
|
|
313
347
|
});
|
|
314
348
|
const stageSwitcher = createStageSwitcherFlow(api);
|
|
315
|
-
const unregisterDependencyToggle = registerDependencyToggle(api, controller);
|
|
349
|
+
const unregisterDependencyToggle = registerDependencyToggle(api, controller, projectRoot);
|
|
316
350
|
let currentSessionId = initialSessionId;
|
|
317
351
|
const unregisterDependencyTree = registerDependencyTree(api, controller, () => currentSessionId || ACTIVE_WORKSPACE_SESSION);
|
|
318
352
|
await controller.load(initialSessionId);
|
|
@@ -4,8 +4,7 @@ import { readWorkContextSnapshot } from "../src/work-context-snapshot.js";
|
|
|
4
4
|
import { normalizeStageId, normalizeWorkspaceId } from "../src/identifiers.js";
|
|
5
5
|
import { jsx } from "@opentui/solid/jsx-runtime";
|
|
6
6
|
import { createSignal } from "solid-js";
|
|
7
|
-
import {
|
|
8
|
-
import { openStageSwitcher, startStageSession } from "./stage-switcher.js";
|
|
7
|
+
import { openStageSwitcher } from "./stage-switcher.js";
|
|
9
8
|
import { openWorkspaceSwitcher } from "./workspace-switcher.js";
|
|
10
9
|
import { openSessionSwitcher } from "./session-switcher.js";
|
|
11
10
|
import { attentionForSession, attentionReasonText } from "./attention.js";
|
|
@@ -16,8 +15,6 @@ const SHORTCUT = "<leader>w";
|
|
|
16
15
|
const STAGE_SHORTCUT = "<leader>s";
|
|
17
16
|
const WORKSPACE_SHORTCUT = "<leader>o";
|
|
18
17
|
const SESSION_SHORTCUT = "<leader>e";
|
|
19
|
-
const CREATE_STAGE_COMMAND = "work_context.create_stage";
|
|
20
|
-
const CREATE_STAGE_SHORTCUT = "<leader>a";
|
|
21
18
|
const DEBOUNCE_MS = 150;
|
|
22
19
|
const POLL_MS = 1000;
|
|
23
20
|
const MARKERS = { planned: "[ ]", in_progress: "[•]", completed: "[✓]", cancelled: "[!]" };
|
|
@@ -566,67 +563,6 @@ export const openWorkContextActionDialog = (api, runtime = {}, options = {}) =>
|
|
|
566
563
|
return true;
|
|
567
564
|
};
|
|
568
565
|
|
|
569
|
-
const currentSessionId = (api) => api?.route?.current?.params?.sessionID || api?.route?.current?.params?.sessionId;
|
|
570
|
-
const projectRoot = (api) => api?.state?.path?.worktree || api?.state?.path?.directory;
|
|
571
|
-
|
|
572
|
-
/** Create a planned stage directly, without routing the request through a chat command. */
|
|
573
|
-
export const addStageForCurrentWorkspace = (api, title, { readContext = contextFor } = {}) => {
|
|
574
|
-
if (!title?.trim()) return { ok: false, error: { code: "INVALID_ARGUMENT", message: "Title is required" } };
|
|
575
|
-
const root = projectRoot(api);
|
|
576
|
-
const sessionId = currentSessionId(api);
|
|
577
|
-
if (!root || !sessionId) return { ok: false, error: { code: "STAGE_CONTEXT_REQUIRED", message: "The current session is not associated with a work-context stage" } };
|
|
578
|
-
try {
|
|
579
|
-
const context = readContext(root, sessionId, "OpenCode TUI");
|
|
580
|
-
const current = context.sessionByOpenCodeId(sessionId, null, null, null) || context.sessionById(sessionId);
|
|
581
|
-
if (!current) return { ok: false, error: { code: "STAGE_CONTEXT_REQUIRED", message: "The current session is not associated with a work-context stage" } };
|
|
582
|
-
return context.addStage(current.workspace, title.trim());
|
|
583
|
-
} catch (error) {
|
|
584
|
-
return { ok: false, error: { code: error.code || "STORAGE_ERROR", message: error.message || "Could not create the stage" } };
|
|
585
|
-
}
|
|
586
|
-
};
|
|
587
|
-
|
|
588
|
-
export const openCreateStageDialog = (api, options = {}) => {
|
|
589
|
-
if (typeof api?.ui?.DialogPrompt !== "function" || typeof api?.ui?.DialogSelect !== "function" || typeof api?.ui?.dialog?.replace !== "function") return false;
|
|
590
|
-
const create = async (title, open) => {
|
|
591
|
-
const result = addStageForCurrentWorkspace(api, title, options);
|
|
592
|
-
if (!result.ok) {
|
|
593
|
-
api.ui?.toast?.({ message: `${result.error.code}: ${result.error.message}`, variant: "error" });
|
|
594
|
-
openCreateStageDialog(api, options);
|
|
595
|
-
return;
|
|
596
|
-
}
|
|
597
|
-
if (open) {
|
|
598
|
-
const started = await startStageSession(api, {
|
|
599
|
-
workspace: result.data.workspace,
|
|
600
|
-
stage: result.data.stage,
|
|
601
|
-
title: title.trim(),
|
|
602
|
-
});
|
|
603
|
-
if (!started.ok) {
|
|
604
|
-
api.ui?.toast?.({ message: `${started.error.code}: ${started.error.message}`, variant: "error" });
|
|
605
|
-
return;
|
|
606
|
-
}
|
|
607
|
-
}
|
|
608
|
-
api.ui.dialog.clear?.();
|
|
609
|
-
api.ui?.toast?.({ message: open ? `Stage ${result.data.stage} created and opened` : `Stage ${result.data.stage} created`, variant: "success" });
|
|
610
|
-
};
|
|
611
|
-
api.ui.dialog.replace(() => api.ui.DialogPrompt({
|
|
612
|
-
title: "Create stage",
|
|
613
|
-
placeholder: "Stage title",
|
|
614
|
-
onConfirm: (title) => {
|
|
615
|
-
if (!title?.trim()) { openCreateStageDialog(api, options); return; }
|
|
616
|
-
api.ui.dialog.replace(() => api.ui.DialogSelect({
|
|
617
|
-
title: "Create stage",
|
|
618
|
-
placeholder: "Choose what happens next",
|
|
619
|
-
options: [
|
|
620
|
-
{ title: "Create stage", description: "Keep working in the current stage", value: false },
|
|
621
|
-
{ title: "Create and open stage", description: "Start the new stage in a new session", value: true },
|
|
622
|
-
],
|
|
623
|
-
onSelect: (option) => void create(title, option.value),
|
|
624
|
-
}));
|
|
625
|
-
},
|
|
626
|
-
}));
|
|
627
|
-
return true;
|
|
628
|
-
};
|
|
629
|
-
|
|
630
566
|
export const openCompatibilityDialog = (api, runtime = {}, options = {}) => {
|
|
631
567
|
const stack = api?.ui?.dialog;
|
|
632
568
|
if (!stack || typeof runtime.jsx !== "function" || typeof stack.replace !== "function") return false;
|
|
@@ -655,16 +591,14 @@ export const registerWorkContextModal = (api, runtime = {}) => {
|
|
|
655
591
|
const stageCommand = { name: "work_context.stage", title: "Switch Work Context Stage", desc: "Open a stage session in the current workspace", category: "Work Context", namespace: "palette", run: () => openStageSwitcher(api) };
|
|
656
592
|
const workspaceCommand = { name: "work_context.workspace", title: "Switch Work Context Workspace", desc: "Open a workspace session", category: "Work Context", namespace: "palette", run: () => openWorkspaceSwitcher(api) };
|
|
657
593
|
const sessionCommand = { name: "work_context.session", title: "Switch Work Context Session", desc: "Open an active or historical work session", category: "Work Context", namespace: "palette", run: () => openSessionSwitcher(api) };
|
|
658
|
-
const createStageCommand = { name: CREATE_STAGE_COMMAND, title: "Create Work Context Stage", desc: "Create a stage in the current workspace", category: "Work Context", namespace: "palette", run: () => openCreateStageDialog(api) };
|
|
659
594
|
const actions = { name: ACTIONS_COMMAND_NAME, title: "Open Work Context Actions", desc: "Prepare a work-context command", category: "Work Context", namespace: "palette", run: () => openWorkContextActionDialog(api, runtime) };
|
|
660
595
|
const registration = api.keymap.registerLayer({
|
|
661
|
-
commands: [command, stageCommand, workspaceCommand, sessionCommand,
|
|
596
|
+
commands: [command, stageCommand, workspaceCommand, sessionCommand, actions],
|
|
662
597
|
bindings: [
|
|
663
598
|
{ key: SHORTCUT, cmd: COMMAND_NAME, desc: command.title },
|
|
664
599
|
{ key: STAGE_SHORTCUT, cmd: stageCommand.name, desc: stageCommand.title },
|
|
665
600
|
{ key: WORKSPACE_SHORTCUT, cmd: workspaceCommand.name, desc: workspaceCommand.title },
|
|
666
601
|
{ key: SESSION_SHORTCUT, cmd: sessionCommand.name, desc: sessionCommand.title },
|
|
667
|
-
{ key: CREATE_STAGE_SHORTCUT, cmd: createStageCommand.name, desc: createStageCommand.title },
|
|
668
602
|
],
|
|
669
603
|
});
|
|
670
604
|
return { supported: true, dispose: () => disposeRegistration(registration) };
|
package/plugin/work-context.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import tools from "../src/tool-definitions.js";
|
|
2
2
|
import { contextFor, titleFor } from "../src/opencode-adapter.js";
|
|
3
|
+
import { readTuiState } from "./tui-state.js";
|
|
3
4
|
|
|
4
5
|
export default async ({ client, directory, worktree }) => ({
|
|
5
6
|
tool: tools,
|
|
@@ -25,7 +26,7 @@ async function updateSessionTitle(client, projectRoot, directory, sessionId) {
|
|
|
25
26
|
const context = contextFor(projectRoot, sessionId);
|
|
26
27
|
const session = context.sessionById(sessionId) || context.sessionByOpenCodeId(sessionId, null, null, null);
|
|
27
28
|
if (!session) return;
|
|
28
|
-
const title = titleFor(context, session.workspace, session.stage, sessionId, session);
|
|
29
|
+
const title = titleFor(context, session.workspace, session.stage, sessionId, session, readTuiState(projectRoot).sidebar_dependencies === true);
|
|
29
30
|
if (!title) return;
|
|
30
31
|
const current = await client.session.get({ path: { id: sessionId }, query: { directory } });
|
|
31
32
|
const currentSession = current.data ?? current;
|
package/src/core.js
CHANGED
|
@@ -41,7 +41,7 @@ function parseIssue(url) {
|
|
|
41
41
|
try {
|
|
42
42
|
const parsed = new URL(url);
|
|
43
43
|
if (!/^https?:$/.test(parsed.protocol)) fail(ERROR_CODES.INVALID_ISSUE_URL, "Expected a supported tracker issue URL");
|
|
44
|
-
let match = parsed.pathname.match(/^\/(.+)\/-\/issues\/(\d+)\/?$/);
|
|
44
|
+
let match = parsed.pathname.match(/^\/(.+)\/-\/(?:issues|work_items)\/(\d+)\/?$/);
|
|
45
45
|
if (match) return { url: parsed.toString(), provider: "gitlab", project: match[1], iid: Number(match[2]) };
|
|
46
46
|
match = parsed.pathname.match(/^\/([^/]+\/[^/]+)\/issues\/(\d+)\/?$/);
|
|
47
47
|
if (match) return { url: parsed.toString(), provider: "github", project: match[1], iid: Number(match[2]) };
|
|
@@ -522,6 +522,24 @@ export class WorkContext {
|
|
|
522
522
|
});
|
|
523
523
|
}
|
|
524
524
|
|
|
525
|
+
unlinkIssue(workspace, url, stage = null) {
|
|
526
|
+
const normalizedWorkspace = normalizeWorkspaceId(workspace);
|
|
527
|
+
const normalizedStage = stage === null || stage === undefined ? null : normalizeStageId(stage);
|
|
528
|
+
const parsed = parseIssue(url);
|
|
529
|
+
return this.transact(`link-${normalizedWorkspace}-${normalizedStage || "workspace"}`, () => {
|
|
530
|
+
const file = normalizedStage ? this.storage.stageFile(normalizedWorkspace, normalizedStage) : this.storage.workspaceFile(normalizedWorkspace);
|
|
531
|
+
const current = normalizedStage ? this.storage.readStage(normalizedWorkspace, normalizedStage) : this.storage.readWorkspace(normalizedWorkspace);
|
|
532
|
+
const links = current.data.tracker_links || [];
|
|
533
|
+
const remaining = links.filter((link) => link.url !== parsed.url);
|
|
534
|
+
if (remaining.length === links.length) return this.result({ workspace: normalizedWorkspace, stage: normalizedStage, issue: parsed }, []);
|
|
535
|
+
current.data.tracker_links = remaining;
|
|
536
|
+
current.data.updated_at = new Date().toISOString();
|
|
537
|
+
this.storage.writeMarkdown(file, current.data, current.body);
|
|
538
|
+
generateProjections(this.storage);
|
|
539
|
+
return this.result({ workspace: normalizedWorkspace, stage: normalizedStage, issue: parsed }, [file]);
|
|
540
|
+
});
|
|
541
|
+
}
|
|
542
|
+
|
|
525
543
|
renameSession(workspace, stage, sessionId, summary) {
|
|
526
544
|
if (!summary?.trim()) fail(ERROR_CODES.INVALID_ARGUMENT, "Summary is required");
|
|
527
545
|
workspace = normalizeWorkspaceId(workspace);
|
|
@@ -650,7 +668,7 @@ export class WorkContext {
|
|
|
650
668
|
help(command = "") {
|
|
651
669
|
return this.result({
|
|
652
670
|
command,
|
|
653
|
-
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]",
|
|
671
|
+
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|unlink-issue|session rename|knowledge list|knowledge add|knowledge update|knowledge supersede|help]",
|
|
654
672
|
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.",
|
|
655
673
|
}, []);
|
|
656
674
|
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." }, []);
|
package/src/opencode-adapter.js
CHANGED
|
@@ -7,11 +7,16 @@ export { readStagesSnapshot } from "./stages-snapshot.js";
|
|
|
7
7
|
export function contextFor(directory, sessionId, actor = "OpenCode") {
|
|
8
8
|
return WorkContext.openExisting(directory, { sessionId, actor });
|
|
9
9
|
}
|
|
10
|
-
export function titleFor(context, workspace, stage, sessionId, knownSession = null) {
|
|
10
|
+
export function titleFor(context, workspace, stage, sessionId, knownSession = null, includeStageTrackerLinks = false) {
|
|
11
11
|
const current = knownSession || context.sessionById(sessionId);
|
|
12
12
|
if (!current) return null;
|
|
13
13
|
const meta = context.storage.readWorkspace(workspace).data;
|
|
14
14
|
const stageMeta = context.storage.readStage(workspace, stage).data;
|
|
15
|
-
|
|
15
|
+
const workspaceLinks = meta.tracker_links || [];
|
|
16
|
+
const primaryTrackerLinks = stageMeta.tracker_links?.length ? stageMeta.tracker_links : workspaceLinks;
|
|
17
|
+
const stageTrackerLinks = includeStageTrackerLinks
|
|
18
|
+
? context.listStages(workspace).data.stages.flatMap((item) => item.tracker_links || []).filter((link) => !workspaceLinks.some((workspaceLink) => workspaceLink.url === link.url) && !primaryTrackerLinks.some((primaryLink) => primaryLink.url === link.url))
|
|
19
|
+
: [];
|
|
20
|
+
return renderTitle({ workspace, stageTitle: stageMeta.title, stage, ordinal: current.ordinal, state: current.state, trackerLinks: primaryTrackerLinks, stageTrackerLinks, issuePrefix: context.storage.config.title?.issue_prefix || "short" });
|
|
16
21
|
}
|
|
17
22
|
export const packageRoot = () => path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
package/src/stages-snapshot.js
CHANGED
|
@@ -43,6 +43,7 @@ export function readStagesSnapshot({ projectRoot, sessionId }) {
|
|
|
43
43
|
status: stage.status,
|
|
44
44
|
description: stage.description,
|
|
45
45
|
depends_on: stage.depends_on,
|
|
46
|
+
tracker_links: stage.tracker_links || [],
|
|
46
47
|
current: stage.stage === session.stage,
|
|
47
48
|
}));
|
|
48
49
|
const currentStage = stages.some((stage) => stage.current) ? session.stage : null;
|
package/src/storage.js
CHANGED
|
@@ -19,7 +19,7 @@ const validTrackerLinks = (links) => links.every((link) => {
|
|
|
19
19
|
if (url.protocol !== "http:" && url.protocol !== "https:") return false;
|
|
20
20
|
if (link.provider === "gitlab" || link.provider === "github") {
|
|
21
21
|
const allowed = ["url", "provider", "project", "iid"];
|
|
22
|
-
const match = url.pathname.match(link.provider === "gitlab" ? /^\/(.+)\/-\/issues\/(\d+)\/?$/ : /^\/([^/]+\/[^/]+)\/issues\/(\d+)\/?$/);
|
|
22
|
+
const match = url.pathname.match(link.provider === "gitlab" ? /^\/(.+)\/-\/(?:issues|work_items)\/(\d+)\/?$/ : /^\/([^/]+\/[^/]+)\/issues\/(\d+)\/?$/);
|
|
23
23
|
return Object.keys(link).every((key) => allowed.includes(key)) && Object.keys(link).length === allowed.length && match && match[1] === link.project && Number(match[2]) === link.iid && Number.isInteger(link.iid) && link.iid > 0;
|
|
24
24
|
}
|
|
25
25
|
if (link.provider === "jira") {
|
package/src/title.js
CHANGED
|
@@ -1,11 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
const trackerLinkText = (link) => {
|
|
2
|
+
const identifier = link.key || link.iid;
|
|
3
|
+
if ((link.provider || "gitlab") === "gitlab") return `GL#${identifier}`;
|
|
4
|
+
if (link.provider === "github") return `GH#${identifier}`;
|
|
5
|
+
return `JIRA ${identifier}`;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export function renderTitle({ workspace, stageTitle, stage, ordinal, state = "active", trackerLinks = [], stageTrackerLinks = [], issuePrefix = "short" }) {
|
|
2
9
|
const link = trackerLinks[0]; let prefix = "";
|
|
3
10
|
if (link && issuePrefix !== "none") {
|
|
4
11
|
const identifier = link.key || link.iid;
|
|
5
|
-
const short = (link
|
|
12
|
+
const short = trackerLinkText(link);
|
|
6
13
|
prefix = issuePrefix === "full" ? `${link.project}#${identifier} | ` : `${short} | `;
|
|
7
14
|
}
|
|
8
15
|
const suffix = state === "active" ? "" : ` (${state})`;
|
|
9
16
|
const description = (stageTitle || stage).replace(/[\r\n|]+/g, " ").trim().slice(0, 80);
|
|
10
|
-
|
|
17
|
+
const taskLinks = [...new Map(stageTrackerLinks.map((item) => [item.url, item])).values()];
|
|
18
|
+
const tasks = taskLinks.length ? `\nTasks: ${taskLinks.map(trackerLinkText).join(", ")}` : "";
|
|
19
|
+
return `${description}\n${prefix}${workspace} ${stage}/${String(ordinal).padStart(2, "0")}${suffix}${tasks}`;
|
|
11
20
|
}
|
package/src/tool-definitions.js
CHANGED
|
@@ -9,7 +9,8 @@ const tool = Object.assign((definition) => definition, { schema: z });
|
|
|
9
9
|
|
|
10
10
|
const run = (fn) => async (args, context) => {
|
|
11
11
|
try {
|
|
12
|
-
const
|
|
12
|
+
const projectRoot = context.worktree === "/" ? context.directory : (context.worktree || context.directory);
|
|
13
|
+
const result = await fn(contextFor(projectRoot, context.sessionID), args, context);
|
|
13
14
|
try { await context.metadata({ title: "work-context", metadata: { result } }); } catch {}
|
|
14
15
|
return { output: JSON.stringify(result), metadata: result };
|
|
15
16
|
} catch (error) {
|
|
@@ -71,6 +72,7 @@ export const work_context_archive_stage = tool({ description: "Archive a stage w
|
|
|
71
72
|
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)) });
|
|
72
73
|
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)) });
|
|
73
74
|
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)) });
|
|
75
|
+
export const work_context_unlink_issue = tool({ description: "Remove a tracker issue URL from a workspace or stage.", args: { workspace: tool.schema.string(), url: tool.schema.string(), stage: tool.schema.string().optional() }, execute: run((ctx, a) => ctx.unlinkIssue(a.workspace, a.url, a.stage)) });
|
|
74
76
|
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); }) });
|
|
75
77
|
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)); }) });
|
|
76
78
|
export const work_context_force_close_session = tool({ description: "Force close a stale active session with an explicit reason and confirmation.", args: { workspace: tool.schema.string(), stage: tool.schema.string(), sessionId: tool.schema.string(), reason: tool.schema.string(), confirmation: tool.schema.string() }, execute: run((ctx, a) => ctx.forceCloseSession(a.workspace, a.stage, a.sessionId, a.reason, a.confirmation)) });
|
|
@@ -83,4 +85,4 @@ export const work_context_add_knowledge = tool({ description: "Add a durable kno
|
|
|
83
85
|
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)) });
|
|
84
86
|
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) ) });
|
|
85
87
|
|
|
86
|
-
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 };
|
|
88
|
+
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_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 };
|
|
@@ -44,6 +44,7 @@ const readWorkspace = (context, record, currentSession) => {
|
|
|
44
44
|
status: stage.status,
|
|
45
45
|
description: stage.description,
|
|
46
46
|
depends_on: stage.depends_on,
|
|
47
|
+
tracker_links: stage.tracker_links || [],
|
|
47
48
|
current: stage.stage === currentStage,
|
|
48
49
|
})),
|
|
49
50
|
currentStage,
|