opencode-work-context 0.4.14 → 0.4.15
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/package.json
CHANGED
|
@@ -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/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) {
|