aiwcli 0.10.2 → 0.11.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/bin/run.js +1 -1
- package/dist/commands/clear.d.ts +11 -6
- package/dist/commands/clear.js +229 -381
- package/dist/commands/init/index.d.ts +1 -17
- package/dist/commands/init/index.js +22 -107
- package/dist/lib/gitignore-manager.d.ts +32 -0
- package/dist/lib/gitignore-manager.js +141 -2
- package/dist/lib/template-installer.d.ts +7 -12
- package/dist/lib/template-installer.js +69 -193
- package/dist/lib/template-settings-reconstructor.d.ts +35 -0
- package/dist/lib/template-settings-reconstructor.js +130 -0
- 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 +104 -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 +138 -0
- package/dist/templates/_shared/lib-ts/base/constants.ts +306 -0
- package/dist/templates/_shared/lib-ts/base/git-state.ts +58 -0
- package/dist/templates/_shared/lib-ts/base/hook-utils.ts +439 -0
- package/dist/templates/_shared/lib-ts/base/inference.ts +252 -0
- package/dist/templates/_shared/lib-ts/base/logger.ts +250 -0
- package/dist/templates/_shared/lib-ts/base/state-io.ts +116 -0
- package/dist/templates/_shared/lib-ts/base/stop-words.ts +184 -0
- package/dist/templates/_shared/lib-ts/base/subprocess-utils.ts +162 -0
- package/dist/templates/_shared/lib-ts/base/utils.ts +184 -0
- package/dist/templates/_shared/lib-ts/context/context-formatter.ts +438 -0
- package/dist/templates/_shared/lib-ts/context/context-selector.ts +515 -0
- package/dist/templates/_shared/lib-ts/context/context-store.ts +707 -0
- package/dist/templates/_shared/lib-ts/context/plan-manager.ts +316 -0
- package/dist/templates/_shared/lib-ts/context/task-tracker.ts +185 -0
- package/dist/templates/_shared/lib-ts/handoff/document-generator.ts +216 -0
- package/dist/templates/_shared/lib-ts/handoff/handoff-reader.ts +159 -0
- package/dist/templates/_shared/lib-ts/package.json +21 -0
- package/dist/templates/_shared/lib-ts/templates/formatters.ts +104 -0
- package/dist/templates/_shared/{lib/templates/plan_context.py → lib-ts/templates/plan-context.ts} +14 -22
- package/dist/templates/_shared/lib-ts/tsconfig.json +13 -0
- package/dist/templates/_shared/lib-ts/types.ts +164 -0
- package/dist/templates/_shared/scripts/resolve_context.ts +24 -0
- package/dist/templates/_shared/scripts/resume_handoff.ts +321 -0
- package/dist/templates/_shared/scripts/save_handoff.ts +359 -0
- package/dist/templates/_shared/scripts/status_line.ts +733 -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/ARCH-EVOLUTION.md +63 -0
- package/dist/templates/cc-native/_cc-native/agents/ARCH-PATTERNS.md +62 -0
- package/dist/templates/cc-native/_cc-native/agents/ARCH-STRUCTURE.md +63 -0
- package/dist/templates/cc-native/_cc-native/agents/{ASSUMPTION-CHAIN-TRACER.md → ASSUMPTION-TRACER.md} +6 -10
- package/dist/templates/cc-native/_cc-native/agents/CLARITY-AUDITOR.md +6 -10
- package/dist/templates/cc-native/_cc-native/agents/CLAUDE.md +74 -3
- package/dist/templates/cc-native/_cc-native/agents/COMPLETENESS-FEASIBILITY.md +67 -0
- package/dist/templates/cc-native/_cc-native/agents/COMPLETENESS-GAPS.md +71 -0
- package/dist/templates/cc-native/_cc-native/agents/COMPLETENESS-ORDERING.md +63 -0
- package/dist/templates/cc-native/_cc-native/agents/CONSTRAINT-VALIDATOR.md +73 -0
- package/dist/templates/cc-native/_cc-native/agents/DESIGN-ADR-VALIDATOR.md +62 -0
- package/dist/templates/cc-native/_cc-native/agents/DESIGN-SCALE-MATCHER.md +65 -0
- package/dist/templates/cc-native/_cc-native/agents/DEVILS-ADVOCATE.md +6 -9
- package/dist/templates/cc-native/_cc-native/agents/DOCUMENTATION-PHILOSOPHY.md +87 -0
- package/dist/templates/cc-native/_cc-native/agents/HANDOFF-READINESS.md +5 -9
- package/dist/templates/cc-native/_cc-native/agents/{HIDDEN-COMPLEXITY-DETECTOR.md → HIDDEN-COMPLEXITY.md} +6 -10
- package/dist/templates/cc-native/_cc-native/agents/INCREMENTAL-DELIVERY.md +67 -0
- package/dist/templates/cc-native/_cc-native/agents/PLAN-ORCHESTRATOR.md +91 -18
- package/dist/templates/cc-native/_cc-native/agents/RISK-DEPENDENCY.md +63 -0
- package/dist/templates/cc-native/_cc-native/agents/RISK-FMEA.md +67 -0
- package/dist/templates/cc-native/_cc-native/agents/RISK-PREMORTEM.md +72 -0
- package/dist/templates/cc-native/_cc-native/agents/RISK-REVERSIBILITY.md +75 -0
- package/dist/templates/cc-native/_cc-native/agents/SCOPE-BOUNDARY.md +78 -0
- package/dist/templates/cc-native/_cc-native/agents/SIMPLICITY-GUARDIAN.md +5 -9
- package/dist/templates/cc-native/_cc-native/agents/SKEPTIC.md +16 -12
- package/dist/templates/cc-native/_cc-native/agents/TESTDRIVEN-BEHAVIOR-AUDITOR.md +62 -0
- package/dist/templates/cc-native/_cc-native/agents/TESTDRIVEN-CHARACTERIZATION.md +72 -0
- package/dist/templates/cc-native/_cc-native/agents/TESTDRIVEN-FIRST-VALIDATOR.md +62 -0
- package/dist/templates/cc-native/_cc-native/agents/TESTDRIVEN-PYRAMID-ANALYZER.md +62 -0
- package/dist/templates/cc-native/_cc-native/agents/TRADEOFF-COSTS.md +68 -0
- package/dist/templates/cc-native/_cc-native/agents/TRADEOFF-STAKEHOLDERS.md +66 -0
- package/dist/templates/cc-native/_cc-native/agents/VERIFY-COVERAGE.md +75 -0
- package/dist/templates/cc-native/_cc-native/agents/VERIFY-STRENGTH.md +70 -0
- 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 +921 -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 +157 -0
- package/dist/templates/cc-native/_cc-native/lib-ts/artifacts.ts +709 -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 +124 -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/debug.ts +80 -0
- package/dist/templates/cc-native/_cc-native/lib-ts/index.ts +119 -0
- package/dist/templates/cc-native/_cc-native/lib-ts/json-parser.ts +162 -0
- package/dist/templates/cc-native/_cc-native/lib-ts/nul +3 -0
- package/dist/templates/cc-native/_cc-native/lib-ts/orchestrator.ts +249 -0
- package/dist/templates/cc-native/_cc-native/lib-ts/reviewers/agent.ts +155 -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 +106 -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 +243 -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 +310 -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 +12 -16
- package/oclif.manifest.json +1 -1
- package/package.json +1 -1
- package/dist/lib/template-merger.d.ts +0 -47
- package/dist/lib/template-merger.js +0 -162
- 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 -169
- 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 -341
- package/dist/templates/_shared/lib/base/inference.py +0 -318
- package/dist/templates/_shared/lib/base/logger.py +0 -291
- package/dist/templates/_shared/lib/base/stop_words.py +0 -213
- package/dist/templates/_shared/lib/base/subprocess_utils.py +0 -46
- package/dist/templates/_shared/lib/base/utils.py +0 -242
- 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 -204
- 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/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 -701
- 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/agents/ACCESSIBILITY-TESTER.md +0 -79
- package/dist/templates/cc-native/_cc-native/agents/ARCHITECT-REVIEWER.md +0 -48
- package/dist/templates/cc-native/_cc-native/agents/CODE-REVIEWER.md +0 -70
- package/dist/templates/cc-native/_cc-native/agents/COMPLETENESS-CHECKER.md +0 -59
- package/dist/templates/cc-native/_cc-native/agents/CONTEXT-EXTRACTOR.md +0 -92
- package/dist/templates/cc-native/_cc-native/agents/DOCUMENTATION-REVIEWER.md +0 -51
- package/dist/templates/cc-native/_cc-native/agents/FEASIBILITY-ANALYST.md +0 -57
- package/dist/templates/cc-native/_cc-native/agents/FRESH-PERSPECTIVE.md +0 -54
- package/dist/templates/cc-native/_cc-native/agents/INCENTIVE-MAPPER.md +0 -61
- package/dist/templates/cc-native/_cc-native/agents/PENETRATION-TESTER.md +0 -79
- package/dist/templates/cc-native/_cc-native/agents/PERFORMANCE-ENGINEER.md +0 -75
- package/dist/templates/cc-native/_cc-native/agents/PRECEDENT-FINDER.md +0 -70
- package/dist/templates/cc-native/_cc-native/agents/REVERSIBILITY-ANALYST.md +0 -61
- package/dist/templates/cc-native/_cc-native/agents/RISK-ASSESSOR.md +0 -58
- package/dist/templates/cc-native/_cc-native/agents/SECOND-ORDER-ANALYST.md +0 -61
- package/dist/templates/cc-native/_cc-native/agents/STAKEHOLDER-ADVOCATE.md +0 -55
- package/dist/templates/cc-native/_cc-native/agents/TRADE-OFF-ILLUMINATOR.md +0 -204
- 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 -869
- 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 -1027
- 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
|
@@ -0,0 +1,438 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Formatting module for context display output.
|
|
3
|
+
* See SPEC.md §11
|
|
4
|
+
*
|
|
5
|
+
* All functions accept a ContextState with fields:
|
|
6
|
+
* id, summary, mode, last_active, plan_path, handoff_path,
|
|
7
|
+
* tasks[], last_session, session_ids, status, method, tags
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import * as fs from "node:fs";
|
|
11
|
+
import * as _path from "node:path";
|
|
12
|
+
|
|
13
|
+
import { parseIsoTimestamp } from "../base/utils.js";
|
|
14
|
+
import type { ContextState, Task } from "../types.js";
|
|
15
|
+
|
|
16
|
+
const MAX_PLAN_INLINE_CHARS = 30_000;
|
|
17
|
+
|
|
18
|
+
// ---------------------------------------------------------------------------
|
|
19
|
+
// Mode display
|
|
20
|
+
// ---------------------------------------------------------------------------
|
|
21
|
+
|
|
22
|
+
const MODE_DISPLAY_MAP: Record<string, string> = {
|
|
23
|
+
idle: "",
|
|
24
|
+
has_plan: "[Plan Ready]",
|
|
25
|
+
has_handoff: "[Handoff Ready]",
|
|
26
|
+
active: "[Active]",
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Get bracketed display string for mode, or empty for idle.
|
|
31
|
+
* See SPEC.md §11.2
|
|
32
|
+
*/
|
|
33
|
+
export function getModeDisplay(mode: string): string {
|
|
34
|
+
return MODE_DISPLAY_MAP[mode] ?? "";
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// ---------------------------------------------------------------------------
|
|
38
|
+
// Time formatting
|
|
39
|
+
// ---------------------------------------------------------------------------
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Format ISO timestamp as '2 hours ago', 'yesterday', etc.
|
|
43
|
+
* See SPEC.md §11.3
|
|
44
|
+
*/
|
|
45
|
+
export function formatRelativeTime(isoTimestamp: null | string): string {
|
|
46
|
+
if (!isoTimestamp) return "unknown";
|
|
47
|
+
|
|
48
|
+
const dt = parseIsoTimestamp(isoTimestamp);
|
|
49
|
+
if (!dt) return isoTimestamp.slice(0, 16);
|
|
50
|
+
|
|
51
|
+
const now = new Date();
|
|
52
|
+
|
|
53
|
+
// Strip timezone info for comparison
|
|
54
|
+
const diffMs = now.getTime() - dt.getTime();
|
|
55
|
+
const diffSec = Math.floor(diffMs / 1000);
|
|
56
|
+
const diffMin = Math.floor(diffSec / 60);
|
|
57
|
+
const diffHours = Math.floor(diffMin / 60);
|
|
58
|
+
const diffDays = Math.floor(diffHours / 24);
|
|
59
|
+
|
|
60
|
+
if (diffDays === 0) {
|
|
61
|
+
if (diffHours === 0) {
|
|
62
|
+
if (diffMin === 0) return "just now";
|
|
63
|
+
return diffMin === 1 ? "1 minute ago" : `${diffMin} minutes ago`;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return diffHours === 1 ? "1 hour ago" : `${diffHours} hours ago`;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (diffDays === 1) return "yesterday";
|
|
70
|
+
if (diffDays < 7) return `${diffDays} days ago`;
|
|
71
|
+
|
|
72
|
+
// Older: show date
|
|
73
|
+
const year = dt.getFullYear();
|
|
74
|
+
const month = String(dt.getMonth() + 1).padStart(2, "0");
|
|
75
|
+
const day = String(dt.getDate()).padStart(2, "0");
|
|
76
|
+
return `${year}-${month}-${day}`;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// ---------------------------------------------------------------------------
|
|
80
|
+
// Internal helpers
|
|
81
|
+
// ---------------------------------------------------------------------------
|
|
82
|
+
|
|
83
|
+
function taskAttr(task: Record<string, any> | Task, key: string, defaultVal = ""): string {
|
|
84
|
+
if (typeof task === "object" && task !== null) {
|
|
85
|
+
return (task as any)[key] ?? defaultVal;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return defaultVal;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function readPlanContent(planPath: string): [null | string, boolean, number] {
|
|
92
|
+
try {
|
|
93
|
+
if (!fs.existsSync(planPath)) return [null, false, 0];
|
|
94
|
+
const content = fs.readFileSync(planPath, "utf8");
|
|
95
|
+
const total = content.length;
|
|
96
|
+
if (total > MAX_PLAN_INLINE_CHARS) {
|
|
97
|
+
return [content.slice(0, MAX_PLAN_INLINE_CHARS), true, total];
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return [content, false, total];
|
|
101
|
+
} catch {
|
|
102
|
+
return [null, false, 0];
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function modeLabel(ctx: ContextState): string {
|
|
107
|
+
const d = getModeDisplay(ctx.mode ?? "idle");
|
|
108
|
+
return d ? d.replaceAll(/^\[|\]$/g, "") : "Active";
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Build restore sections from last_session, tasks, and plan_path.
|
|
113
|
+
* See SPEC.md §11.4
|
|
114
|
+
*/
|
|
115
|
+
export function buildRestoreSections(
|
|
116
|
+
ctx: ContextState,
|
|
117
|
+
projectRoot?: string,
|
|
118
|
+
inlinePlan = false,
|
|
119
|
+
): string {
|
|
120
|
+
const sections: string[] = [];
|
|
121
|
+
const lastSession = ctx.last_session ?? {};
|
|
122
|
+
|
|
123
|
+
if (lastSession) {
|
|
124
|
+
const savedAt = lastSession.saved_at ?? "";
|
|
125
|
+
if (savedAt) {
|
|
126
|
+
const reason = lastSession.save_reason ?? "";
|
|
127
|
+
const reasonDisplay = reason ? reason.replaceAll('_', " ") : "unknown";
|
|
128
|
+
sections.push(`**Last session ended:** ${formatRelativeTime(savedAt)} (${reasonDisplay})`);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const tasks = ctx.tasks ?? [];
|
|
133
|
+
if (tasks.length > 0) {
|
|
134
|
+
const buckets: Record<string, string[]> = {
|
|
135
|
+
completed: [],
|
|
136
|
+
in_progress: [],
|
|
137
|
+
pending: [],
|
|
138
|
+
blocked: [],
|
|
139
|
+
};
|
|
140
|
+
for (const t of tasks) {
|
|
141
|
+
const s = taskAttr(t, "status", "pending");
|
|
142
|
+
if (buckets[s]) {
|
|
143
|
+
buckets[s]!.push(taskAttr(t, "subject"));
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (Object.values(buckets).some(b => b.length > 0)) {
|
|
148
|
+
sections.push("", `### Previous Work (${tasks.length} tasks)`, "");
|
|
149
|
+
const marks: Record<string, string> = {
|
|
150
|
+
completed: "[x]",
|
|
151
|
+
in_progress: "[~]",
|
|
152
|
+
pending: "[ ]",
|
|
153
|
+
blocked: "[!]",
|
|
154
|
+
};
|
|
155
|
+
for (const [status, mark] of Object.entries(marks)) {
|
|
156
|
+
for (const subj of buckets[status] ?? []) {
|
|
157
|
+
sections.push(`- ${mark} ${subj}`);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const planPath = ctx.plan_path;
|
|
164
|
+
if (planPath) {
|
|
165
|
+
if (inlinePlan) {
|
|
166
|
+
const [content, truncated, totalChars] = readPlanContent(planPath);
|
|
167
|
+
if (content) {
|
|
168
|
+
let header = `Plan loaded from: \`${planPath}\``;
|
|
169
|
+
if (truncated) header += ` (truncated, ${totalChars} chars total)`;
|
|
170
|
+
sections.push("", "### Plan", header, "", content);
|
|
171
|
+
if (truncated) {
|
|
172
|
+
sections.push(`\n*Plan truncated at ${MAX_PLAN_INLINE_CHARS} characters. Full plan at: \`${planPath}\`*`);
|
|
173
|
+
}
|
|
174
|
+
} else {
|
|
175
|
+
sections.push("", "### Plan", `*Plan file not found at \`${planPath}\`.*`);
|
|
176
|
+
}
|
|
177
|
+
} else {
|
|
178
|
+
sections.push("", "### Plan", `Read the plan at: \`${planPath}\``);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const gitState = lastSession?.git_state ?? {};
|
|
183
|
+
if (gitState && Object.keys(gitState).length > 0) {
|
|
184
|
+
const branch = gitState.branch ?? "unknown";
|
|
185
|
+
const uncommitted: string[] = gitState.uncommitted_files ?? [];
|
|
186
|
+
const lastCommit = gitState.last_commit_short ?? "";
|
|
187
|
+
let uncStr = uncommitted.length > 0 ? uncommitted.slice(0, 5).join(", ") : "none";
|
|
188
|
+
if (uncommitted.length > 5) uncStr += ` (+${uncommitted.length - 5} more)`;
|
|
189
|
+
sections.push("", "### Git State", `Branch: ${branch} | Uncommitted: ${uncStr}`);
|
|
190
|
+
if (lastCommit) sections.push(`Last commit: ${lastCommit}`);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
return sections.join("\n");
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function resumeBlock(ctx: ContextState, projectRoot: string | undefined, modeText: string, instructions: string[]): string {
|
|
197
|
+
const lines = [
|
|
198
|
+
`## Resuming Context: ${ctx.id}`, "",
|
|
199
|
+
`**Summary:** ${ctx.summary}`,
|
|
200
|
+
`**Mode:** ${modeText}`,
|
|
201
|
+
];
|
|
202
|
+
const restore = buildRestoreSections(ctx, projectRoot, true);
|
|
203
|
+
if (restore) lines.push(restore);
|
|
204
|
+
lines.push("", "---", "", "**Instructions:**", ...instructions);
|
|
205
|
+
return lines.join("\n");
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// ---------------------------------------------------------------------------
|
|
209
|
+
// Public formatters
|
|
210
|
+
// ---------------------------------------------------------------------------
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Format output when resuming a context with a pending handoff.
|
|
214
|
+
* See SPEC.md §11.5
|
|
215
|
+
*/
|
|
216
|
+
export function formatHandoffContinuation(ctx: ContextState, projectRoot?: string): string {
|
|
217
|
+
const handoffPath = ctx.handoff_path ?? "";
|
|
218
|
+
const lines = [
|
|
219
|
+
`## Resuming Context: ${ctx.id} (Handoff Available)`, "",
|
|
220
|
+
`**Summary:** ${ctx.summary}`,
|
|
221
|
+
`**Mode:** Implementing (handoff from previous session)`, "",
|
|
222
|
+
];
|
|
223
|
+
|
|
224
|
+
try {
|
|
225
|
+
if (handoffPath && fs.existsSync(handoffPath)) {
|
|
226
|
+
lines.push("### Previous Session Handoff", "", fs.readFileSync(handoffPath, "utf8"), "");
|
|
227
|
+
} else {
|
|
228
|
+
lines.push(`*Handoff document not found at \`${handoffPath}\`*`, "");
|
|
229
|
+
}
|
|
230
|
+
} catch (error: any) {
|
|
231
|
+
lines.push(`*Handoff document at \`${handoffPath}\` could not be read: ${error}*`, "");
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
const restore = buildRestoreSections(ctx, projectRoot, true);
|
|
235
|
+
if (restore) lines.push(restore);
|
|
236
|
+
|
|
237
|
+
lines.push("", "---", "", "**Instructions:**",
|
|
238
|
+
"1. Review the handoff document above - especially dead ends",
|
|
239
|
+
"2. Check the plan file for remaining tasks",
|
|
240
|
+
"3. Continue implementation from where the previous session left off");
|
|
241
|
+
return lines.join("\n");
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Format output for pending plan implementation (mode=has_plan).
|
|
246
|
+
* See SPEC.md §11.6
|
|
247
|
+
*/
|
|
248
|
+
export function formatPlanContinuation(ctx: ContextState, projectRoot?: string): string {
|
|
249
|
+
return resumeBlock(ctx, projectRoot, "Pending Implementation", [
|
|
250
|
+
"1. Review the plan and previous work above",
|
|
251
|
+
"2. Continue from where the previous session left off",
|
|
252
|
+
]);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Format output for ongoing implementation (mode=active).
|
|
257
|
+
* See SPEC.md §11.7
|
|
258
|
+
*/
|
|
259
|
+
export function formatActiveContinuation(ctx: ContextState, projectRoot?: string): string {
|
|
260
|
+
return resumeBlock(ctx, projectRoot, "Implementing", [
|
|
261
|
+
"1. Review the plan and previous work above",
|
|
262
|
+
"2. Continue from where the previous session left off",
|
|
263
|
+
]);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Format list of contexts for display.
|
|
268
|
+
* See SPEC.md §11.8
|
|
269
|
+
*/
|
|
270
|
+
export function formatContextList(contexts: ContextState[]): string {
|
|
271
|
+
if (contexts.length === 0) return "No active contexts found.";
|
|
272
|
+
|
|
273
|
+
const lines = ["## Active Contexts\n"];
|
|
274
|
+
for (const [i, context_] of contexts.entries()) {
|
|
275
|
+
const ctx = context_!;
|
|
276
|
+
const timeStr = formatRelativeTime(ctx.last_active);
|
|
277
|
+
const md = getModeDisplay(ctx.mode ?? "idle");
|
|
278
|
+
const si = md ? ` ${md}` : "";
|
|
279
|
+
lines.push(`**${i + 1}. ${ctx.id}**${si}`, ` ${ctx.summary}`);
|
|
280
|
+
if (ctx.method) {
|
|
281
|
+
lines.push(` Method: ${ctx.method} | Last active: ${timeStr}`);
|
|
282
|
+
} else {
|
|
283
|
+
lines.push(` Last active: ${timeStr}`);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
lines.push("");
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
return lines.join("\n");
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Format notification for a newly created context.
|
|
294
|
+
* See SPEC.md §11.9
|
|
295
|
+
*/
|
|
296
|
+
export function formatContextCreated(ctx: ContextState): string {
|
|
297
|
+
return [
|
|
298
|
+
`## Context Created: ${ctx.id}`, "",
|
|
299
|
+
`**Summary:** ${ctx.summary}`, "",
|
|
300
|
+
"A new context has been created for this work.",
|
|
301
|
+
"Tasks created with TaskCreate will be persisted to this context.",
|
|
302
|
+
].join("\n");
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Format system reminder: lightweight (per-prompt) or rich (first-bind restore).
|
|
307
|
+
* See SPEC.md §11.10
|
|
308
|
+
*/
|
|
309
|
+
export function formatActiveContextReminder(
|
|
310
|
+
ctx: ContextState,
|
|
311
|
+
projectRoot?: string,
|
|
312
|
+
includeRestore = false,
|
|
313
|
+
): string {
|
|
314
|
+
const timeStr = formatRelativeTime(ctx.last_active);
|
|
315
|
+
const label = modeLabel(ctx);
|
|
316
|
+
|
|
317
|
+
if (includeRestore) {
|
|
318
|
+
const lines = [
|
|
319
|
+
`## Resuming Context: ${ctx.id}`, "",
|
|
320
|
+
`**Summary:** ${ctx.summary}`,
|
|
321
|
+
`**Mode:** ${label}`,
|
|
322
|
+
];
|
|
323
|
+
const restore = buildRestoreSections(ctx, projectRoot, true);
|
|
324
|
+
if (restore) lines.push(restore);
|
|
325
|
+
lines.push("", "---", "", "**Instructions:**",
|
|
326
|
+
"1. Review the previous work above",
|
|
327
|
+
"2. Continue from where the previous session left off");
|
|
328
|
+
return lines.join("\n");
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
return [
|
|
332
|
+
`## Active Context: ${ctx.id}`, "",
|
|
333
|
+
`**Summary:** ${ctx.summary}`,
|
|
334
|
+
`**Mode:** ${label}`,
|
|
335
|
+
`**Last Active:** ${timeStr}`, "",
|
|
336
|
+
`All work belongs to context "${ctx.id}".`,
|
|
337
|
+
"Tasks created with TaskCreate will be persisted to this context.",
|
|
338
|
+
].join("\n");
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
// ---------------------------------------------------------------------------
|
|
342
|
+
// Picker / command feedback
|
|
343
|
+
// ---------------------------------------------------------------------------
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Format the boxed picker shown on stderr when blocking for selection.
|
|
347
|
+
* See SPEC.md §11.11
|
|
348
|
+
*/
|
|
349
|
+
export function formatContextPickerStderr(contexts: ContextState[]): string {
|
|
350
|
+
const lines = [
|
|
351
|
+
"",
|
|
352
|
+
"+----------------------------------------------------------------+",
|
|
353
|
+
"| CONTEXT SELECTION REQUIRED |",
|
|
354
|
+
"+----------------------------------------------------------------+",
|
|
355
|
+
];
|
|
356
|
+
|
|
357
|
+
let selectableCount = 0;
|
|
358
|
+
for (const [i, context_] of contexts.entries()) {
|
|
359
|
+
const ctx = context_!;
|
|
360
|
+
const timeStr = formatRelativeTime(ctx.last_active);
|
|
361
|
+
const mode = ctx.mode ?? "idle";
|
|
362
|
+
const isSelectable = mode === "active" || Boolean(ctx.handoff_path);
|
|
363
|
+
if (isSelectable) selectableCount++;
|
|
364
|
+
|
|
365
|
+
let status = "";
|
|
366
|
+
if (ctx.handoff_path) {
|
|
367
|
+
status = " [Handoff Ready]";
|
|
368
|
+
} else if (getModeDisplay(mode)) {
|
|
369
|
+
status = ` ${getModeDisplay(mode)}`;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
const summary = ctx.summary.length > 48 ? ctx.summary.slice(0, 45) + "..." : ctx.summary;
|
|
373
|
+
const selTag = isSelectable ? " [selectable]" : " [end only]";
|
|
374
|
+
|
|
375
|
+
lines.push(`| ^${i + 1} ${ctx.id}${status}${selTag}`, `| ${summary}`, `| [${timeStr}]`, "|");
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
lines.push(
|
|
379
|
+
"+----------------------------------------------------------------+",
|
|
380
|
+
"| Usage: |",
|
|
381
|
+
"| ^S<N> - Select context by number |",
|
|
382
|
+
"| ^E<N> - End/complete context by number |",
|
|
383
|
+
"| ^S:query - Select by ID match (race-safe) |",
|
|
384
|
+
"| ^E:query - End by ID match (race-safe) |",
|
|
385
|
+
"| ^E<N>+ - End context N and all after |",
|
|
386
|
+
"| ^E* - End ALL contexts |",
|
|
387
|
+
"| ^E1E2S3 - End #1 and #2, select #3 |",
|
|
388
|
+
"| ^E:fooS:bar - End 'foo...', select 'bar...' |",
|
|
389
|
+
"| ^0 work description - Create new context (10+ chars) |",
|
|
390
|
+
"+----------------------------------------------------------------+",
|
|
391
|
+
);
|
|
392
|
+
|
|
393
|
+
if (selectableCount === 0) {
|
|
394
|
+
lines.push(
|
|
395
|
+
"| NOTE: No selectable contexts. |",
|
|
396
|
+
"| Use ^E<N> to end old contexts, then ^0 to create new. |",
|
|
397
|
+
"+----------------------------------------------------------------+",
|
|
398
|
+
);
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
lines.push("");
|
|
402
|
+
return lines.join("\n");
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
/**
|
|
406
|
+
* Format feedback about caret command operations performed.
|
|
407
|
+
* See SPEC.md §11.12
|
|
408
|
+
*/
|
|
409
|
+
export function formatCommandFeedback(
|
|
410
|
+
endedContexts: ContextState[],
|
|
411
|
+
selectedContext: ContextState | null,
|
|
412
|
+
): string {
|
|
413
|
+
const lines: string[] = [];
|
|
414
|
+
if (endedContexts.length > 0) {
|
|
415
|
+
lines.push("## Contexts Ended", "");
|
|
416
|
+
for (const ctx of endedContexts) {
|
|
417
|
+
const s = ctx.summary.length > 50 ? ctx.summary.slice(0, 50) + "..." : ctx.summary;
|
|
418
|
+
lines.push(`- **${ctx.id}**: ${s}`);
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
lines.push("");
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
if (selectedContext) {
|
|
425
|
+
const label = modeLabel(selectedContext);
|
|
426
|
+
const timeStr = formatRelativeTime(selectedContext.last_active);
|
|
427
|
+
lines.push(
|
|
428
|
+
`## Active Context: ${selectedContext.id}`, "",
|
|
429
|
+
`**Summary:** ${selectedContext.summary}`,
|
|
430
|
+
`**Mode:** ${label}`,
|
|
431
|
+
`**Last Active:** ${timeStr}`, "",
|
|
432
|
+
`All work belongs to context "${selectedContext.id}".`,
|
|
433
|
+
"Tasks created with TaskCreate will be persisted to this context.",
|
|
434
|
+
);
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
return lines.join("\n");
|
|
438
|
+
}
|