opencode-work-context 0.4.13 → 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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "opencode-work-context",
3
3
  "type": "module",
4
- "version": "0.4.13",
4
+ "version": "0.4.15",
5
5
  "description": "Filesystem work-context core and OpenCode adapter",
6
6
  "license": "MIT",
7
7
  "author": {
@@ -272,25 +272,29 @@ const currentSessionId = (api) => api?.route?.current?.name === "session"
272
272
  : undefined;
273
273
  const linkedSessionIds = (snapshot) => new Set((snapshot?.data?.workspaces || []).flatMap((workspace) =>
274
274
  (workspace.sessions || []).map((session) => session.opencode_session_id).filter(Boolean)));
275
+ const visibleSessionRecords = (snapshot, sessionId) => (snapshot?.workspaces || []).flatMap((workspace) => {
276
+ const visibleStages = new Set((workspace.stages || [])
277
+ .filter((stage) => stage.status !== "archived")
278
+ .map((stage) => stage.id));
279
+ return (workspace.sessions || [])
280
+ .filter((session) => session.opencode_session_id === sessionId && visibleStages.has(session.stage))
281
+ .map((session) => ({ workspace, session }));
282
+ });
275
283
  const notificationContexts = (snapshot, sessionId, reason) => {
276
284
  const contexts = [];
277
285
  const seen = new Set();
278
- for (const workspace of snapshot?.workspaces || []) {
279
- for (const session of workspace.sessions || []) {
280
- if (session.opencode_session_id !== sessionId || !session.stage) continue;
281
- const key = `${workspace.id}:${session.stage}`;
282
- if (seen.has(key)) continue;
283
- const stage = (workspace.stages || []).find((item) => item.id === session.stage);
284
- if (!stage) continue;
285
- seen.add(key);
286
- contexts.push({
287
- workspaceId: workspace.id,
288
- workspaceTitle: workspace.title,
289
- stageId: stage.id,
290
- stageTitle: stage.title,
291
- reason,
292
- });
293
- }
286
+ for (const { workspace, session } of visibleSessionRecords(snapshot, sessionId)) {
287
+ const key = `${workspace.id}:${session.stage}`;
288
+ if (seen.has(key)) continue;
289
+ const stage = workspace.stages.find((item) => item.id === session.stage);
290
+ seen.add(key);
291
+ contexts.push({
292
+ workspaceId: workspace.id,
293
+ workspaceTitle: workspace.title,
294
+ stageId: stage.id,
295
+ stageTitle: stage.title,
296
+ reason,
297
+ });
294
298
  }
295
299
  return contexts;
296
300
  };
@@ -359,9 +363,7 @@ export const createAttentionTuiController = ({ api, projectRoot, read = readWork
359
363
  const current = currentSessionId(api);
360
364
  for (const attention of engine.list()) {
361
365
  if (attention.sessionId === current) continue;
362
- const records = (snapshot?.workspaces || []).flatMap((workspace) => (workspace.sessions || [])
363
- .filter((session) => session.opencode_session_id === attention.sessionId)
364
- .map((session) => ({ workspace, session })));
366
+ const records = visibleSessionRecords(snapshot, attention.sessionId);
365
367
  if (records.some(matches)) bySession.set(attention.sessionId, attention);
366
368
  }
367
369
  const items = [...bySession.values()];
package/src/core.js CHANGED
@@ -111,7 +111,7 @@ export class WorkContext {
111
111
  workspace = normalizeWorkspaceId(workspace);
112
112
  const dir = path.join(this.storage.workspaceDir(workspace), "stages");
113
113
  if (!fs.existsSync(dir)) fail(ERROR_CODES.NOT_FOUND, "Workspace not found");
114
- const stages = fs.readdirSync(dir).filter((file) => /^\d{2}\.md$/.test(file)).map((file) => {
114
+ const stages = fs.readdirSync(dir).filter((file) => /^\d{2}\.md$/.test(file)).sort().map((file) => {
115
115
  const stage = this.storage.readStage(workspace, file.slice(0, 2)).data;
116
116
  return { ...stage, description: stage.goal };
117
117
  });
@@ -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 result = await fn(contextFor(context.worktree || context.directory, context.sessionID), args, context);
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) {