opencode-work-context 0.8.0 → 0.10.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 +131 -4
- package/commands/wc.md +32 -4
- package/package.json +1 -1
- package/plugin/stages-tui.js +54 -20
- package/plugin/work-context-modal.js +2 -0
- package/src/candidates.js +60 -5
- package/src/capability-profiles.js +78 -0
- package/src/core.js +175 -9
- package/src/delivery.js +135 -0
- package/src/errors.js +1 -0
- package/src/git-candidates.js +44 -1
- package/src/index.js +2 -0
- package/src/stages-renderer.js +47 -2
- package/src/stages-snapshot.js +15 -5
- package/src/storage.js +13 -4
- package/src/tool-definitions.js +12 -3
- package/src/work-context-snapshot.js +19 -8
- package/tools/work_context_configure_capability_profiles.js +2 -0
- package/tools/work_context_mark_delivery.js +3 -0
- package/tools/work_context_read_delivery.js +3 -0
- package/tools/work_context_refresh_stage_profiles.js +2 -0
- package/tools/work_context_reset_capability_profiles.js +2 -0
- package/tools/work_context_set_stage_profiles.js +2 -0
- package/tools/work_context_show_capability_profiles.js +2 -0
package/src/storage.js
CHANGED
|
@@ -4,6 +4,7 @@ import { randomUUID } from "node:crypto";
|
|
|
4
4
|
import { WorkContextError, ERROR_CODES, fail } from "./errors.js";
|
|
5
5
|
import { parseFrontmatter, renderMarkdown } from "./markdown.js";
|
|
6
6
|
import { validateExecutionRecord } from "./stage-execution.js";
|
|
7
|
+
import { CAPABILITY_CLASSIFICATIONS, CAPABILITY_DEPTHS, CAPABILITY_PROFILES } from "./capability-profiles.js";
|
|
7
8
|
|
|
8
9
|
const now = () => new Date().toISOString();
|
|
9
10
|
const ensure = (dir) => fs.mkdirSync(dir, { recursive: true });
|
|
@@ -89,7 +90,7 @@ const validateEventStream = (events) => {
|
|
|
89
90
|
}
|
|
90
91
|
};
|
|
91
92
|
function validateMetadata(data, kind, workspace, stage = null) {
|
|
92
|
-
const allowed = kind === "workspace" ? ["schema", "workspace", "title", "status", "mode", "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"];
|
|
93
|
+
const allowed = kind === "workspace" ? ["schema", "workspace", "title", "status", "mode", "created_at", "updated_at", "tracker_links", "reopen_history"] : ["schema", "workspace", "stage", "title", "status", "goal", "prompt", "depends_on", "owner", "execution_profile", "execution_depth", "execution_classification", "review_profile", "created_at", "updated_at", "tracker_links", "reopen_history", "archive_history"];
|
|
93
94
|
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`);
|
|
94
95
|
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`);
|
|
95
96
|
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`);
|
|
@@ -103,6 +104,13 @@ function validateMetadata(data, kind, workspace, stage = null) {
|
|
|
103
104
|
|| data.depends_on.includes(data.stage) || data.depends_on.some((item) => typeof item !== "string" || !/^\d{2}$/.test(item))
|
|
104
105
|
|| (data.reopen_history !== undefined && !validReopenHistory(data.reopen_history))
|
|
105
106
|
|| (data.archive_history !== undefined && !validArchiveHistory(data.archive_history))
|
|
107
|
+
|| (data.execution_profile !== undefined && !CAPABILITY_PROFILES.includes(data.execution_profile))
|
|
108
|
+
|| (data.execution_depth !== undefined && !CAPABILITY_DEPTHS.includes(data.execution_depth))
|
|
109
|
+
|| (data.execution_classification !== undefined && !CAPABILITY_CLASSIFICATIONS.includes(data.execution_classification))
|
|
110
|
+
|| (data.review_profile !== undefined && !CAPABILITY_PROFILES.includes(data.review_profile))
|
|
111
|
+
|| (data.execution_depth !== undefined && data.execution_profile === undefined)
|
|
112
|
+
|| (data.execution_classification !== undefined && (data.execution_profile === undefined || data.execution_depth === undefined))
|
|
113
|
+
|| (data.execution_profile !== undefined && data.execution_depth !== undefined && data.execution_classification === undefined)
|
|
106
114
|
);
|
|
107
115
|
if (invalidWorkspaceHistory || invalidStageMetadata) fail(ERROR_CODES.STORAGE_ERROR, `Invalid ${kind} metadata`);
|
|
108
116
|
}
|
|
@@ -134,7 +142,7 @@ export class FileStorage {
|
|
|
134
142
|
constructor(projectRoot, config = {}) {
|
|
135
143
|
this.projectRoot = projectRoot;
|
|
136
144
|
const storage = config.storage || {};
|
|
137
|
-
this.config = { mode: "hybrid", root: ".work-context", personal_root: ".work-context/local", title: { issue_prefix: "short" }, tracker: { provider: null }, ...config, ...storage, title: { issue_prefix: "short", ...(config.title || {}) }, tracker: { provider: null, ...(config.tracker || {}) } };
|
|
145
|
+
this.config = { mode: "hybrid", root: ".work-context", personal_root: ".work-context/local", title: { issue_prefix: "short" }, tracker: { provider: null }, capability_profiles: { mode: "advisory" }, ...config, ...storage, title: { issue_prefix: "short", ...(config.title || {}) }, tracker: { provider: null, ...(config.tracker || {}) }, capability_profiles: { mode: "advisory", ...(config.capability_profiles || {}) } };
|
|
138
146
|
this.root = path.resolve(projectRoot, this.config.root);
|
|
139
147
|
this.personalRoot = path.resolve(projectRoot, this.config.personal_root);
|
|
140
148
|
const project = path.resolve(projectRoot);
|
|
@@ -302,7 +310,7 @@ export class FileStorage {
|
|
|
302
310
|
|
|
303
311
|
export function loadConfig(projectRoot, configFile = path.resolve(projectRoot, ".work-context", "config.yaml")) {
|
|
304
312
|
if (!fs.existsSync(configFile)) return {};
|
|
305
|
-
const data = Object.assign(Object.create(null), { storage: Object.create(null), title: Object.create(null), tracker: Object.create(null), notifications: Object.create(null) });
|
|
313
|
+
const data = Object.assign(Object.create(null), { storage: Object.create(null), title: Object.create(null), tracker: Object.create(null), notifications: Object.create(null), capability_profiles: Object.create(null) });
|
|
306
314
|
let section = null;
|
|
307
315
|
for (const line of fs.readFileSync(configFile, "utf8").split("\n")) {
|
|
308
316
|
if (!line.trim() || line.trim().startsWith("#")) continue;
|
|
@@ -310,7 +318,8 @@ export function loadConfig(projectRoot, configFile = path.resolve(projectRoot, "
|
|
|
310
318
|
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; }
|
|
311
319
|
if (section && data[section] && typeof data[section] === "object") data[section][match[2]] = scalarConfig(match[3]);
|
|
312
320
|
}
|
|
313
|
-
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");
|
|
321
|
+
if (Object.keys(data).some((key) => !["schema", "storage", "title", "tracker", "notifications", "capability_profiles"].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.capability_profiles || typeof data.capability_profiles !== "object" || Array.isArray(data.capability_profiles) || Object.keys(data.capability_profiles).some((key) => key !== "mode") || (data.capability_profiles.mode !== undefined && !["advisory", "off"].includes(data.capability_profiles.mode)) || 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");
|
|
322
|
+
data.capability_profiles.mode ||= "advisory";
|
|
314
323
|
return data;
|
|
315
324
|
}
|
|
316
325
|
const scalarConfig = (value) => value === "null" ? null : value === "[]" ? [] : value === "{}" ? {} : /^(true|false)$/.test(value) ? value === "true" : /^-?\d+(\.\d+)?$/.test(value) ? Number(value) : value;
|
package/src/tool-definitions.js
CHANGED
|
@@ -19,6 +19,8 @@ const run = (fn) => async (args, context) => {
|
|
|
19
19
|
};
|
|
20
20
|
const common = { workspace: tool.schema.string(), stage: tool.schema.string() };
|
|
21
21
|
const contextualStage = { workspace: tool.schema.string().optional(), stage: tool.schema.string().optional() };
|
|
22
|
+
const capabilityProfile = tool.schema.enum(["routine", "implementation", "architecture", "security", "review"]);
|
|
23
|
+
const capabilityDepth = tool.schema.enum(["light", "standard", "deep"]);
|
|
22
24
|
const executionSections = {
|
|
23
25
|
scope: tool.schema.array(tool.schema.string()).optional(),
|
|
24
26
|
completed: tool.schema.array(tool.schema.string()).optional(),
|
|
@@ -48,7 +50,7 @@ const sessionFor = (ctx, oc, workspace, stage) => ctx.sessionById(oc.sessionID)?
|
|
|
48
50
|
const addStageFromTool = (ctx, args, oc) => {
|
|
49
51
|
const currentSession = sessionFromContext(ctx);
|
|
50
52
|
const workspace = workspaceFromSession(ctx, args.workspace);
|
|
51
|
-
const created = ctx.addStage(workspace, args.title, { goal: args.goal, prompt: args.prompt, dependsOn: args.dependsOn });
|
|
53
|
+
const created = ctx.addStage(workspace, args.title, { goal: args.goal, prompt: args.prompt, dependsOn: args.dependsOn, executionProfile: args.executionProfile, executionDepth: args.executionDepth, classification: args.classification, reviewProfile: args.reviewProfile });
|
|
52
54
|
if (currentSession) return created;
|
|
53
55
|
|
|
54
56
|
const started = ctx.startSession(workspace, created.data.stage, {
|
|
@@ -73,6 +75,8 @@ export const work_context_list_candidates = tool({ description: "List local comm
|
|
|
73
75
|
export const work_context_ready_candidate = tool({ description: "Mark a captured draft candidate ready for a later explicit commit operation.", args: { workspace: tool.schema.string(), candidateId: tool.schema.string() }, execute: run((ctx, a) => ctx.readyCandidate(a.workspace, a.candidateId)) });
|
|
74
76
|
export const work_context_commit_candidate = tool({ description: "Commit a ready candidate atomically without using the ordinary Git index. Uses its stored message unless message is provided.", args: { workspace: tool.schema.string(), candidateId: tool.schema.string(), message: tool.schema.string().optional() }, execute: run((ctx, a) => ctx.commitCandidate(a.workspace, a.candidateId, a.message)) });
|
|
75
77
|
export const work_context_discard_candidate = tool({ description: "Discard a local commit candidate without changing Git state.", args: { workspace: tool.schema.string(), candidateId: tool.schema.string() }, execute: run((ctx, a) => ctx.discardCandidate(a.workspace, a.candidateId)) });
|
|
78
|
+
export const work_context_read_delivery = tool({ description: "Read workspace-level delivery context. Exact Git inspection runs only when both immutable from and to commit hashes are provided.", args: { workspace: tool.schema.string(), environment: tool.schema.string().optional(), from: tool.schema.string().optional(), to: tool.schema.string().optional() }, execute: run((ctx, a) => ctx.readDelivery(a.workspace, { environment: a.environment, from: a.from, to: a.to })) });
|
|
79
|
+
export const work_context_mark_delivery = tool({ description: "Record a confirmed environment delivery checkpoint without executing deployment. Requires DELIVERY_CONFIRMED.", args: { workspace: tool.schema.string(), environment: tool.schema.string(), commit: tool.schema.string(), confirmation: tool.schema.string() }, execute: run((ctx, a) => ctx.markDelivery(a.workspace, a.environment, a.commit, a.confirmation)) });
|
|
76
80
|
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)) });
|
|
77
81
|
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)) });
|
|
78
82
|
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(), mode: tool.schema.enum(["standard", "startup"]).optional() }, execute: run((ctx, a, oc) => {
|
|
@@ -80,7 +84,12 @@ export const work_context_create_workspace = tool({ description: "Create a works
|
|
|
80
84
|
return ctx.createWorkspace(a.title, { sessionId: randomUUID(), mode: a.mode, ...(currentSession ? {} : { opencodeSessionId: oc.sessionID }) });
|
|
81
85
|
}) });
|
|
82
86
|
export const work_context_start_session = tool({ description: "Start a new active session for a stage and return its human-oriented presentation, prompt, active workspace knowledge, and startup policy when applicable.", args: { ...common, summary: tool.schema.string().optional() }, execute: run((ctx, a, oc) => ctx.startSession(a.workspace, a.stage, { sessionId: randomUUID(), opencodeSessionId: oc.sessionID, summary: a.summary, takeover: true })) });
|
|
83
|
-
export const work_context_add_stage = tool({ description: "Add a stage
|
|
87
|
+
export const work_context_add_stage = tool({ description: "Add a stage with an optional execution capability and depth. When the user did not specify them, infer both from the prompt and pass classification: inferred. Explicit user choices use classification: explicit.", args: { workspace: tool.schema.string().optional(), title: tool.schema.string(), goal: tool.schema.string().optional(), prompt: tool.schema.string().optional(), dependsOn: tool.schema.array(tool.schema.string()).optional(), executionProfile: capabilityProfile.optional(), executionDepth: capabilityDepth.optional(), classification: tool.schema.enum(["inferred", "explicit"]).optional(), reviewProfile: capabilityProfile.optional() }, execute: run(addStageFromTool) });
|
|
88
|
+
export const work_context_set_stage_profiles = tool({ description: "Explicitly set or clear a stage execution capability and depth. Omitted fields are unchanged; pass null for both execution fields to clear them. Review profile remains optional metadata.", args: { ...contextualStage, executionProfile: capabilityProfile.nullable().optional(), executionDepth: capabilityDepth.nullable().optional(), reviewProfile: capabilityProfile.nullable().optional() }, execute: run((ctx, a) => { const workspace = workspaceFromSession(ctx, a.workspace); return ctx.setStageProfiles(workspace, stageFromSession(ctx, workspace, a.stage), { ...(Object.hasOwn(a, "executionProfile") ? { executionProfile: a.executionProfile } : {}), ...(Object.hasOwn(a, "executionDepth") ? { executionDepth: a.executionDepth } : {}), ...(Object.hasOwn(a, "reviewProfile") ? { reviewProfile: a.reviewProfile } : {}) }); }) });
|
|
89
|
+
export const work_context_refresh_stage_profiles = tool({ description: "Atomically apply agent-inferred execution capability and depth recommendations. Ordinary refresh preserves explicit classifications; includeExplicit permits an explicitly requested override.", args: { workspace: tool.schema.string(), recommendations: tool.schema.array(tool.schema.object({ stage: tool.schema.string(), executionProfile: capabilityProfile, executionDepth: capabilityDepth })), includeExplicit: tool.schema.boolean().optional() }, execute: run((ctx, a) => ctx.refreshStageProfiles(a.workspace, a.recommendations, { includeExplicit: a.includeExplicit })) });
|
|
90
|
+
export const work_context_show_capability_profiles = tool({ description: "Show capability recommendation mode and validated user-local depth mappings.", args: {}, execute: run((ctx) => ctx.showCapabilityProfiles()) });
|
|
91
|
+
export const work_context_configure_capability_profiles = tool({ description: "Atomically configure either capability recommendation mode or user-local light, standard, and deep model labels. Interactive setup calls it separately for mode and mappings after gathering preferences.", args: { mode: tool.schema.enum(["advisory", "off"]).optional(), mappings: tool.schema.object({ light: tool.schema.string().optional(), standard: tool.schema.string().optional(), deep: tool.schema.string().optional() }).strict().optional() }, execute: run((ctx, a) => ctx.configureCapabilityProfiles(a)) });
|
|
92
|
+
export const work_context_reset_capability_profiles = tool({ description: "Remove all user-local model mappings after explicit RESET_PROFILES confirmation. Stage classifications and project mode remain unchanged.", args: { confirmation: tool.schema.string() }, execute: run((ctx, a) => ctx.resetCapabilityProfiles(a.confirmation)) });
|
|
84
93
|
export const work_context_rename_stage = tool({ description: "Rename a stage while preserving its ID and history; workspace and stage can be omitted in the current OpenCode session.", args: { ...contextualStage, title: tool.schema.string() }, execute: run((ctx, a) => { const workspace = workspaceFromSession(ctx, a.workspace); return ctx.renameStage(workspace, stageFromSession(ctx, workspace, a.stage), a.title); }) });
|
|
85
94
|
export const work_context_update_stage = tool({ description: "Update an existing stage description; workspace and stage can be omitted in the current OpenCode session.", args: { ...contextualStage, description: tool.schema.string() }, execute: run((ctx, a) => { const workspace = workspaceFromSession(ctx, a.workspace); return ctx.updateStage(workspace, stageFromSession(ctx, workspace, a.stage), a.description); }) });
|
|
86
95
|
export const work_context_update_stage_prompt = tool({ description: "Update the optional working prompt of an existing stage; workspace and stage can be omitted in the current OpenCode session.", args: { ...contextualStage, prompt: tool.schema.string() }, execute: run((ctx, a) => { const workspace = workspaceFromSession(ctx, a.workspace); return ctx.updateStagePrompt(workspace, stageFromSession(ctx, workspace, a.stage), a.prompt); }) });
|
|
@@ -105,4 +114,4 @@ export const work_context_add_knowledge = tool({ description: "Add a durable kno
|
|
|
105
114
|
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)) });
|
|
106
115
|
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) ) });
|
|
107
116
|
|
|
108
|
-
export default { work_context_list_workspaces, work_context_workspace_list, work_context_rename_workspace, work_context_set_workspace_mode, work_context_create_candidate, work_context_capture_candidate, work_context_preview_candidate, work_context_show_candidate, work_context_list_candidates, work_context_ready_candidate, work_context_commit_candidate, work_context_discard_candidate, work_context_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_read_stage_execution, work_context_replace_stage_execution, work_context_update_stage_execution, work_context_archive_stage, work_context_reopen_stage, work_context_restore_stage, work_context_link_issue, work_context_unlink_issue, work_context_rename_session, work_context_close_session, work_context_force_close_session, work_context_handoff_stage, work_context_abandon_stage, work_context_finish_stage, work_context_help, work_context_list_knowledge, work_context_add_knowledge, work_context_update_knowledge, work_context_supersede_knowledge };
|
|
117
|
+
export default { work_context_list_workspaces, work_context_workspace_list, work_context_rename_workspace, work_context_set_workspace_mode, work_context_create_candidate, work_context_capture_candidate, work_context_preview_candidate, work_context_show_candidate, work_context_list_candidates, work_context_ready_candidate, work_context_commit_candidate, work_context_discard_candidate, work_context_read_delivery, work_context_mark_delivery, work_context_workspace_finish, work_context_reopen_workspace, work_context_create_workspace, work_context_start_session, work_context_add_stage, work_context_set_stage_profiles, work_context_refresh_stage_profiles, work_context_show_capability_profiles, work_context_configure_capability_profiles, work_context_reset_capability_profiles, work_context_rename_stage, work_context_update_stage, work_context_update_stage_prompt, work_context_update_stage_result, work_context_read_stage_execution, work_context_replace_stage_execution, work_context_update_stage_execution, work_context_archive_stage, work_context_reopen_stage, work_context_restore_stage, work_context_link_issue, work_context_unlink_issue, work_context_rename_session, work_context_close_session, work_context_force_close_session, work_context_handoff_stage, work_context_abandon_stage, work_context_finish_stage, work_context_help, work_context_list_knowledge, work_context_add_knowledge, work_context_update_knowledge, work_context_supersede_knowledge };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { WorkContext } from "./core.js";
|
|
2
|
+
import { capabilityProfileMode, readCapabilityMappings, stageCapabilityProfiles } from "./capability-profiles.js";
|
|
2
3
|
|
|
3
4
|
const emptySnapshot = () => ({
|
|
4
5
|
schema: 1,
|
|
@@ -24,7 +25,7 @@ const sessionFor = (context, sessionId) => {
|
|
|
24
25
|
|| context.sessionByOpenCodeId(sessionId, null, null, null);
|
|
25
26
|
};
|
|
26
27
|
|
|
27
|
-
const readWorkspace = (context, record, currentSession) => {
|
|
28
|
+
const readWorkspace = (context, record, currentSession, capabilityMappings) => {
|
|
28
29
|
const listed = context.listStages(record.workspace).data;
|
|
29
30
|
const sessions = listed.sessions;
|
|
30
31
|
const matchingSession = currentSession?.workspace === record.workspace
|
|
@@ -32,23 +33,32 @@ const readWorkspace = (context, record, currentSession) => {
|
|
|
32
33
|
: sessions.find((session) => session.session_id === currentSession?.session_id);
|
|
33
34
|
const currentStage = matchingSession?.stage || null;
|
|
34
35
|
const mode = record.mode || "standard";
|
|
35
|
-
const
|
|
36
|
+
const candidateProjection = mode === "startup" ? context.candidates().activeProjection(record.workspace) : null;
|
|
37
|
+
const deliveryProjection = context.deliveries().projection(record.workspace);
|
|
38
|
+
const delivery = deliveryProjection.committed.count || deliveryProjection.environments.length || deliveryProjection.unavailable
|
|
39
|
+
? { committed: deliveryProjection.committed.count, plan_needed: deliveryProjection.plan_needed, environments: deliveryProjection.environments, ...(deliveryProjection.unavailable ? { unavailable: true } : {}) }
|
|
40
|
+
: null;
|
|
41
|
+
const visibleStages = listed.stages
|
|
42
|
+
.filter((stage) => stage.status !== "archived")
|
|
43
|
+
.sort((left, right) => Number(left.stage) - Number(right.stage));
|
|
44
|
+
const visibleStageIds = new Set(visibleStages.map((stage) => stage.stage));
|
|
36
45
|
return {
|
|
37
46
|
id: record.workspace,
|
|
38
47
|
title: record.title,
|
|
39
48
|
status: record.status,
|
|
40
49
|
mode,
|
|
41
|
-
...(
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
.sort((left, right) => Number(left.stage) - Number(right.stage))
|
|
50
|
+
...(candidateProjection ? { candidates: candidateProjection.summary } : {}),
|
|
51
|
+
...(delivery ? { delivery } : {}),
|
|
52
|
+
stages: visibleStages
|
|
45
53
|
.map((stage) => ({
|
|
46
54
|
id: stage.stage,
|
|
47
55
|
title: stage.title,
|
|
48
56
|
status: stage.status,
|
|
49
57
|
description: stage.description,
|
|
50
|
-
depends_on: stage.depends_on,
|
|
58
|
+
depends_on: stage.depends_on.filter((dependency) => visibleStageIds.has(dependency)),
|
|
51
59
|
tracker_links: stage.tracker_links || [],
|
|
60
|
+
...stageCapabilityProfiles(context.storage, stage, capabilityMappings),
|
|
61
|
+
...(candidateProjection?.by_stage[stage.stage] ? { candidates: candidateProjection.by_stage[stage.stage] } : {}),
|
|
52
62
|
current: stage.stage === currentStage,
|
|
53
63
|
})),
|
|
54
64
|
currentStage,
|
|
@@ -62,9 +72,10 @@ export function readWorkContextSnapshot({ projectRoot, sessionId } = {}) {
|
|
|
62
72
|
try {
|
|
63
73
|
const context = WorkContext.openExisting(projectRoot, { sessionId, actor: "OpenCode TUI" });
|
|
64
74
|
const currentSession = sessionFor(context, sessionId);
|
|
75
|
+
const capabilityMappings = capabilityProfileMode(context.storage) === "advisory" ? readCapabilityMappings(context.storage) : null;
|
|
65
76
|
const workspaces = context.listWorkspaces().data
|
|
66
77
|
.sort((left, right) => left.workspace.localeCompare(right.workspace))
|
|
67
|
-
.map((record) => readWorkspace(context, record, currentSession));
|
|
78
|
+
.map((record) => readWorkspace(context, record, currentSession, capabilityMappings));
|
|
68
79
|
const currentWorkspace = currentSession?.workspace
|
|
69
80
|
&& workspaces.some((workspace) => workspace.id === currentSession.workspace)
|
|
70
81
|
? currentSession.workspace
|