opencode-work-context 0.10.1 → 0.10.2
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 +70 -0
- package/commands/wc.md +8 -0
- package/package.json +1 -1
- package/plugin/work-context.js +4 -4
- package/src/core.js +14 -1
- package/src/delivery-contracts.js +108 -0
- package/src/delivery-doctor.js +304 -0
- package/src/delivery-git.js +159 -0
- package/src/delivery-redaction.js +68 -0
- package/src/delivery-slices.js +125 -0
- package/src/delivery.js +126 -0
- package/src/errors.js +2 -0
- package/src/index.js +5 -0
- package/src/opencode-adapter.js +25 -0
- package/src/protocol.js +47 -0
- package/src/storage.js +18 -5
- package/src/tool-definitions.js +42 -2
- package/tools/work_context_doctor_delivery.js +3 -0
- package/tools/work_context_explain_delivery.js +3 -0
package/src/storage.js
CHANGED
|
@@ -5,6 +5,7 @@ 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
7
|
import { CAPABILITY_CLASSIFICATIONS, CAPABILITY_DEPTHS, CAPABILITY_PROFILES } from "./capability-profiles.js";
|
|
8
|
+
import { validateSecretPathPatterns } from "./delivery-redaction.js";
|
|
8
9
|
|
|
9
10
|
const now = () => new Date().toISOString();
|
|
10
11
|
const ensure = (dir) => fs.mkdirSync(dir, { recursive: true });
|
|
@@ -142,7 +143,8 @@ export class FileStorage {
|
|
|
142
143
|
constructor(projectRoot, config = {}) {
|
|
143
144
|
this.projectRoot = projectRoot;
|
|
144
145
|
const storage = config.storage || {};
|
|
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 || {}) } };
|
|
146
|
+
this.config = { mode: "hybrid", root: ".work-context", personal_root: ".work-context/local", title: { issue_prefix: "short" }, tracker: { provider: null }, capability_profiles: { mode: "advisory" }, delivery: { secret_path_patterns: [] }, ...config, ...storage, title: { issue_prefix: "short", ...(config.title || {}) }, tracker: { provider: null, ...(config.tracker || {}) }, capability_profiles: { mode: "advisory", ...(config.capability_profiles || {}) }, delivery: { secret_path_patterns: [], ...(config.delivery || {}) } };
|
|
147
|
+
this.config.delivery.secret_path_patterns = validateSecretPathPatterns(this.config.delivery.secret_path_patterns);
|
|
146
148
|
this.root = path.resolve(projectRoot, this.config.root);
|
|
147
149
|
this.personalRoot = path.resolve(projectRoot, this.config.personal_root);
|
|
148
150
|
const project = path.resolve(projectRoot);
|
|
@@ -310,7 +312,7 @@ export class FileStorage {
|
|
|
310
312
|
|
|
311
313
|
export function loadConfig(projectRoot, configFile = path.resolve(projectRoot, ".work-context", "config.yaml")) {
|
|
312
314
|
if (!fs.existsSync(configFile)) return {};
|
|
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) });
|
|
315
|
+
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), delivery: Object.create(null) });
|
|
314
316
|
let section = null;
|
|
315
317
|
for (const line of fs.readFileSync(configFile, "utf8").split("\n")) {
|
|
316
318
|
if (!line.trim() || line.trim().startsWith("#")) continue;
|
|
@@ -318,9 +320,20 @@ export function loadConfig(projectRoot, configFile = path.resolve(projectRoot, "
|
|
|
318
320
|
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; }
|
|
319
321
|
if (section && data[section] && typeof data[section] === "object") data[section][match[2]] = scalarConfig(match[3]);
|
|
320
322
|
}
|
|
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");
|
|
323
|
+
if (Object.keys(data).some((key) => !["schema", "storage", "title", "tracker", "notifications", "capability_profiles", "delivery"].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.delivery || typeof data.delivery !== "object" || Array.isArray(data.delivery) || Object.keys(data.delivery).some((key) => key !== "secret_path_patterns") || 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
324
|
data.capability_profiles.mode ||= "advisory";
|
|
325
|
+
data.delivery.secret_path_patterns = validateSecretPathPatterns(data.delivery.secret_path_patterns || []);
|
|
323
326
|
return data;
|
|
324
327
|
}
|
|
325
|
-
const scalarConfig = (value) =>
|
|
326
|
-
|
|
328
|
+
const scalarConfig = (value) => {
|
|
329
|
+
if (value === "null") return null;
|
|
330
|
+
if (value === "[]") return [];
|
|
331
|
+
if (value === "{}") return {};
|
|
332
|
+
if (/^(true|false)$/.test(value)) return value === "true";
|
|
333
|
+
if (/^-?\d+(\.\d+)?$/.test(value)) return Number(value);
|
|
334
|
+
if (value.startsWith("[") && value.endsWith("]")) {
|
|
335
|
+
try { return JSON.parse(value); } catch { return value; }
|
|
336
|
+
}
|
|
337
|
+
return value;
|
|
338
|
+
};
|
|
339
|
+
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\ndelivery:\n secret_path_patterns: []\n`;
|
package/src/tool-definitions.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
import { contextFor, titleFor } from "../src/opencode-adapter.js";
|
|
3
|
+
import { contextFor, runtimeSelfReport, titleFor } from "../src/opencode-adapter.js";
|
|
4
|
+
import { WorkContext } from "../src/core.js";
|
|
4
5
|
import { fail, ERROR_CODES } from "../src/errors.js";
|
|
5
6
|
import { normalizeStageId, normalizeWorkspaceId } from "../src/identifiers.js";
|
|
6
7
|
|
|
@@ -17,10 +18,34 @@ const run = (fn) => async (args, context) => {
|
|
|
17
18
|
return { output: JSON.stringify({ ok: false, error: { code: error.code || "STORAGE_ERROR", message: error.message, details: error.details || {} } }), metadata: { code: error.code || "STORAGE_ERROR" } };
|
|
18
19
|
}
|
|
19
20
|
};
|
|
21
|
+
const runProject = (fn, { metadata = true, redactErrors = false } = {}) => async (args, context) => {
|
|
22
|
+
try {
|
|
23
|
+
const projectRoot = context.worktree === "/" ? context.directory : (context.worktree || context.directory);
|
|
24
|
+
const result = await fn(projectRoot, args, context);
|
|
25
|
+
if (metadata) try { await context.metadata({ title: "work-context", metadata: { result } }); } catch {}
|
|
26
|
+
return { output: JSON.stringify(result), metadata: result };
|
|
27
|
+
} catch (error) {
|
|
28
|
+
const stable = Object.values(ERROR_CODES).includes(error.code) ? error.code : ERROR_CODES.STORAGE_ERROR;
|
|
29
|
+
const result = { ok: false, error: {
|
|
30
|
+
code: stable,
|
|
31
|
+
message: redactErrors && stable !== ERROR_CODES.DELIVERY_COMMAND_PROTOCOL_MISMATCH ? "Delivery doctor could not complete safely" : error.message,
|
|
32
|
+
details: redactErrors && stable !== ERROR_CODES.DELIVERY_COMMAND_PROTOCOL_MISMATCH ? {} : (error.details || {}),
|
|
33
|
+
} };
|
|
34
|
+
return { output: JSON.stringify(result), metadata: { code: result.error.code } };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
20
37
|
const common = { workspace: tool.schema.string(), stage: tool.schema.string() };
|
|
21
38
|
const contextualStage = { workspace: tool.schema.string().optional(), stage: tool.schema.string().optional() };
|
|
22
39
|
const capabilityProfile = tool.schema.enum(["routine", "implementation", "architecture", "security", "review"]);
|
|
23
40
|
const capabilityDepth = tool.schema.enum(["light", "standard", "deep"]);
|
|
41
|
+
const deliveryFinding = tool.schema.object({
|
|
42
|
+
id: tool.schema.string(),
|
|
43
|
+
severity: tool.schema.enum(["info", "warning", "error"]),
|
|
44
|
+
summary: tool.schema.string(),
|
|
45
|
+
affected_paths: tool.schema.array(tool.schema.string()).optional(),
|
|
46
|
+
remediation_ids: tool.schema.array(tool.schema.string()).optional(),
|
|
47
|
+
recommendation: tool.schema.string().optional(),
|
|
48
|
+
}).strict();
|
|
24
49
|
const executionSections = {
|
|
25
50
|
scope: tool.schema.array(tool.schema.string()).optional(),
|
|
26
51
|
completed: tool.schema.array(tool.schema.string()).optional(),
|
|
@@ -76,6 +101,15 @@ export const work_context_ready_candidate = tool({ description: "Mark a captured
|
|
|
76
101
|
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)) });
|
|
77
102
|
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
103
|
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 })) });
|
|
104
|
+
export const work_context_explain_delivery = tool({ description: "Explain a bounded immutable delivery range with read-only Git evidence, findings, and traceability.", args: { workspace: tool.schema.string(), from: tool.schema.string(), to: tool.schema.string(), findings: tool.schema.array(deliveryFinding).optional() }, execute: run((ctx, a) => ctx.explainDelivery(a.workspace, a.from, a.to, a.findings) ) });
|
|
105
|
+
const createDoctorDeliveryTool = ({ runtimeEvidence = runtimeSelfReport } = {}) => tool({
|
|
106
|
+
description: "Diagnose project delivery command, installation, and loaded-plugin protocol evidence without making changes.",
|
|
107
|
+
args: {},
|
|
108
|
+
execute: runProject((projectRoot) => WorkContext.doctorDelivery(projectRoot, {
|
|
109
|
+
loadedPlugin: typeof runtimeEvidence === "function" ? runtimeEvidence(projectRoot) : runtimeEvidence,
|
|
110
|
+
}), { metadata: false, redactErrors: true }),
|
|
111
|
+
});
|
|
112
|
+
export const work_context_doctor_delivery = createDoctorDeliveryTool();
|
|
79
113
|
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)) });
|
|
80
114
|
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)) });
|
|
81
115
|
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)) });
|
|
@@ -114,4 +148,10 @@ export const work_context_add_knowledge = tool({ description: "Add a durable kno
|
|
|
114
148
|
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)) });
|
|
115
149
|
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) ) });
|
|
116
150
|
|
|
117
|
-
|
|
151
|
+
const defaultTools = { 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_explain_delivery, work_context_doctor_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 };
|
|
152
|
+
|
|
153
|
+
export function createToolDefinitions(options = {}) {
|
|
154
|
+
return { ...defaultTools, work_context_doctor_delivery: createDoctorDeliveryTool(options) };
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export default defaultTools;
|