opencode-work-context 0.14.1 → 0.16.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 +110 -21
- package/commands/wc.md +30 -8
- package/package.json +1 -1
- package/plugin/attention.js +3 -2
- package/plugin/session-switcher.js +12 -11
- package/plugin/stage-switcher.js +6 -5
- package/plugin/stages-tui.js +24 -5
- package/plugin/work-context-modal.js +13 -10
- package/plugin/work-context.js +32 -1
- package/plugin/workspace-switcher.js +4 -3
- package/src/candidates.js +116 -2
- package/src/core.js +307 -35
- package/src/dependency-handoffs.js +204 -0
- package/src/errors.js +6 -0
- package/src/index.js +1 -0
- package/src/integration-notices.js +317 -0
- package/src/protocol.js +2 -2
- package/src/session-diagnostics.js +22 -14
- package/src/sessions.js +5 -0
- package/src/stages-snapshot.js +8 -4
- package/src/storage.js +18 -2
- package/src/tool-definitions.js +26 -28
- package/src/work-context-snapshot.js +4 -4
- package/tools/work_context_add_stage_dependency.js +2 -0
- package/tools/work_context_confirm_candidate_coverage.js +1 -0
- package/tools/work_context_delegate_stage.js +2 -0
- package/tools/work_context_publish_dependency_handoff.js +2 -0
- package/tools/work_context_read_dependency_context.js +2 -0
- package/tools/work_context_remove_stage_dependency.js +2 -0
package/src/stages-snapshot.js
CHANGED
|
@@ -18,12 +18,12 @@ export function readStagesSnapshot({ projectRoot, sessionId }) {
|
|
|
18
18
|
try {
|
|
19
19
|
const context = WorkContext.openExisting(projectRoot, { sessionId, actor: "OpenCode TUI" });
|
|
20
20
|
const sessionDiagnostics = context.diagnoseSessionAssociations(sessionId || null).data;
|
|
21
|
-
let session = sessionId ? context.
|
|
21
|
+
let session = sessionId ? context.sessionAffinityByOpenCodeId(sessionId) : null;
|
|
22
22
|
if (!session && sessionId) {
|
|
23
23
|
const conflict = sessionDiagnostics.findings[0];
|
|
24
24
|
session = conflict
|
|
25
25
|
? context.sessionById(conflict.presumed_original_association.stage_session_id)
|
|
26
|
-
: context.
|
|
26
|
+
: context.sessionById(sessionId);
|
|
27
27
|
}
|
|
28
28
|
if (!session) {
|
|
29
29
|
const activeWorkspaces = context.listWorkspaces().data.filter((workspace) => workspace.status === "in_progress");
|
|
@@ -39,11 +39,13 @@ export function readStagesSnapshot({ projectRoot, sessionId }) {
|
|
|
39
39
|
const mode = workspace.mode || "standard";
|
|
40
40
|
const commitMode = workspace.commit_mode || "manual";
|
|
41
41
|
const candidateProjection = mode === "startup" ? context.candidates().activeProjection(session.workspace) : null;
|
|
42
|
+
const coverageProjection = mode === "startup" ? context.candidates().committedCoverageProjection(session.workspace) : null;
|
|
42
43
|
const deliveryProjection = context.deliveries().projection(session.workspace);
|
|
43
44
|
const delivery = deliveryProjection.committed.count || deliveryProjection.environments.length || deliveryProjection.unavailable
|
|
44
45
|
? { committed: deliveryProjection.committed.count, plan_needed: deliveryProjection.plan_needed, environments: deliveryProjection.environments, ...(deliveryProjection.unavailable ? { unavailable: true } : {}) }
|
|
45
46
|
: null;
|
|
46
|
-
const
|
|
47
|
+
const allStages = context.listStages(session.workspace).data.stages;
|
|
48
|
+
const visibleStages = allStages
|
|
47
49
|
.filter((stage) => stage.status !== "archived")
|
|
48
50
|
.sort((left, right) => Number(left.stage) - Number(right.stage));
|
|
49
51
|
const visibleStageIds = new Set(visibleStages.map((stage) => stage.stage));
|
|
@@ -59,7 +61,9 @@ export function readStagesSnapshot({ projectRoot, sessionId }) {
|
|
|
59
61
|
...(stage.commit_mode ? { commit_mode: stage.commit_mode } : {}),
|
|
60
62
|
...stageCapabilityProfiles(context.storage, stage, capabilityMappings),
|
|
61
63
|
...(candidateProjection?.by_stage[stage.stage] ? { candidates: candidateProjection.by_stage[stage.stage] } : {}),
|
|
62
|
-
|
|
64
|
+
...(coverageProjection?.by_stage[stage.stage] ? { committed_coverage: coverageProjection.by_stage[stage.stage] } : {}),
|
|
65
|
+
...(stage.depends_on.length ? { dependency_context: context.handoffs().context(session.workspace, stage.stage, allStages) } : {}),
|
|
66
|
+
current: stage.stage === session.stage,
|
|
63
67
|
}));
|
|
64
68
|
const currentStage = stages.some((stage) => stage.current) ? session.stage : null;
|
|
65
69
|
if (currentStage) {
|
package/src/storage.js
CHANGED
|
@@ -54,6 +54,19 @@ const validArchiveHistory = (history) => Array.isArray(history) && history.every
|
|
|
54
54
|
&& (item.previous_status === undefined || ["planned", "in_progress", "completed", "cancelled"].includes(item.previous_status))
|
|
55
55
|
&& (item.restored_status === undefined || ["planned", "in_progress", "completed", "cancelled"].includes(item.restored_status))
|
|
56
56
|
&& (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));
|
|
57
|
+
const validDelegation = (delegation) => delegation && typeof delegation === "object" && !Array.isArray(delegation)
|
|
58
|
+
&& Object.keys(delegation).every((key) => ["schema", "dependent_stage", "requested_outcome", "created_at"].includes(key))
|
|
59
|
+
&& delegation.schema === 1 && /^\d{2}$/.test(delegation.dependent_stage)
|
|
60
|
+
&& requiredString(delegation, "requested_outcome") && delegation.requested_outcome === delegation.requested_outcome.trim()
|
|
61
|
+
&& delegation.requested_outcome.length <= 4000 && validTimestamp(delegation.created_at);
|
|
62
|
+
const validDependencyEpochs = (epochs, dependsOn) => epochs && typeof epochs === "object" && !Array.isArray(epochs)
|
|
63
|
+
&& Object.keys(epochs).length <= 98
|
|
64
|
+
&& Object.entries(epochs).every(([stage, item]) => /^\d{2}$/.test(stage) && item && typeof item === "object" && !Array.isArray(item)
|
|
65
|
+
&& Object.keys(item).every((key) => ["generation", "added_at", "removed_at"].includes(key))
|
|
66
|
+
&& Number.isInteger(item.generation) && item.generation > 0 && item.generation <= 1000000
|
|
67
|
+
&& validTimestamp(item.added_at) && (item.removed_at === undefined || (validTimestamp(item.removed_at) && Date.parse(item.removed_at) >= Date.parse(item.added_at)))
|
|
68
|
+
&& (dependsOn.includes(stage) ? item.removed_at === undefined : item.removed_at !== undefined))
|
|
69
|
+
&& dependsOn.every((stage) => Object.hasOwn(epochs, stage));
|
|
57
70
|
const validEvents = new Set(["session.started", "session.renamed", "session.handed_off", "session.closed", "session.abandoned"]);
|
|
58
71
|
const validateEvent = (item) => {
|
|
59
72
|
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");
|
|
@@ -61,7 +74,7 @@ const validateEvent = (item) => {
|
|
|
61
74
|
const allowed = item.event === "session.started" ? ["summary", "opencode_session_id", "branch"] : item.event === "session.renamed" ? ["summary"] : ["reason", "forced"];
|
|
62
75
|
if (keys.some((key) => !allowed.includes(key)) || (item.event === "session.started" && (typeof item.data.summary !== "string" || !item.data.summary.trim() || (item.data.opencode_session_id !== null && item.data.opencode_session_id !== undefined && typeof item.data.opencode_session_id !== "string") || (item.data.branch !== null && item.data.branch !== undefined && typeof item.data.branch !== "string"))) || (item.event === "session.renamed" && (typeof item.data.summary !== "string" || !item.data.summary.trim())) || (item.event !== "session.started" && item.event !== "session.renamed" && (typeof item.data.reason !== "string" || !item.data.reason.trim()) || (item.data.forced !== undefined && typeof item.data.forced !== "boolean"))) fail(ERROR_CODES.STORAGE_ERROR, "Invalid session event data");
|
|
63
76
|
};
|
|
64
|
-
const validateEventStream = (events) => {
|
|
77
|
+
export const validateEventStream = (events) => {
|
|
65
78
|
const ids = new Set();
|
|
66
79
|
const sessions = new Map();
|
|
67
80
|
const stages = new Map();
|
|
@@ -91,7 +104,7 @@ const validateEventStream = (events) => {
|
|
|
91
104
|
}
|
|
92
105
|
};
|
|
93
106
|
function validateMetadata(data, kind, workspace, stage = null) {
|
|
94
|
-
const allowed = kind === "workspace" ? ["schema", "workspace", "title", "status", "mode", "commit_mode", "created_at", "updated_at", "tracker_links", "reopen_history"] : ["schema", "workspace", "stage", "title", "status", "goal", "prompt", "depends_on", "owner", "commit_mode", "execution_profile", "execution_depth", "execution_classification", "review_profile", "created_at", "updated_at", "tracker_links", "reopen_history", "archive_history"];
|
|
107
|
+
const allowed = kind === "workspace" ? ["schema", "workspace", "title", "status", "mode", "commit_mode", "created_at", "updated_at", "tracker_links", "reopen_history"] : ["schema", "workspace", "stage", "title", "status", "goal", "prompt", "depends_on", "dependency_epochs", "delegation", "owner", "commit_mode", "execution_profile", "execution_depth", "execution_classification", "review_profile", "created_at", "updated_at", "tracker_links", "reopen_history", "archive_history"];
|
|
95
108
|
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`);
|
|
96
109
|
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`);
|
|
97
110
|
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,8 +116,10 @@ function validateMetadata(data, kind, workspace, stage = null) {
|
|
|
103
116
|
|| (data.prompt !== undefined && !requiredString(data, "prompt")) || !requiredString(data, "owner")
|
|
104
117
|
|| !Array.isArray(data.depends_on) || new Set(data.depends_on).size !== data.depends_on.length
|
|
105
118
|
|| data.depends_on.includes(data.stage) || data.depends_on.some((item) => typeof item !== "string" || !/^\d{2}$/.test(item))
|
|
119
|
+
|| (data.dependency_epochs !== undefined && !validDependencyEpochs(data.dependency_epochs, data.depends_on))
|
|
106
120
|
|| (data.reopen_history !== undefined && !validReopenHistory(data.reopen_history))
|
|
107
121
|
|| (data.archive_history !== undefined && !validArchiveHistory(data.archive_history))
|
|
122
|
+
|| (data.delegation !== undefined && (!validDelegation(data.delegation) || data.delegation.dependent_stage === data.stage))
|
|
108
123
|
|| (data.execution_profile !== undefined && !CAPABILITY_PROFILES.includes(data.execution_profile))
|
|
109
124
|
|| (data.execution_depth !== undefined && !CAPABILITY_DEPTHS.includes(data.execution_depth))
|
|
110
125
|
|| (data.execution_classification !== undefined && !CAPABILITY_CLASSIFICATIONS.includes(data.execution_classification))
|
|
@@ -161,6 +176,7 @@ export class FileStorage {
|
|
|
161
176
|
knowledgeFile(id) { return path.join(this.workspaceDir(id), "KNOWLEDGE.md"); }
|
|
162
177
|
stageFile(id, stage) { return path.join(this.workspaceDir(id), "stages", `${stage}.md`); }
|
|
163
178
|
stageExecutionFile(id, stage) { return path.join(this.workspaceDir(id), "stages", `${stage}.execution.json`); }
|
|
179
|
+
dependencyHandoffsFile(id) { return path.join(this.workspaceDir(id), "dependency-handoffs.json"); }
|
|
164
180
|
sessionFile() { return path.join(this.personalRoot, "sessions.jsonl"); }
|
|
165
181
|
lockPath(name = "write") { return path.join(this.root, ".locks", `${name}.lock`); }
|
|
166
182
|
readWorkspace(id) { const record = this.readCanonical(this.workspaceFile(id)); validateMetadata(record.data, "workspace", id); return record; }
|
package/src/tool-definitions.js
CHANGED
|
@@ -62,8 +62,8 @@ const sessionFromContext = (ctx, workspace) => {
|
|
|
62
62
|
next_action: "Specify both workspace and stage to hand off or close the incorrect association after reviewing the session history.",
|
|
63
63
|
});
|
|
64
64
|
}
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
const affinity = ctx.sessionAffinityByOpenCodeId(ctx.options.sessionId);
|
|
66
|
+
return affinity && (!workspace || affinity.workspace === workspace) ? affinity : null;
|
|
67
67
|
};
|
|
68
68
|
const workspaceFromSession = (ctx, workspace) => {
|
|
69
69
|
if (workspace !== undefined) return normalizeWorkspaceId(workspace);
|
|
@@ -77,25 +77,16 @@ const stageFromSession = (ctx, workspace, stage) => {
|
|
|
77
77
|
if (!session) fail(ERROR_CODES.STAGE_CONTEXT_REQUIRED, "Stage is required when the current session is not associated with a stage");
|
|
78
78
|
return session.stage;
|
|
79
79
|
};
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
80
|
+
const activeSessionFromContext = (ctx, workspace, stage) => {
|
|
81
|
+
const associated = ctx.sessionByOpenCodeId(ctx.options.sessionId, workspace, stage);
|
|
82
|
+
if (associated) return associated;
|
|
83
|
+
const direct = ctx.sessionById(ctx.options.sessionId);
|
|
84
|
+
return direct?.workspace === workspace && direct.stage === stage && direct.state === "active" ? direct : null;
|
|
85
|
+
};
|
|
86
|
+
const sessionFor = (ctx, oc, workspace, stage) => activeSessionFromContext(ctx, workspace, stage)?.session_id || oc.sessionID;
|
|
87
|
+
const addStageFromTool = (ctx, args) => {
|
|
86
88
|
const workspace = workspaceFromSession(ctx, args.workspace);
|
|
87
|
-
|
|
88
|
-
if (currentSession) return created;
|
|
89
|
-
|
|
90
|
-
const started = ctx.startSession(workspace, created.data.stage, {
|
|
91
|
-
sessionId: randomUUID(),
|
|
92
|
-
opencodeSessionId: oc.sessionID,
|
|
93
|
-
summary: `started ${args.title.trim()}`,
|
|
94
|
-
});
|
|
95
|
-
return {
|
|
96
|
-
...started,
|
|
97
|
-
data: { ...started.data, status: "in_progress", session_started: true, resume_required: false },
|
|
98
|
-
};
|
|
89
|
+
return 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 });
|
|
99
90
|
};
|
|
100
91
|
export const work_context_list_workspaces = tool({ description: "List work-context workspaces.", args: {}, execute: run((ctx) => ctx.listWorkspaces()) });
|
|
101
92
|
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)) });
|
|
@@ -109,6 +100,7 @@ export const work_context_preview_candidate = tool({ description: "Preview a can
|
|
|
109
100
|
export const work_context_show_candidate = tool({ description: "Show local candidate metadata and its exact captured patch.", args: { workspace: tool.schema.string(), candidateId: tool.schema.string() }, execute: run((ctx, a) => ctx.showCandidate(a.workspace, a.candidateId)) });
|
|
110
101
|
export const work_context_list_candidates = tool({ description: "List local commit candidates associated with a startup-mode workspace.", args: { workspace: tool.schema.string() }, execute: run((ctx, a) => ctx.listCandidates(a.workspace)) });
|
|
111
102
|
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)) });
|
|
103
|
+
export const work_context_confirm_candidate_coverage = tool({ description: "Explicitly confirm that one ready integration candidate covers the stable Current items of selected stages. Requires INTEGRATION_COVERAGE_CONFIRMED.", args: { workspace: tool.schema.string(), candidateId: tool.schema.string(), stages: tool.schema.array(tool.schema.string()), confirmation: tool.schema.string() }, execute: run((ctx, a) => ctx.confirmCandidateCoverage(a.workspace, a.candidateId, a.stages, a.confirmation)) });
|
|
112
104
|
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)) });
|
|
113
105
|
export const work_context_inspect_commit_all = tool({ description: "Inspect a repository-local integration boundary and return a confirmation fingerprint without changing Git or candidate state.", args: { workspace: tool.schema.string(), relatedStages: tool.schema.array(tool.schema.string()).optional(), excludePaths: tool.schema.array(tool.schema.string()).optional(), message: tool.schema.string().optional() }, execute: run((ctx, a) => ctx.inspectCommitAll(a.workspace, { relatedStages: a.relatedStages, excludePaths: a.excludePaths, message: a.message })) });
|
|
114
106
|
export const work_context_commit_all = tool({ description: "Reproduce and atomically publish a previously inspected repository-local integration plan after exact explicit confirmation.", args: { workspace: tool.schema.string(), expectedFingerprint: tool.schema.string(), confirmation: tool.schema.string(), relatedStages: tool.schema.array(tool.schema.string()).optional(), excludePaths: tool.schema.array(tool.schema.string()).optional(), message: tool.schema.string().optional() }, execute: run((ctx, a) => ctx.commitAll(a.workspace, a.expectedFingerprint, a.confirmation, { relatedStages: a.relatedStages, excludePaths: a.excludePaths, message: a.message })) });
|
|
@@ -126,17 +118,23 @@ export const work_context_doctor_delivery = createDoctorDeliveryTool();
|
|
|
126
118
|
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)) });
|
|
127
119
|
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)) });
|
|
128
120
|
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)) });
|
|
129
|
-
export const work_context_create_workspace = tool({ description: "Create a workspace; enter its planning stage only when the
|
|
130
|
-
const currentSession = ctx.
|
|
131
|
-
return ctx.createWorkspace(a.title, {
|
|
121
|
+
export const work_context_create_workspace = tool({ description: "Create a workspace; enter its planning stage only when the native OpenCode session has no active or historical work-context stage affinity.", args: { title: tool.schema.string(), mode: tool.schema.enum(["standard", "startup"]).optional() }, execute: run((ctx, a, oc) => {
|
|
122
|
+
const currentSession = ctx.sessionAffinityByOpenCodeId(oc.sessionID);
|
|
123
|
+
return ctx.createWorkspace(a.title, { mode: a.mode, ...(currentSession ? { startSession: false } : { sessionId: randomUUID(), opencodeSessionId: oc.sessionID }) });
|
|
132
124
|
}) });
|
|
133
|
-
export const work_context_start_session = tool({ description: "Start a new active session for
|
|
125
|
+
export const work_context_start_session = tool({ description: "Start a new active session for the stage permanently associated with this OpenCode session and return its human-oriented presentation, prompt, active workspace knowledge, and startup policy when applicable. A different stage requires a separate OpenCode session.", 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 })) });
|
|
134
126
|
export const work_context_acknowledge_commit = tool({ description: "Acknowledge a user-created current-HEAD commit for the active session using a short or full commit hash. This is a deterministic light control-plane operation and does not infer ownership.", args: { sha: tool.schema.string() }, execute: run((ctx, a) => {
|
|
135
|
-
const
|
|
127
|
+
const affinity = sessionFromContext(ctx);
|
|
128
|
+
const session = affinity && activeSessionFromContext(ctx, affinity.workspace, affinity.stage);
|
|
136
129
|
if (!session) fail(ERROR_CODES.STAGE_CONTEXT_REQUIRED, "An active work-context stage is required to acknowledge a commit");
|
|
137
130
|
return ctx.acknowledgeCommit(session.workspace, session.stage, session.session_id, a.sha);
|
|
138
131
|
}) });
|
|
139
|
-
export const work_context_add_stage = tool({ description: "Add a stage
|
|
132
|
+
export const work_context_add_stage = tool({ description: "Add a planned stage without starting or changing a stage session. When the user did not specify execution capability and depth, 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) });
|
|
133
|
+
export const work_context_delegate_stage = tool({ description: "Atomically create a delegated working stage and add it as a dependency of the active delegating stage.", args: { ...contextualStage, title: tool.schema.string(), requestedOutcome: 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((ctx, a, oc) => { const workspace = workspaceFromSession(ctx, a.workspace); const stage = stageFromSession(ctx, workspace, a.stage); return ctx.delegateStage(workspace, stage, sessionFor(ctx, oc, workspace, stage), a.title, a.requestedOutcome, a); }) });
|
|
134
|
+
export const work_context_add_stage_dependency = tool({ description: "Add one explicit cycle-safe dependency edge to an actionable dependent stage.", args: { ...contextualStage, dependency: tool.schema.string() }, execute: run((ctx, a) => { const workspace = workspaceFromSession(ctx, a.workspace); return ctx.addStageDependency(workspace, stageFromSession(ctx, workspace, a.stage), a.dependency); }) });
|
|
135
|
+
export const work_context_remove_stage_dependency = tool({ description: "Remove one explicit dependency edge while retaining historical handoffs.", args: { ...contextualStage, dependency: tool.schema.string() }, execute: run((ctx, a) => { const workspace = workspaceFromSession(ctx, a.workspace); return ctx.removeStageDependency(workspace, stageFromSession(ctx, workspace, a.stage), a.dependency); }) });
|
|
136
|
+
export const work_context_publish_dependency_handoff = tool({ description: "Publish a bounded intermediate handoff from the active source stage to all formal direct dependents without finishing any stage.", args: { ...contextualStage, outcome: tool.schema.string(), candidateIds: tool.schema.array(tool.schema.string()).optional(), commits: tool.schema.array(tool.schema.string()).optional(), verification: tool.schema.array(tool.schema.string()).optional(), blockers: tool.schema.array(tool.schema.string()).optional() }, execute: run((ctx, a, oc) => { const workspace = workspaceFromSession(ctx, a.workspace); const stage = stageFromSession(ctx, workspace, a.stage); return ctx.publishDependencyHandoff(workspace, stage, sessionFor(ctx, oc, workspace, stage), a); }) });
|
|
137
|
+
export const work_context_read_dependency_context = tool({ description: "Read direct dependency satisfaction and current bounded handoffs for one stage.", args: contextualStage, execute: run((ctx, a) => { const workspace = workspaceFromSession(ctx, a.workspace); return ctx.readDependencyContext(workspace, stageFromSession(ctx, workspace, a.stage)); }) });
|
|
140
138
|
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 } : {}) }); }) });
|
|
141
139
|
export const work_context_set_stage_commit_mode = tool({ description: "Set or clear a stage checklist commit-mode override; null inherits the workspace mode.", args: { ...contextualStage, commitMode: commitMode.nullable() }, execute: run((ctx, a) => { const workspace = workspaceFromSession(ctx, a.workspace); return ctx.setStageCommitMode(workspace, stageFromSession(ctx, workspace, a.stage), a.commitMode); }) });
|
|
142
140
|
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 })) });
|
|
@@ -161,14 +159,14 @@ export const work_context_close_session = tool({ description: "Close the current
|
|
|
161
159
|
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)) });
|
|
162
160
|
export const work_context_handoff_stage = tool({ description: "Hand off the current stage by closing the current session; 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.handoff(workspace, stage, sessionFor(ctx, oc, workspace, stage)); }) });
|
|
163
161
|
export const work_context_abandon_stage = tool({ description: "Abandon the current stage session without completing the 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.abandon(workspace, stage, sessionFor(ctx, oc, workspace, stage)); }) });
|
|
164
|
-
export const work_context_finish_stage = tool({ description: "Finish a stage only for an explicit user lifecycle request, unless the Planning-stage prompt explicitly permits automatic completion. Review durable workspace knowledge; use knowledgeReview=added after changes or none when no durable findings exist.", args: { ...contextualStage, result: tool.schema.string().optional(), knowledgeReview: tool.schema.string().optional() }, execute: run((ctx, a, oc) => { const workspace = workspaceFromSession(ctx, a.workspace); const stage = stageFromSession(ctx, workspace, a.stage); return ctx.finish(workspace, stage, sessionFor(ctx, oc, workspace, stage),
|
|
162
|
+
export const work_context_finish_stage = tool({ description: "Finish a stage only for an explicit user lifecycle request, unless the Planning-stage prompt explicitly permits automatic completion. Direct dependents receive one immutable final handoff. Review durable workspace knowledge; use knowledgeReview=added after changes or none when no durable findings exist.", args: { ...contextualStage, result: tool.schema.string().optional(), handoffOutcome: tool.schema.string().optional(), knowledgeReview: tool.schema.string().optional(), candidateIds: tool.schema.array(tool.schema.string()).optional(), commits: tool.schema.array(tool.schema.string()).optional(), verification: tool.schema.array(tool.schema.string()).optional(), blockers: tool.schema.array(tool.schema.string()).optional() }, execute: run((ctx, a, oc) => { const workspace = workspaceFromSession(ctx, a.workspace); const stage = stageFromSession(ctx, workspace, a.stage); return ctx.finish(workspace, stage, sessionFor(ctx, oc, workspace, stage), a); }) });
|
|
165
163
|
export const work_context_help = tool({ description: "Show work-context command help.", args: { command: tool.schema.string().optional() }, execute: run((ctx, a) => ctx.help(a.command)) });
|
|
166
164
|
export const work_context_list_knowledge = tool({ description: "List durable knowledge entries for a workspace.", args: { workspace: tool.schema.string() }, execute: run((ctx, a) => ctx.listKnowledge(a.workspace)) });
|
|
167
165
|
export const work_context_add_knowledge = tool({ description: "Add a durable knowledge entry.", args: { workspace: tool.schema.string(), title: tool.schema.string(), kind: tool.schema.string().optional(), text: tool.schema.string(), sources: tool.schema.array(tool.schema.string()).optional() }, execute: run((ctx, a) => ctx.addKnowledge(a.workspace, a)) });
|
|
168
166
|
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)) });
|
|
169
167
|
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) ) });
|
|
170
168
|
|
|
171
|
-
const defaultTools = { work_context_list_workspaces, work_context_workspace_list, work_context_rename_workspace, work_context_set_workspace_mode, work_context_set_workspace_commit_mode, work_context_read_effective_commit_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_inspect_commit_all, work_context_commit_all, 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_acknowledge_commit, work_context_add_stage, work_context_set_stage_profiles, work_context_set_stage_commit_mode, 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_complete_current, 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 };
|
|
169
|
+
const defaultTools = { work_context_list_workspaces, work_context_workspace_list, work_context_rename_workspace, work_context_set_workspace_mode, work_context_set_workspace_commit_mode, work_context_read_effective_commit_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_confirm_candidate_coverage, work_context_commit_candidate, work_context_inspect_commit_all, work_context_commit_all, 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_acknowledge_commit, work_context_add_stage, work_context_delegate_stage, work_context_add_stage_dependency, work_context_remove_stage_dependency, work_context_publish_dependency_handoff, work_context_read_dependency_context, work_context_set_stage_profiles, work_context_set_stage_commit_mode, 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_complete_current, 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 };
|
|
172
170
|
|
|
173
171
|
export function createToolDefinitions(options = {}) {
|
|
174
172
|
return { ...defaultTools, work_context_doctor_delivery: createDoctorDeliveryTool(options) };
|
|
@@ -22,12 +22,9 @@ const errorResult = (error) => ({
|
|
|
22
22
|
|
|
23
23
|
const sessionFor = (context, sessionId) => {
|
|
24
24
|
if (!sessionId) return null;
|
|
25
|
-
const direct = context.sessionById(sessionId);
|
|
26
|
-
if (direct) return direct;
|
|
27
25
|
const conflict = context.diagnoseSessionAssociations(sessionId).data.findings[0];
|
|
28
26
|
if (conflict) return context.sessionById(conflict.presumed_original_association.stage_session_id);
|
|
29
|
-
return context.
|
|
30
|
-
|| context.sessionByOpenCodeId(sessionId, null, null, null);
|
|
27
|
+
return context.sessionAffinityByOpenCodeId(sessionId) || context.sessionById(sessionId);
|
|
31
28
|
};
|
|
32
29
|
|
|
33
30
|
const readWorkspace = (context, record, currentSession, capabilityMappings) => {
|
|
@@ -40,6 +37,7 @@ const readWorkspace = (context, record, currentSession, capabilityMappings) => {
|
|
|
40
37
|
const mode = record.mode || "standard";
|
|
41
38
|
const commitMode = record.commit_mode || "manual";
|
|
42
39
|
const candidateProjection = mode === "startup" ? context.candidates().activeProjection(record.workspace) : null;
|
|
40
|
+
const coverageProjection = mode === "startup" ? context.candidates().committedCoverageProjection(record.workspace) : null;
|
|
43
41
|
const deliveryProjection = context.deliveries().projection(record.workspace);
|
|
44
42
|
const delivery = deliveryProjection.committed.count || deliveryProjection.environments.length || deliveryProjection.unavailable
|
|
45
43
|
? { committed: deliveryProjection.committed.count, plan_needed: deliveryProjection.plan_needed, environments: deliveryProjection.environments, ...(deliveryProjection.unavailable ? { unavailable: true } : {}) }
|
|
@@ -67,6 +65,8 @@ const readWorkspace = (context, record, currentSession, capabilityMappings) => {
|
|
|
67
65
|
...(stage.commit_mode ? { commit_mode: stage.commit_mode } : {}),
|
|
68
66
|
...stageCapabilityProfiles(context.storage, stage, capabilityMappings),
|
|
69
67
|
...(candidateProjection?.by_stage[stage.stage] ? { candidates: candidateProjection.by_stage[stage.stage] } : {}),
|
|
68
|
+
...(coverageProjection?.by_stage[stage.stage] ? { committed_coverage: coverageProjection.by_stage[stage.stage] } : {}),
|
|
69
|
+
...(stage.depends_on.length ? { dependency_context: context.handoffs().context(record.workspace, stage.stage, listed.stages) } : {}),
|
|
70
70
|
current: stage.stage === currentStage,
|
|
71
71
|
})),
|
|
72
72
|
currentStage,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { work_context_confirm_candidate_coverage as default } from "../src/tool-definitions.js";
|