aiwcli 0.10.3 → 0.11.1
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/bin/run.js +1 -1
- package/dist/commands/clear.js +28 -131
- package/dist/commands/init/index.js +3 -3
- package/dist/lib/gitignore-manager.d.ts +32 -0
- package/dist/lib/gitignore-manager.js +141 -2
- package/dist/templates/CLAUDE.md +8 -8
- package/dist/templates/_shared/.claude/commands/handoff-resume.md +64 -0
- package/dist/templates/_shared/.claude/commands/handoff.md +16 -10
- package/dist/templates/_shared/.claude/settings.json +7 -7
- package/dist/templates/_shared/hooks-ts/_utils/git-state.ts +2 -0
- package/dist/templates/_shared/hooks-ts/archive_plan.ts +159 -0
- package/dist/templates/_shared/hooks-ts/context_monitor.ts +147 -0
- package/dist/templates/_shared/hooks-ts/file-suggestion.ts +130 -0
- package/dist/templates/_shared/hooks-ts/pre_compact.ts +49 -0
- package/dist/templates/_shared/hooks-ts/session_end.ts +107 -0
- package/dist/templates/_shared/hooks-ts/session_start.ts +144 -0
- package/dist/templates/_shared/hooks-ts/task_create_capture.ts +48 -0
- package/dist/templates/_shared/hooks-ts/task_update_capture.ts +74 -0
- package/dist/templates/_shared/hooks-ts/user_prompt_submit.ts +83 -0
- package/dist/templates/_shared/lib-ts/CLAUDE.md +318 -0
- package/dist/templates/_shared/lib-ts/base/atomic-write.ts +12 -12
- package/dist/templates/_shared/lib-ts/base/constants.ts +22 -15
- package/dist/templates/_shared/lib-ts/base/git-state.ts +1 -1
- package/dist/templates/_shared/lib-ts/base/hook-utils.ts +129 -50
- package/dist/templates/_shared/lib-ts/base/inference.ts +28 -21
- package/dist/templates/_shared/lib-ts/base/logger.ts +15 -2
- package/dist/templates/_shared/lib-ts/base/state-io.ts +9 -7
- package/dist/templates/_shared/lib-ts/base/stop-words.ts +131 -131
- package/dist/templates/_shared/lib-ts/base/subprocess-utils.ts +142 -0
- package/dist/templates/_shared/lib-ts/base/utils.ts +69 -69
- package/dist/templates/_shared/lib-ts/context/context-formatter.ts +30 -24
- package/dist/templates/_shared/lib-ts/context/context-selector.ts +50 -32
- package/dist/templates/_shared/lib-ts/context/context-store.ts +76 -48
- package/dist/templates/_shared/lib-ts/context/plan-manager.ts +43 -23
- package/dist/templates/_shared/lib-ts/context/task-tracker.ts +10 -6
- package/dist/templates/_shared/lib-ts/handoff/document-generator.ts +11 -10
- package/dist/templates/_shared/lib-ts/handoff/handoff-reader.ts +158 -0
- package/dist/templates/_shared/lib-ts/templates/formatters.ts +6 -4
- package/dist/templates/_shared/lib-ts/types.ts +68 -55
- package/dist/templates/_shared/scripts/resolve_context.ts +24 -0
- package/dist/templates/_shared/scripts/resume_handoff.ts +345 -0
- package/dist/templates/_shared/scripts/save_handoff.ts +3 -3
- package/dist/templates/_shared/scripts/status_line.ts +687 -0
- package/dist/templates/cc-native/.claude/settings.json +175 -185
- package/dist/templates/cc-native/TEMPLATE-SCHEMA.md +15 -17
- package/dist/templates/cc-native/_cc-native/agents/CLAUDE.md +0 -2
- package/dist/templates/cc-native/_cc-native/hooks/CLAUDE.md +109 -135
- package/dist/templates/cc-native/_cc-native/hooks/add_plan_context.ts +119 -0
- package/dist/templates/cc-native/_cc-native/hooks/cc-native-plan-review.ts +1027 -0
- package/dist/templates/cc-native/_cc-native/hooks/plan_questions_early.ts +61 -0
- package/dist/templates/cc-native/_cc-native/lib-ts/aggregate-agents.ts +156 -0
- package/dist/templates/cc-native/_cc-native/lib-ts/artifacts.ts +792 -0
- package/dist/templates/cc-native/_cc-native/lib-ts/cc-native-state.ts +199 -0
- package/dist/templates/cc-native/_cc-native/lib-ts/cli-output-parser.ts +144 -0
- package/dist/templates/cc-native/_cc-native/lib-ts/config.ts +57 -0
- package/dist/templates/cc-native/_cc-native/lib-ts/constants.ts +83 -0
- package/dist/templates/cc-native/_cc-native/lib-ts/corroboration.ts +115 -0
- package/dist/templates/cc-native/_cc-native/lib-ts/debug.ts +80 -0
- package/dist/templates/cc-native/_cc-native/lib-ts/index.ts +120 -0
- package/dist/templates/cc-native/_cc-native/lib-ts/json-parser.ts +168 -0
- package/dist/templates/cc-native/_cc-native/lib-ts/nul +3 -0
- package/dist/templates/cc-native/_cc-native/lib-ts/orchestrator.ts +250 -0
- package/dist/templates/cc-native/_cc-native/lib-ts/reviewers/agent.ts +275 -0
- package/dist/templates/cc-native/_cc-native/lib-ts/reviewers/codex.ts +130 -0
- package/dist/templates/cc-native/_cc-native/lib-ts/reviewers/gemini.ts +107 -0
- package/dist/templates/cc-native/_cc-native/lib-ts/reviewers/index.ts +10 -0
- package/dist/templates/cc-native/_cc-native/lib-ts/reviewers/types.ts +23 -0
- package/dist/templates/cc-native/_cc-native/lib-ts/state.ts +240 -0
- package/dist/templates/cc-native/_cc-native/lib-ts/tsconfig.json +18 -0
- package/dist/templates/cc-native/_cc-native/lib-ts/types.ts +385 -0
- package/dist/templates/cc-native/_cc-native/lib-ts/verdict.ts +72 -0
- package/dist/templates/cc-native/_cc-native/plan-review.config.json +14 -1
- package/oclif.manifest.json +1 -1
- package/package.json +2 -2
- package/dist/templates/_shared/hooks/__init__.py +0 -16
- package/dist/templates/_shared/hooks/__pycache__/__init__.cpython-313.pyc +0 -0
- package/dist/templates/_shared/hooks/__pycache__/archive_plan.cpython-313.pyc +0 -0
- package/dist/templates/_shared/hooks/__pycache__/context_enforcer.cpython-313.pyc +0 -0
- package/dist/templates/_shared/hooks/__pycache__/context_monitor.cpython-313.pyc +0 -0
- package/dist/templates/_shared/hooks/__pycache__/file-suggestion.cpython-313.pyc +0 -0
- package/dist/templates/_shared/hooks/__pycache__/pre_compact.cpython-313.pyc +0 -0
- package/dist/templates/_shared/hooks/__pycache__/session_end.cpython-313.pyc +0 -0
- package/dist/templates/_shared/hooks/__pycache__/session_start.cpython-313.pyc +0 -0
- package/dist/templates/_shared/hooks/__pycache__/task_create_atomicity.cpython-313.pyc +0 -0
- package/dist/templates/_shared/hooks/__pycache__/task_create_capture.cpython-313.pyc +0 -0
- package/dist/templates/_shared/hooks/__pycache__/task_update_capture.cpython-313.pyc +0 -0
- package/dist/templates/_shared/hooks/__pycache__/user_prompt_submit.cpython-313.pyc +0 -0
- package/dist/templates/_shared/hooks/archive_plan.py +0 -177
- package/dist/templates/_shared/hooks/context_monitor.py +0 -270
- package/dist/templates/_shared/hooks/file-suggestion.py +0 -215
- package/dist/templates/_shared/hooks/pre_compact.py +0 -104
- package/dist/templates/_shared/hooks/session_end.py +0 -173
- package/dist/templates/_shared/hooks/session_start.py +0 -206
- package/dist/templates/_shared/hooks/task_create_capture.py +0 -108
- package/dist/templates/_shared/hooks/task_update_capture.py +0 -145
- package/dist/templates/_shared/hooks/user_prompt_submit.py +0 -139
- package/dist/templates/_shared/lib/__init__.py +0 -1
- package/dist/templates/_shared/lib/__pycache__/__init__.cpython-313.pyc +0 -0
- package/dist/templates/_shared/lib/base/__init__.py +0 -65
- package/dist/templates/_shared/lib/base/__pycache__/__init__.cpython-313.pyc +0 -0
- package/dist/templates/_shared/lib/base/__pycache__/atomic_write.cpython-313.pyc +0 -0
- package/dist/templates/_shared/lib/base/__pycache__/constants.cpython-313.pyc +0 -0
- package/dist/templates/_shared/lib/base/__pycache__/hook_utils.cpython-313.pyc +0 -0
- package/dist/templates/_shared/lib/base/__pycache__/inference.cpython-313.pyc +0 -0
- package/dist/templates/_shared/lib/base/__pycache__/logger.cpython-313.pyc +0 -0
- package/dist/templates/_shared/lib/base/__pycache__/stop_words.cpython-313.pyc +0 -0
- package/dist/templates/_shared/lib/base/__pycache__/subprocess_utils.cpython-313.pyc +0 -0
- package/dist/templates/_shared/lib/base/__pycache__/utils.cpython-313.pyc +0 -0
- package/dist/templates/_shared/lib/base/atomic_write.py +0 -180
- package/dist/templates/_shared/lib/base/constants.py +0 -358
- package/dist/templates/_shared/lib/base/hook_utils.py +0 -339
- package/dist/templates/_shared/lib/base/inference.py +0 -307
- package/dist/templates/_shared/lib/base/logger.py +0 -305
- package/dist/templates/_shared/lib/base/stop_words.py +0 -221
- package/dist/templates/_shared/lib/base/subprocess_utils.py +0 -46
- package/dist/templates/_shared/lib/base/utils.py +0 -263
- package/dist/templates/_shared/lib/context/__init__.py +0 -102
- package/dist/templates/_shared/lib/context/__pycache__/__init__.cpython-313.pyc +0 -0
- package/dist/templates/_shared/lib/context/__pycache__/cache.cpython-313.pyc +0 -0
- package/dist/templates/_shared/lib/context/__pycache__/context_extractor.cpython-313.pyc +0 -0
- package/dist/templates/_shared/lib/context/__pycache__/context_formatter.cpython-313.pyc +0 -0
- package/dist/templates/_shared/lib/context/__pycache__/context_manager.cpython-313.pyc +0 -0
- package/dist/templates/_shared/lib/context/__pycache__/context_selector.cpython-313.pyc +0 -0
- package/dist/templates/_shared/lib/context/__pycache__/context_store.cpython-313.pyc +0 -0
- package/dist/templates/_shared/lib/context/__pycache__/discovery.cpython-313.pyc +0 -0
- package/dist/templates/_shared/lib/context/__pycache__/event_log.cpython-313.pyc +0 -0
- package/dist/templates/_shared/lib/context/__pycache__/plan_archive.cpython-313.pyc +0 -0
- package/dist/templates/_shared/lib/context/__pycache__/plan_manager.cpython-313.pyc +0 -0
- package/dist/templates/_shared/lib/context/__pycache__/task_sync.cpython-313.pyc +0 -0
- package/dist/templates/_shared/lib/context/__pycache__/task_tracker.cpython-313.pyc +0 -0
- package/dist/templates/_shared/lib/context/context_formatter.py +0 -317
- package/dist/templates/_shared/lib/context/context_selector.py +0 -508
- package/dist/templates/_shared/lib/context/context_store.py +0 -653
- package/dist/templates/_shared/lib/context/plan_manager.py +0 -303
- package/dist/templates/_shared/lib/context/task_tracker.py +0 -188
- package/dist/templates/_shared/lib/handoff/__init__.py +0 -22
- package/dist/templates/_shared/lib/handoff/__pycache__/__init__.cpython-313.pyc +0 -0
- package/dist/templates/_shared/lib/handoff/__pycache__/document_generator.cpython-313.pyc +0 -0
- package/dist/templates/_shared/lib/handoff/document_generator.py +0 -278
- package/dist/templates/_shared/lib/templates/README.md +0 -206
- package/dist/templates/_shared/lib/templates/__init__.py +0 -36
- package/dist/templates/_shared/lib/templates/__pycache__/__init__.cpython-313.pyc +0 -0
- package/dist/templates/_shared/lib/templates/__pycache__/formatters.cpython-313.pyc +0 -0
- package/dist/templates/_shared/lib/templates/__pycache__/persona_questions.cpython-313.pyc +0 -0
- package/dist/templates/_shared/lib/templates/__pycache__/plan_context.cpython-313.pyc +0 -0
- package/dist/templates/_shared/lib/templates/formatters.py +0 -146
- package/dist/templates/_shared/lib/templates/plan_context.py +0 -73
- package/dist/templates/_shared/scripts/__pycache__/save_handoff.cpython-313.pyc +0 -0
- package/dist/templates/_shared/scripts/__pycache__/status_line.cpython-313.pyc +0 -0
- package/dist/templates/_shared/scripts/save_handoff.py +0 -357
- package/dist/templates/_shared/scripts/status_line.py +0 -716
- package/dist/templates/cc-native/.claude/commands/cc-native/fresh-perspective.md +0 -8
- package/dist/templates/cc-native/.windsurf/workflows/cc-native/fresh-perspective.md +0 -8
- package/dist/templates/cc-native/MIGRATION.md +0 -86
- package/dist/templates/cc-native/_cc-native/hooks/__pycache__/add_plan_context.cpython-313.pyc +0 -0
- package/dist/templates/cc-native/_cc-native/hooks/__pycache__/cc-native-plan-review.cpython-313.pyc +0 -0
- package/dist/templates/cc-native/_cc-native/hooks/__pycache__/mark_questions_asked.cpython-313.pyc +0 -0
- package/dist/templates/cc-native/_cc-native/hooks/__pycache__/plan_accepted.cpython-313.pyc +0 -0
- package/dist/templates/cc-native/_cc-native/hooks/__pycache__/plan_questions_early.cpython-313.pyc +0 -0
- package/dist/templates/cc-native/_cc-native/hooks/__pycache__/suggest-fresh-perspective.cpython-313.pyc +0 -0
- package/dist/templates/cc-native/_cc-native/hooks/add_plan_context.py +0 -130
- package/dist/templates/cc-native/_cc-native/hooks/cc-native-plan-review.py +0 -954
- package/dist/templates/cc-native/_cc-native/hooks/plan_questions_early.py +0 -81
- package/dist/templates/cc-native/_cc-native/hooks/suggest-fresh-perspective.py +0 -340
- package/dist/templates/cc-native/_cc-native/lib/CLAUDE.md +0 -265
- package/dist/templates/cc-native/_cc-native/lib/__init__.py +0 -53
- package/dist/templates/cc-native/_cc-native/lib/__pycache__/__init__.cpython-313.pyc +0 -0
- package/dist/templates/cc-native/_cc-native/lib/__pycache__/atomic_write.cpython-313.pyc +0 -0
- package/dist/templates/cc-native/_cc-native/lib/__pycache__/constants.cpython-313.pyc +0 -0
- package/dist/templates/cc-native/_cc-native/lib/__pycache__/debug.cpython-313.pyc +0 -0
- package/dist/templates/cc-native/_cc-native/lib/__pycache__/orchestrator.cpython-313.pyc +0 -0
- package/dist/templates/cc-native/_cc-native/lib/__pycache__/state.cpython-313.pyc +0 -0
- package/dist/templates/cc-native/_cc-native/lib/__pycache__/utils.cpython-313.pyc +0 -0
- package/dist/templates/cc-native/_cc-native/lib/constants.py +0 -45
- package/dist/templates/cc-native/_cc-native/lib/debug.py +0 -139
- package/dist/templates/cc-native/_cc-native/lib/orchestrator.py +0 -362
- package/dist/templates/cc-native/_cc-native/lib/reviewers/__init__.py +0 -28
- package/dist/templates/cc-native/_cc-native/lib/reviewers/__pycache__/__init__.cpython-313.pyc +0 -0
- package/dist/templates/cc-native/_cc-native/lib/reviewers/__pycache__/agent.cpython-313.pyc +0 -0
- package/dist/templates/cc-native/_cc-native/lib/reviewers/__pycache__/base.cpython-313.pyc +0 -0
- package/dist/templates/cc-native/_cc-native/lib/reviewers/__pycache__/codex.cpython-313.pyc +0 -0
- package/dist/templates/cc-native/_cc-native/lib/reviewers/__pycache__/gemini.cpython-313.pyc +0 -0
- package/dist/templates/cc-native/_cc-native/lib/reviewers/agent.py +0 -215
- package/dist/templates/cc-native/_cc-native/lib/reviewers/base.py +0 -88
- package/dist/templates/cc-native/_cc-native/lib/reviewers/codex.py +0 -124
- package/dist/templates/cc-native/_cc-native/lib/reviewers/gemini.py +0 -108
- package/dist/templates/cc-native/_cc-native/lib/state.py +0 -268
- package/dist/templates/cc-native/_cc-native/lib/utils.py +0 -1071
- package/dist/templates/cc-native/_cc-native/scripts/__pycache__/aggregate_agents.cpython-313.pyc +0 -0
- package/dist/templates/cc-native/_cc-native/scripts/aggregate_agents.py +0 -168
- package/dist/templates/cc-native/_cc-native/workflows/fresh-perspective.md +0 -134
|
@@ -6,10 +6,10 @@
|
|
|
6
6
|
* Uses state-io for I/O to avoid circular imports with context-store.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { readStateJson, writeStateJson, toDict } from "../base/state-io.js";
|
|
10
9
|
import { logWarn } from "../base/logger.js";
|
|
10
|
+
import { readStateJson, toDict as _toDict, writeStateJson } from "../base/state-io.js";
|
|
11
11
|
import { nowIso } from "../base/utils.js";
|
|
12
|
-
import type { ContextState, Task } from "../types.js";
|
|
12
|
+
import type { ContextState as _ContextState, Task } from "../types.js";
|
|
13
13
|
|
|
14
14
|
// ---------------------------------------------------------------------------
|
|
15
15
|
// Public API
|
|
@@ -27,7 +27,7 @@ export function generateNextTaskId(contextId: string, projectRoot?: string): str
|
|
|
27
27
|
for (const t of tasks) {
|
|
28
28
|
const match = /^aiw-(\d+)$/.exec(t.id);
|
|
29
29
|
if (match) {
|
|
30
|
-
const num = parseInt(match[1]!, 10);
|
|
30
|
+
const num = Number.parseInt(match[1]!, 10);
|
|
31
31
|
if (num > maxNum) maxNum = num;
|
|
32
32
|
}
|
|
33
33
|
}
|
|
@@ -46,7 +46,7 @@ export function addTask(
|
|
|
46
46
|
activeForm = "",
|
|
47
47
|
sessionId = "",
|
|
48
48
|
projectRoot?: string,
|
|
49
|
-
):
|
|
49
|
+
): null | Task {
|
|
50
50
|
const state = readStateJson(contextId, projectRoot);
|
|
51
51
|
if (!state) return null;
|
|
52
52
|
|
|
@@ -80,11 +80,11 @@ export function updateTask(
|
|
|
80
80
|
contextId: string,
|
|
81
81
|
taskId: string,
|
|
82
82
|
opts?: {
|
|
83
|
-
status?: string;
|
|
84
83
|
evidence?: string;
|
|
85
|
-
work_summary?: string;
|
|
86
84
|
files_changed?: string[];
|
|
87
85
|
session_id?: string;
|
|
86
|
+
status?: string;
|
|
87
|
+
work_summary?: string;
|
|
88
88
|
},
|
|
89
89
|
projectRoot?: string,
|
|
90
90
|
): boolean {
|
|
@@ -99,6 +99,7 @@ export function updateTask(
|
|
|
99
99
|
task.completed_at = nowIso();
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
|
+
|
|
102
103
|
if (opts?.evidence) task.evidence = opts.evidence;
|
|
103
104
|
if (opts?.work_summary) task.work_summary = opts.work_summary;
|
|
104
105
|
if (opts?.files_changed !== undefined) task.files_changed = opts.files_changed;
|
|
@@ -167,12 +168,15 @@ export function generateTaskSummary(contextId: string, projectRoot?: string): st
|
|
|
167
168
|
const ws = t.work_summary ? `\n Work: ${t.work_summary}` : "";
|
|
168
169
|
lines.push(`- [x] ${t.id}: ${t.subject}${ws}`);
|
|
169
170
|
}
|
|
171
|
+
|
|
170
172
|
for (const t of inProgress) {
|
|
171
173
|
lines.push(`- [~] ${t.id}: ${t.subject}`);
|
|
172
174
|
}
|
|
175
|
+
|
|
173
176
|
for (const t of pending) {
|
|
174
177
|
lines.push(`- [ ] ${t.id}: ${t.subject}`);
|
|
175
178
|
}
|
|
179
|
+
|
|
176
180
|
for (const t of blocked) {
|
|
177
181
|
lines.push(`- [!] ${t.id}: ${t.subject}`);
|
|
178
182
|
}
|
|
@@ -6,17 +6,18 @@
|
|
|
6
6
|
* work to a new session (typically due to context window limits).
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
+
import * as crypto from "node:crypto";
|
|
9
10
|
import * as fs from "node:fs";
|
|
10
11
|
import * as path from "node:path";
|
|
11
|
-
|
|
12
|
-
import { getContextHandoffsDir, getContextDir } from "../base/constants.js";
|
|
12
|
+
|
|
13
13
|
import { atomicWrite } from "../base/atomic-write.js";
|
|
14
|
-
import {
|
|
14
|
+
import { getContextDir, getContextHandoffsDir } from "../base/constants.js";
|
|
15
|
+
import { logError, logInfo } from "../base/logger.js";
|
|
15
16
|
import { nowIso } from "../base/utils.js";
|
|
16
|
-
import { getContext, saveState } from "../context/context-store.js";
|
|
17
|
+
import { getContext, saveState as _saveState } from "../context/context-store.js";
|
|
17
18
|
import { getTasks } from "../context/task-tracker.js";
|
|
18
|
-
import {
|
|
19
|
-
import type { HandoffDocument, Task } from "../types.js";
|
|
19
|
+
import { formatContinuationHeader, formatReason, renderTaskList } from "../templates/formatters.js";
|
|
20
|
+
import type { HandoffDocument, Task as _Task } from "../types.js";
|
|
20
21
|
|
|
21
22
|
/**
|
|
22
23
|
* Generate and save a handoff document for a context.
|
|
@@ -124,8 +125,7 @@ function renderHandoffMarkdown(doc: HandoffDocument): string {
|
|
|
124
125
|
);
|
|
125
126
|
|
|
126
127
|
// Active tasks
|
|
127
|
-
lines.push(renderTaskList(doc.active_tasks, "Active Tasks", true).trimEnd());
|
|
128
|
-
lines.push("");
|
|
128
|
+
lines.push(renderTaskList(doc.active_tasks, "Active Tasks", true).trimEnd(), "");
|
|
129
129
|
|
|
130
130
|
// Completed this session
|
|
131
131
|
if (doc.completed_tasks_this_session.length > 0) {
|
|
@@ -133,8 +133,7 @@ function renderHandoffMarkdown(doc: HandoffDocument): string {
|
|
|
133
133
|
doc.completed_tasks_this_session as any[],
|
|
134
134
|
"Completed This Session",
|
|
135
135
|
false,
|
|
136
|
-
).trimEnd());
|
|
137
|
-
lines.push("");
|
|
136
|
+
).trimEnd(), "");
|
|
138
137
|
}
|
|
139
138
|
|
|
140
139
|
// Work summary
|
|
@@ -148,6 +147,7 @@ function renderHandoffMarkdown(doc: HandoffDocument): string {
|
|
|
148
147
|
for (let i = 0; i < doc.next_steps.length; i++) {
|
|
149
148
|
lines.push(`${i + 1}. ${doc.next_steps[i]}`);
|
|
150
149
|
}
|
|
150
|
+
|
|
151
151
|
lines.push("");
|
|
152
152
|
}
|
|
153
153
|
|
|
@@ -157,6 +157,7 @@ function renderHandoffMarkdown(doc: HandoffDocument): string {
|
|
|
157
157
|
for (const note of doc.important_notes) {
|
|
158
158
|
lines.push(`- ${note}`);
|
|
159
159
|
}
|
|
160
|
+
|
|
160
161
|
lines.push("");
|
|
161
162
|
}
|
|
162
163
|
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Handoff reader utilities for programmatic resume.
|
|
3
|
+
*
|
|
4
|
+
* Provides functions to find, read, and parse handoff folders
|
|
5
|
+
* created by save_handoff.ts. Used by resume_handoff.ts script
|
|
6
|
+
* and potentially by session_start hooks.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import * as fs from "node:fs";
|
|
10
|
+
import * as path from "node:path";
|
|
11
|
+
import { getContextHandoffsDir } from "../base/constants.js";
|
|
12
|
+
import { getContext } from "../context/context-store.js";
|
|
13
|
+
import type { HandoffSections } from "../types.js";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Find the most recent handoff folder for a context.
|
|
17
|
+
* Lists subdirectories in the handoffs dir, sorts by name
|
|
18
|
+
* (YYYY-MM-DD-HHMM format ensures lexicographic = chronological).
|
|
19
|
+
* Returns full path to most recent folder, or null.
|
|
20
|
+
*/
|
|
21
|
+
export function findLatestHandoff(contextId: string, projectRoot?: string): string | null {
|
|
22
|
+
const handoffsDir = getContextHandoffsDir(contextId, projectRoot);
|
|
23
|
+
|
|
24
|
+
try {
|
|
25
|
+
if (!fs.existsSync(handoffsDir)) return null;
|
|
26
|
+
const entries = fs.readdirSync(handoffsDir, { withFileTypes: true })
|
|
27
|
+
.filter(e => e.isDirectory())
|
|
28
|
+
.map(e => e.name)
|
|
29
|
+
.sort();
|
|
30
|
+
|
|
31
|
+
if (entries.length === 0) return null;
|
|
32
|
+
return path.join(handoffsDir, entries[entries.length - 1]!);
|
|
33
|
+
} catch {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Read all section files from a handoff folder, structured by priority.
|
|
40
|
+
* Returns content for each file (null if missing/unreadable).
|
|
41
|
+
*/
|
|
42
|
+
export function readHandoffSections(handoffFolder: string): HandoffSections {
|
|
43
|
+
const fileMap: Record<keyof HandoffSections, string> = {
|
|
44
|
+
index: "index.md",
|
|
45
|
+
deadEnds: "dead-ends.md",
|
|
46
|
+
pending: "pending.md",
|
|
47
|
+
plan: "plan.md",
|
|
48
|
+
decisions: "decisions.md",
|
|
49
|
+
completedWork: "completed-work.md",
|
|
50
|
+
context: "context.md",
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const sections: HandoffSections = {
|
|
54
|
+
index: null,
|
|
55
|
+
deadEnds: null,
|
|
56
|
+
pending: null,
|
|
57
|
+
plan: null,
|
|
58
|
+
decisions: null,
|
|
59
|
+
completedWork: null,
|
|
60
|
+
context: null,
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
for (const [key, filename] of Object.entries(fileMap)) {
|
|
64
|
+
const filePath = path.join(handoffFolder, filename);
|
|
65
|
+
try {
|
|
66
|
+
if (fs.existsSync(filePath)) {
|
|
67
|
+
sections[key as keyof HandoffSections] = fs.readFileSync(filePath, "utf-8");
|
|
68
|
+
}
|
|
69
|
+
} catch {
|
|
70
|
+
// graceful — leave as null
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return sections;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Parse the handoff folder name to extract creation timestamp.
|
|
79
|
+
* Expects YYYY-MM-DD-HHMM format (with optional -N suffix for collisions).
|
|
80
|
+
*/
|
|
81
|
+
export function getHandoffTimestamp(handoffFolder: string): Date | null {
|
|
82
|
+
const basename = path.basename(handoffFolder);
|
|
83
|
+
// Match YYYY-MM-DD-HHMM with optional collision suffix
|
|
84
|
+
const match = basename.match(/^(\d{4})-(\d{2})-(\d{2})-(\d{2})(\d{2})/);
|
|
85
|
+
if (!match) return null;
|
|
86
|
+
|
|
87
|
+
const [, year, month, day, hour, minute] = match;
|
|
88
|
+
const date = new Date(
|
|
89
|
+
parseInt(year!, 10),
|
|
90
|
+
parseInt(month!, 10) - 1,
|
|
91
|
+
parseInt(day!, 10),
|
|
92
|
+
parseInt(hour!, 10),
|
|
93
|
+
parseInt(minute!, 10),
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
return isNaN(date.getTime()) ? null : date;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Get the plan path referenced by a handoff.
|
|
101
|
+
* First checks plan.md frontmatter for plan_path, then falls back
|
|
102
|
+
* to the context state's plan_path.
|
|
103
|
+
*/
|
|
104
|
+
export function getHandoffPlanReference(
|
|
105
|
+
handoffFolder: string,
|
|
106
|
+
contextId: string,
|
|
107
|
+
projectRoot?: string,
|
|
108
|
+
): string | null {
|
|
109
|
+
// Try plan.md frontmatter
|
|
110
|
+
const planMdPath = path.join(handoffFolder, "plan.md");
|
|
111
|
+
try {
|
|
112
|
+
if (fs.existsSync(planMdPath)) {
|
|
113
|
+
const content = fs.readFileSync(planMdPath, "utf-8");
|
|
114
|
+
const frontmatter = parseFrontmatter(content);
|
|
115
|
+
if (frontmatter["plan_path"]) {
|
|
116
|
+
const pp = frontmatter["plan_path"];
|
|
117
|
+
if (fs.existsSync(pp)) return pp;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
} catch {
|
|
121
|
+
// fall through to context state
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Fall back to context state
|
|
125
|
+
try {
|
|
126
|
+
const context = getContext(contextId, projectRoot);
|
|
127
|
+
if (context?.plan_path && fs.existsSync(context.plan_path)) {
|
|
128
|
+
return context.plan_path;
|
|
129
|
+
}
|
|
130
|
+
} catch {
|
|
131
|
+
// ignore
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Parse YAML-style frontmatter from markdown content.
|
|
139
|
+
* Returns key-value pairs from the --- block.
|
|
140
|
+
*/
|
|
141
|
+
function parseFrontmatter(content: string): Record<string, string> {
|
|
142
|
+
const frontmatter: Record<string, string> = {};
|
|
143
|
+
if (!content.startsWith("---")) return frontmatter;
|
|
144
|
+
|
|
145
|
+
const parts = content.split("---", 3);
|
|
146
|
+
if (parts.length < 3) return frontmatter;
|
|
147
|
+
|
|
148
|
+
for (const line of parts[1]!.trim().split(/\r?\n/)) {
|
|
149
|
+
const colonIdx = line.indexOf(":");
|
|
150
|
+
if (colonIdx !== -1) {
|
|
151
|
+
const key = line.slice(0, colonIdx).trim();
|
|
152
|
+
const value = line.slice(colonIdx + 1).trim();
|
|
153
|
+
frontmatter[key] = value;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return frontmatter;
|
|
158
|
+
}
|
|
@@ -32,7 +32,7 @@ export function getStatusIcon(status: string): string {
|
|
|
32
32
|
|
|
33
33
|
// §13.3 — Task rendering
|
|
34
34
|
export function renderTaskItem(
|
|
35
|
-
task:
|
|
35
|
+
task: Record<string, any> | Task,
|
|
36
36
|
showDescription = true,
|
|
37
37
|
maxDescriptionLength = 100,
|
|
38
38
|
): string {
|
|
@@ -48,14 +48,16 @@ export function renderTaskItem(
|
|
|
48
48
|
let truncated = description.slice(0, maxDescriptionLength);
|
|
49
49
|
if (description.length > maxDescriptionLength) {
|
|
50
50
|
truncated += "...";
|
|
51
|
-
}
|
|
51
|
+
}
|
|
52
|
+
|
|
52
53
|
return `${line}\n - ${truncated}`;
|
|
53
|
-
}
|
|
54
|
+
}
|
|
55
|
+
|
|
54
56
|
return line;
|
|
55
57
|
}
|
|
56
58
|
|
|
57
59
|
export function renderTaskList(
|
|
58
|
-
tasks: Array<
|
|
60
|
+
tasks: Array<Record<string, any> | Task>,
|
|
59
61
|
header = "Active Tasks",
|
|
60
62
|
showDescription = true,
|
|
61
63
|
): string {
|
|
@@ -5,112 +5,114 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
// §1.1
|
|
8
|
-
export type Mode = "
|
|
8
|
+
export type Mode = "active" | "has_handoff" | "has_plan" | "idle";
|
|
9
9
|
|
|
10
10
|
export interface ContextState {
|
|
11
|
-
id: string;
|
|
12
|
-
status: "active" | "completed";
|
|
13
|
-
summary: string;
|
|
14
|
-
method: string;
|
|
15
|
-
tags: string[];
|
|
16
11
|
created_at: string;
|
|
12
|
+
handoff_consumed: boolean;
|
|
13
|
+
handoff_path: null | string;
|
|
14
|
+
id: string;
|
|
17
15
|
last_active: string;
|
|
16
|
+
last_session: LastSession | null;
|
|
17
|
+
method: string;
|
|
18
18
|
mode: Mode;
|
|
19
|
-
plan_path: string | null;
|
|
20
|
-
plan_hash: string | null;
|
|
21
|
-
plan_signature: string | null;
|
|
22
|
-
plan_id: string | null;
|
|
23
19
|
plan_anchors: string[];
|
|
24
20
|
plan_consumed: boolean;
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
plan_hash: null | string;
|
|
22
|
+
plan_id: null | string;
|
|
23
|
+
plan_path: null | string;
|
|
24
|
+
plan_signature: null | string;
|
|
27
25
|
session_ids: string[];
|
|
28
|
-
|
|
26
|
+
status: "active" | "completed";
|
|
27
|
+
summary: string;
|
|
28
|
+
tags: string[];
|
|
29
29
|
tasks: Task[];
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
// §1.2
|
|
33
33
|
export interface GitState {
|
|
34
34
|
branch?: string;
|
|
35
|
-
uncommitted_files?: string[];
|
|
36
35
|
last_commit_short?: string;
|
|
36
|
+
uncommitted_files?: string[];
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
export interface LastSession {
|
|
40
|
-
session_id?: string;
|
|
41
|
-
saved_at?: string;
|
|
42
|
-
save_reason?: string;
|
|
43
|
-
transcript_path?: string;
|
|
44
40
|
context_remaining_pct?: number;
|
|
41
|
+
context_warnings_fired?: number[];
|
|
45
42
|
git_state?: GitState;
|
|
43
|
+
save_reason?: string;
|
|
44
|
+
saved_at?: string;
|
|
45
|
+
session_id?: string;
|
|
46
|
+
transcript_path?: string;
|
|
46
47
|
}
|
|
47
48
|
|
|
48
49
|
// §1.3
|
|
49
50
|
export interface Task {
|
|
50
|
-
id: string;
|
|
51
|
-
subject: string;
|
|
52
|
-
description: string;
|
|
53
51
|
active_form: string;
|
|
54
|
-
|
|
52
|
+
completed_at: null | string;
|
|
55
53
|
created_at: string;
|
|
56
|
-
|
|
54
|
+
description: string;
|
|
57
55
|
evidence: string;
|
|
58
|
-
work_summary: string;
|
|
59
56
|
files_changed: string[];
|
|
57
|
+
id: string;
|
|
60
58
|
session_id?: string;
|
|
59
|
+
status: "blocked" | "completed" | "in_progress" | "pending";
|
|
60
|
+
subject: string;
|
|
61
|
+
work_summary: string;
|
|
61
62
|
}
|
|
62
63
|
|
|
63
64
|
// §1.4
|
|
64
65
|
export interface IndexEntry {
|
|
65
|
-
summary: string;
|
|
66
|
-
mode: string;
|
|
67
66
|
last_active: string;
|
|
67
|
+
mode: string;
|
|
68
|
+
summary: string;
|
|
68
69
|
}
|
|
69
70
|
|
|
70
71
|
export interface IndexFile {
|
|
71
|
-
version: "3.0";
|
|
72
|
-
updated_at: string;
|
|
73
|
-
sessions: Record<string, string>;
|
|
74
72
|
contexts: Record<string, IndexEntry>;
|
|
73
|
+
sessions: Record<string, string>;
|
|
74
|
+
updated_at: string;
|
|
75
|
+
version: "3.0";
|
|
75
76
|
}
|
|
76
77
|
|
|
77
78
|
// §1.5
|
|
78
79
|
export interface LogEntry {
|
|
79
|
-
ts: string;
|
|
80
|
-
level: "debug" | "info" | "warn" | "error";
|
|
81
|
-
hook: string;
|
|
82
|
-
msg: string;
|
|
83
80
|
component?: string;
|
|
84
81
|
data?: any;
|
|
82
|
+
hook: string;
|
|
83
|
+
level: "debug" | "error" | "info" | "warn";
|
|
84
|
+
msg: string;
|
|
85
85
|
tb?: string;
|
|
86
|
+
ts: string;
|
|
86
87
|
}
|
|
87
88
|
|
|
88
89
|
// §1.6
|
|
89
90
|
export interface HookInput {
|
|
90
|
-
hook_event_name: string;
|
|
91
|
-
tool_name?: string;
|
|
92
|
-
tool_input?: Record<string, any>;
|
|
93
|
-
tool_result?: string;
|
|
94
|
-
session_id?: string;
|
|
95
|
-
cwd?: string;
|
|
96
|
-
transcript_path?: string;
|
|
97
91
|
context_window?: {
|
|
92
|
+
context_window_size?: number;
|
|
98
93
|
current_usage?: {
|
|
94
|
+
cache_creation_input_tokens?: number;
|
|
99
95
|
cache_read_input_tokens?: number;
|
|
100
96
|
input_tokens?: number;
|
|
101
|
-
cache_creation_input_tokens?: number;
|
|
102
97
|
output_tokens?: number;
|
|
103
98
|
};
|
|
104
|
-
context_window_size?: number;
|
|
105
99
|
};
|
|
100
|
+
cwd?: string;
|
|
101
|
+
hook_event_name: string;
|
|
106
102
|
permission_mode?: string;
|
|
103
|
+
session_id?: string;
|
|
107
104
|
source?: string;
|
|
105
|
+
tool_input?: Record<string, any>;
|
|
106
|
+
tool_name?: string;
|
|
107
|
+
tool_result?: string;
|
|
108
|
+
transcript_path?: string;
|
|
108
109
|
}
|
|
109
110
|
|
|
110
111
|
// §1.7
|
|
111
112
|
export interface HookOutput {
|
|
112
113
|
hookSpecificOutput?: {
|
|
113
114
|
additionalContext?: string;
|
|
115
|
+
hookEventName?: string;
|
|
114
116
|
permissionDecision?: "allow" | "deny";
|
|
115
117
|
permissionDecisionReason?: string;
|
|
116
118
|
};
|
|
@@ -118,34 +120,45 @@ export interface HookOutput {
|
|
|
118
120
|
|
|
119
121
|
// §1.8
|
|
120
122
|
export interface InferenceResult {
|
|
121
|
-
success: boolean;
|
|
122
|
-
output: string;
|
|
123
123
|
error?: string;
|
|
124
124
|
latency_ms: number;
|
|
125
|
+
output: string;
|
|
126
|
+
success: boolean;
|
|
125
127
|
}
|
|
126
128
|
|
|
127
129
|
// §1.9
|
|
128
130
|
export interface HandoffDocument {
|
|
131
|
+
active_tasks: Task[];
|
|
132
|
+
completed_tasks_this_session: Array<{ subject: string }>;
|
|
133
|
+
context_folder: string;
|
|
129
134
|
context_id: string;
|
|
130
135
|
context_summary: string;
|
|
131
|
-
session_id: string;
|
|
132
|
-
reason: string;
|
|
133
136
|
created_at: string;
|
|
134
|
-
plan_path: string | null;
|
|
135
|
-
context_folder: string;
|
|
136
137
|
events_log_path: string;
|
|
137
|
-
|
|
138
|
-
completed_tasks_this_session: Array<{ subject: string }>;
|
|
139
|
-
work_summary: string;
|
|
140
|
-
next_steps: string[];
|
|
138
|
+
file_path: null | string;
|
|
141
139
|
important_notes: string[];
|
|
142
|
-
|
|
140
|
+
next_steps: string[];
|
|
141
|
+
plan_path: null | string;
|
|
142
|
+
reason: string;
|
|
143
|
+
session_id: string;
|
|
144
|
+
work_summary: string;
|
|
143
145
|
}
|
|
144
146
|
|
|
145
147
|
// §1.10
|
|
148
|
+
export interface HandoffSections {
|
|
149
|
+
completedWork: null | string;
|
|
150
|
+
context: null | string;
|
|
151
|
+
deadEnds: null | string;
|
|
152
|
+
decisions: null | string;
|
|
153
|
+
index: null | string;
|
|
154
|
+
pending: null | string;
|
|
155
|
+
plan: null | string;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// §1.11
|
|
146
159
|
export interface CaretCommand {
|
|
147
160
|
ends: string[];
|
|
148
|
-
|
|
149
|
-
new_context_desc: string | null;
|
|
161
|
+
new_context_desc: null | string;
|
|
150
162
|
remaining_prompt: string;
|
|
163
|
+
select: null | string;
|
|
151
164
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
/**
|
|
3
|
+
* Resolve and print the active context ID.
|
|
4
|
+
*
|
|
5
|
+
* Usage:
|
|
6
|
+
* bun .aiwcli/_shared/scripts/resolve_context.ts
|
|
7
|
+
*
|
|
8
|
+
* Prints the context ID to stdout. Exits 1 if no active context found.
|
|
9
|
+
* Used by command templates (/handoff, /handoff-resume) to programmatically
|
|
10
|
+
* get the context ID instead of parsing system reminders.
|
|
11
|
+
*/
|
|
12
|
+
import { getProjectRoot } from "../lib-ts/base/constants.js";
|
|
13
|
+
import { eprint } from "../lib-ts/base/utils.js";
|
|
14
|
+
import { findActiveContextId } from "../lib-ts/context/context-store.js";
|
|
15
|
+
|
|
16
|
+
const projectRoot = getProjectRoot(process.cwd());
|
|
17
|
+
const contextId = findActiveContextId(projectRoot);
|
|
18
|
+
|
|
19
|
+
if (!contextId) {
|
|
20
|
+
eprint("No active context found. Handoffs require an active context.");
|
|
21
|
+
process.exit(1);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
console.log(contextId);
|