aiwcli 0.15.5 → 0.15.7
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 +6 -3
- package/dist/capabilities/branch/adapters.d.ts +2 -0
- package/dist/capabilities/branch/adapters.js +21 -0
- package/dist/capabilities/branch/contracts.d.ts +57 -0
- package/dist/capabilities/branch/contracts.js +1 -0
- package/dist/capabilities/branch/control-plane.d.ts +2 -0
- package/dist/capabilities/branch/control-plane.js +343 -0
- package/dist/capabilities/branch/runtime-core.d.ts +5 -0
- package/dist/capabilities/branch/runtime-core.js +36 -0
- package/dist/capabilities/installation/control-plane/clean-command.d.ts +41 -0
- package/dist/capabilities/installation/control-plane/clean-command.js +196 -0
- package/dist/capabilities/installation/control-plane/clear-command.d.ts +160 -0
- package/dist/capabilities/installation/control-plane/clear-command.js +1220 -0
- package/dist/capabilities/installation/control-plane/init-command.d.ts +81 -0
- package/dist/capabilities/installation/control-plane/init-command.js +449 -0
- package/dist/capabilities/launch/contracts.d.ts +51 -0
- package/dist/capabilities/launch/contracts.js +1 -0
- package/dist/capabilities/launch/control-plane/execute-launch.d.ts +2 -0
- package/dist/capabilities/launch/control-plane/execute-launch.js +222 -0
- package/dist/capabilities/launch/runtime-core/launch-options.d.ts +14 -0
- package/dist/capabilities/launch/runtime-core/launch-options.js +69 -0
- package/dist/cli/base-command.d.ts +18 -0
- package/dist/cli/base-command.js +55 -0
- package/dist/commands/branch.d.ts +0 -20
- package/dist/commands/branch.js +24 -416
- package/dist/commands/clean.d.ts +1 -41
- package/dist/commands/clean.js +1 -196
- package/dist/commands/clear.d.ts +1 -161
- package/dist/commands/clear.js +1 -1121
- package/dist/commands/init/index.d.ts +1 -98
- package/dist/commands/init/index.js +4 -478
- package/dist/commands/launch.d.ts +36 -11
- package/dist/commands/launch.js +135 -159
- package/dist/lib/base-command.d.ts +1 -114
- package/dist/lib/base-command.js +1 -153
- package/dist/lib/claude-settings-types.d.ts +31 -19
- package/dist/lib/context/context-formatter.d.ts +74 -0
- package/dist/lib/context/context-formatter.js +493 -0
- package/dist/lib/context/context-selector.d.ts +42 -0
- package/dist/lib/context/context-selector.js +451 -0
- package/dist/lib/context/context-store.d.ts +100 -0
- package/dist/lib/context/context-store.js +618 -0
- package/dist/lib/context/plan-manager.d.ts +54 -0
- package/dist/lib/context/plan-manager.js +282 -0
- package/dist/lib/context/task-tracker.d.ts +44 -0
- package/dist/lib/context/task-tracker.js +146 -0
- package/dist/lib/core-ide-base.d.ts +4 -0
- package/dist/lib/core-ide-base.js +77 -0
- package/dist/lib/core-installer.d.ts +5 -0
- package/dist/lib/core-installer.js +54 -0
- package/dist/lib/git-exclude-manager.d.ts +2 -2
- package/dist/lib/git-exclude-manager.js +3 -3
- package/dist/lib/hooks/hook-utils.d.ts +143 -0
- package/dist/lib/hooks/hook-utils.js +609 -0
- package/dist/lib/hooks/session-end-logic.d.ts +5 -0
- package/dist/lib/hooks/session-end-logic.js +63 -0
- package/dist/lib/hooks-merger.js +25 -19
- package/dist/lib/ide-path-resolver.d.ts +19 -7
- package/dist/lib/ide-path-resolver.js +25 -9
- package/dist/lib/install-state.d.ts +34 -0
- package/dist/lib/install-state.js +161 -0
- package/dist/lib/launch-options.d.ts +1 -0
- package/dist/lib/launch-options.js +1 -0
- package/dist/lib/lsp-patch.d.ts +12 -0
- package/dist/lib/lsp-patch.js +156 -0
- package/dist/lib/multiplexer.d.ts +57 -0
- package/dist/lib/multiplexer.js +19 -0
- package/dist/lib/multiplexers/psmux.d.ts +75 -0
- package/dist/lib/multiplexers/psmux.js +384 -0
- package/dist/lib/multiplexers/tmux.d.ts +44 -0
- package/dist/lib/multiplexers/tmux.js +262 -0
- package/dist/lib/mux-utils.d.ts +5 -0
- package/dist/lib/mux-utils.js +42 -0
- package/dist/lib/paths.d.ts +2 -2
- package/dist/lib/paths.js +2 -2
- package/dist/lib/platform-commands.d.ts +27 -0
- package/dist/lib/platform-commands.js +49 -0
- package/dist/lib/runtime/aiw-cli.d.ts +37 -0
- package/dist/lib/runtime/aiw-cli.js +74 -0
- package/dist/lib/runtime/atomic-write.d.ts +19 -0
- package/dist/lib/runtime/atomic-write.js +121 -0
- package/dist/lib/runtime/cli-args.d.ts +55 -0
- package/dist/lib/runtime/cli-args.js +185 -0
- package/dist/lib/runtime/constants.d.ts +56 -0
- package/dist/lib/runtime/constants.js +230 -0
- package/dist/lib/runtime/executable-policy.d.ts +16 -0
- package/dist/lib/runtime/executable-policy.js +57 -0
- package/dist/lib/runtime/git-state.d.ts +9 -0
- package/dist/lib/runtime/git-state.js +59 -0
- package/dist/lib/runtime/inference.d.ts +37 -0
- package/dist/lib/runtime/inference.js +262 -0
- package/dist/lib/runtime/lint-dispatch.d.ts +40 -0
- package/dist/lib/runtime/lint-dispatch.js +285 -0
- package/dist/lib/runtime/logger.d.ts +66 -0
- package/dist/lib/runtime/logger.js +201 -0
- package/dist/lib/runtime/models.d.ts +14 -0
- package/dist/lib/runtime/models.js +14 -0
- package/dist/lib/runtime/platform-adapter.d.ts +7 -0
- package/dist/lib/runtime/platform-adapter.js +21 -0
- package/dist/lib/runtime/preflight.d.ts +24 -0
- package/dist/lib/runtime/preflight.js +65 -0
- package/dist/lib/runtime/sentinel-ipc.d.ts +14 -0
- package/dist/lib/runtime/sentinel-ipc.js +67 -0
- package/dist/lib/runtime/state-io.d.ts +30 -0
- package/dist/lib/runtime/state-io.js +174 -0
- package/dist/lib/runtime/stop-words.d.ts +20 -0
- package/dist/lib/runtime/stop-words.js +150 -0
- package/dist/lib/runtime/subprocess-utils.d.ts +29 -0
- package/dist/lib/runtime/subprocess-utils.js +96 -0
- package/dist/lib/runtime/tmux-preflight.d.ts +13 -0
- package/dist/lib/runtime/tmux-preflight.js +78 -0
- package/dist/lib/runtime/utils.d.ts +54 -0
- package/dist/lib/runtime/utils.js +162 -0
- package/dist/lib/sentinel-wrapper.d.ts +9 -0
- package/dist/lib/sentinel-wrapper.js +20 -0
- package/dist/lib/shell-quoting.d.ts +5 -0
- package/dist/lib/shell-quoting.js +17 -0
- package/dist/lib/spawn-errors.d.ts +6 -0
- package/dist/lib/spawn-errors.js +15 -0
- package/dist/lib/spawn.js +5 -11
- package/dist/lib/template-installer.d.ts +4 -5
- package/dist/lib/template-installer.js +36 -34
- package/dist/lib/template-resolver.d.ts +6 -7
- package/dist/lib/template-resolver.js +26 -21
- package/dist/lib/template-settings-reconstructor.d.ts +7 -2
- package/dist/lib/template-settings-reconstructor.js +76 -45
- package/dist/lib/terminal-strategy.d.ts +11 -0
- package/dist/lib/terminal-strategy.js +49 -0
- package/dist/lib/terminal.d.ts +28 -0
- package/dist/lib/terminal.js +162 -112
- package/dist/lib/tmux-pane-placement.d.ts +17 -0
- package/dist/lib/tmux-pane-placement.js +58 -0
- package/dist/lib/tmux-primitives.d.ts +5 -0
- package/dist/lib/tmux-primitives.js +15 -0
- package/dist/lib/tmux-session.d.ts +32 -0
- package/dist/lib/tmux-session.js +86 -0
- package/dist/lib/tty-detection.js +1 -1
- package/dist/lib/types.d.ts +168 -0
- package/dist/lib/types.js +6 -0
- package/dist/lib/version.d.ts +1 -1
- package/dist/lib/version.js +1 -1
- package/dist/platform/launch.d.ts +10 -0
- package/dist/platform/launch.js +10 -0
- package/dist/templates/CLAUDE.md +31 -40
- package/dist/templates/cc-native/.claude/settings.json +27 -27
- package/dist/templates/cc-native/CC-NATIVE-README.md +1 -1
- package/dist/templates/cc-native/TEMPLATE-SCHEMA.md +10 -9
- package/dist/templates/cc-native/_cc-native/CLAUDE.md +18 -18
- package/dist/templates/cc-native/_cc-native/artifacts/CLAUDE.md +3 -3
- package/dist/templates/cc-native/_cc-native/artifacts/lib/format.ts +14 -14
- package/dist/templates/cc-native/_cc-native/artifacts/lib/tracker.ts +1 -1
- package/dist/templates/cc-native/_cc-native/artifacts/lib/write.ts +3 -3
- package/dist/templates/cc-native/_cc-native/cc-native.config.json +3 -3
- package/dist/templates/cc-native/_cc-native/hooks/CLAUDE.md +16 -15
- package/dist/templates/cc-native/_cc-native/hooks/cc-native-plan-review.ts +3 -3
- package/dist/templates/cc-native/_cc-native/hooks/enhance_plan_post_subagent.ts +2 -2
- package/dist/templates/cc-native/_cc-native/hooks/enhance_plan_post_write.ts +2 -2
- package/dist/templates/cc-native/_cc-native/hooks/mark_questions_asked.ts +3 -3
- package/dist/templates/cc-native/_cc-native/hooks/plan_questions_early.ts +2 -2
- package/dist/templates/cc-native/_cc-native/hooks/validate_task_prompt.ts +3 -3
- package/dist/templates/cc-native/_cc-native/lib-ts/CLAUDE.md +8 -8
- package/dist/templates/cc-native/_cc-native/lib-ts/aggregate-agents.ts +1 -1
- package/dist/templates/cc-native/_cc-native/lib-ts/cc-native-state.ts +4 -4
- package/dist/templates/cc-native/_cc-native/lib-ts/cli-output-parser.ts +1 -1
- package/dist/templates/cc-native/_cc-native/lib-ts/config.ts +1 -1
- package/dist/templates/cc-native/_cc-native/lib-ts/debug.ts +1 -1
- package/dist/templates/cc-native/_cc-native/lib-ts/json-parser.ts +1 -1
- package/dist/templates/cc-native/_cc-native/lib-ts/plan-discovery.ts +2 -2
- package/dist/templates/cc-native/_cc-native/lib-ts/rlm/logger.ts +1 -1
- package/dist/templates/cc-native/_cc-native/lib-ts/rlm/retrieval-pipeline.ts +2 -2
- package/dist/templates/cc-native/_cc-native/lib-ts/rlm/types.ts +1 -1
- package/dist/templates/cc-native/_cc-native/lib-ts/settings.ts +8 -8
- package/dist/templates/cc-native/_cc-native/lib-ts/state.ts +3 -3
- package/dist/templates/cc-native/_cc-native/lib-ts/tsconfig.json +2 -2
- package/dist/templates/cc-native/_cc-native/lib-ts/types.ts +3 -3
- package/dist/templates/cc-native/_cc-native/plan-review/CLAUDE.md +3 -1
- package/dist/templates/cc-native/_cc-native/plan-review/lib/__tests__/agent-selection.test.ts +345 -0
- package/dist/templates/cc-native/_cc-native/plan-review/lib/__tests__/preflight.test.ts +344 -0
- package/dist/templates/cc-native/_cc-native/plan-review/lib/agent-selection.ts +37 -15
- package/dist/templates/cc-native/_cc-native/plan-review/lib/corroboration.ts +16 -69
- package/dist/templates/cc-native/_cc-native/plan-review/lib/orchestrator.ts +1 -1
- package/dist/templates/cc-native/_cc-native/plan-review/lib/output-builder.ts +1 -1
- package/dist/templates/cc-native/_cc-native/plan-review/lib/plan-questions.ts +2 -2
- package/dist/templates/cc-native/_cc-native/plan-review/lib/preflight.ts +56 -26
- package/dist/templates/cc-native/_cc-native/plan-review/lib/review-pipeline.ts +7 -7
- package/dist/templates/cc-native/_cc-native/plan-review/lib/reviewers/agent.ts +4 -4
- package/dist/templates/cc-native/_cc-native/plan-review/lib/reviewers/base/base-agent.ts +3 -3
- package/dist/templates/cc-native/_cc-native/plan-review/lib/reviewers/index.ts +1 -1
- package/dist/templates/cc-native/_cc-native/plan-review/lib/reviewers/providers/claude-agent.ts +2 -2
- package/dist/templates/cc-native/_cc-native/plan-review/lib/reviewers/providers/codex-agent.ts +4 -4
- package/dist/templates/cc-native/_cc-native/plan-review/lib/reviewers/providers/gemini-agent.ts +1 -1
- package/dist/templates/cc-native/_cc-native/plan-review/lib/reviewers/providers/orchestrator-claude-agent.ts +5 -6
- package/dist/templates/core/.codex/workflows/codex.md +17 -0
- package/dist/templates/core/.codex/workflows/handoff.md +5 -0
- package/dist/templates/core/.codex/workflows/meta-plan.md +7 -0
- package/dist/templates/core/.cognition/AGENTS.md +5 -0
- package/dist/templates/core/.cognition/config.json +12 -0
- package/dist/templates/{_shared → core}/.windsurf/workflows/handoff.md +1 -1
- package/dist/templates/{_shared → core}/.windsurf/workflows/meta-plan.md +1 -1
- package/dist/templates/core/hooks-ts/_utils/git-state.ts +2 -0
- package/dist/templates/{_shared → core}/hooks-ts/archive_plan.ts +14 -23
- package/dist/templates/core/hooks-ts/codex_explorer.ts +160 -0
- package/dist/templates/{_shared → core}/hooks-ts/context_monitor.ts +23 -55
- package/dist/templates/{_shared → core}/hooks-ts/file-suggestion.ts +4 -3
- package/dist/templates/{_shared → core}/hooks-ts/lint_after_edit.ts +7 -9
- package/dist/templates/{_shared → core}/hooks-ts/pre_compact.ts +5 -5
- package/dist/templates/{_shared → core}/hooks-ts/session_end.ts +38 -78
- package/dist/templates/{_shared → core}/hooks-ts/session_start.ts +5 -5
- package/dist/templates/core/hooks-ts/task_create_capture.ts +32 -0
- package/dist/templates/{_shared → core}/hooks-ts/task_update_capture.ts +9 -24
- package/dist/templates/core/hooks-ts/user_prompt_submit.ts +46 -0
- package/dist/templates/{_shared → core}/lib-ts/CLAUDE.md +27 -16
- package/dist/templates/{_shared → core}/lib-ts/agent-exec/backends/headless.ts +3 -2
- package/dist/templates/{_shared → core}/lib-ts/agent-exec/backends/tmux.ts +44 -15
- package/dist/templates/{_shared → core}/lib-ts/agent-exec/base-agent.ts +6 -4
- package/dist/templates/{_shared → core}/lib-ts/agent-exec/execution-backend.ts +1 -1
- package/dist/templates/{_shared → core}/lib-ts/agent-exec/index.ts +2 -2
- package/dist/templates/{_shared → core}/lib-ts/agent-exec/structured-output.ts +4 -5
- package/dist/templates/{_shared → core}/lib-ts/context/CLAUDE.md +9 -6
- package/dist/templates/{_shared → core}/lib-ts/context/context-formatter.ts +16 -21
- package/dist/templates/{_shared → core}/lib-ts/context/context-selector.ts +8 -6
- package/dist/templates/{_shared → core}/lib-ts/context/context-store.ts +32 -20
- package/dist/templates/{_shared → core}/lib-ts/context/plan-manager.ts +19 -15
- package/dist/templates/{_shared → core}/lib-ts/context/task-tracker.ts +3 -3
- package/dist/templates/core/lib-ts/hooks/context-monitor-logic.ts +32 -0
- package/dist/templates/{_shared/lib-ts/base → core/lib-ts/hooks}/hook-utils.ts +168 -41
- package/dist/templates/core/lib-ts/hooks/prompt-binding-logic.ts +80 -0
- package/dist/templates/core/lib-ts/hooks/session-end-logic.ts +93 -0
- package/dist/templates/core/lib-ts/package.json +19 -0
- package/dist/templates/core/lib-ts/runtime/agent-launcher.ts +295 -0
- package/dist/templates/core/lib-ts/runtime/aiw-cli.ts +106 -0
- package/dist/templates/{_shared/lib-ts/base → core/lib-ts/runtime}/atomic-write.ts +12 -7
- package/dist/templates/{_shared/lib-ts/base → core/lib-ts/runtime}/cli-args.ts +8 -6
- package/dist/templates/{_shared/lib-ts/base → core/lib-ts/runtime}/constants.ts +326 -324
- package/dist/templates/core/lib-ts/runtime/executable-policy.ts +89 -0
- package/dist/templates/{_shared/lib-ts/base → core/lib-ts/runtime}/git-state.ts +6 -4
- package/dist/templates/{_shared/lib-ts/base → core/lib-ts/runtime}/inference.ts +59 -10
- package/dist/templates/{_shared/lib-ts/base → core/lib-ts/runtime}/lint-dispatch.ts +25 -23
- package/dist/templates/{_shared/lib-ts/base → core/lib-ts/runtime}/logger.ts +32 -29
- package/dist/templates/{_shared/lib-ts/base → core/lib-ts/runtime}/models.ts +2 -2
- package/dist/templates/core/lib-ts/runtime/platform-adapter.ts +33 -0
- package/dist/templates/{_shared/lib-ts/base → core/lib-ts/runtime}/preflight.ts +4 -3
- package/dist/templates/core/lib-ts/runtime/sentinel-ipc.ts +91 -0
- package/dist/templates/{_shared/lib-ts/base → core/lib-ts/runtime}/state-io.ts +11 -7
- package/dist/templates/core/lib-ts/runtime/stop-words.ts +185 -0
- package/dist/templates/core/lib-ts/runtime/subprocess-utils.ts +147 -0
- package/dist/templates/core/lib-ts/runtime/tmux-preflight.ts +93 -0
- package/dist/templates/{_shared/lib-ts/base → core/lib-ts/runtime}/utils.ts +4 -3
- package/dist/templates/{_shared → core}/lib-ts/templates/formatters.ts +7 -5
- package/dist/templates/{_shared → core}/lib-ts/templates/plan-context.ts +2 -1
- package/dist/templates/{_shared → core}/lib-ts/tsconfig.json +3 -1
- package/dist/templates/{_shared → core}/lib-ts/types.ts +78 -77
- package/dist/templates/core/scripts/resolve-run.ts +61 -0
- package/dist/templates/{_shared → core}/scripts/resolve_context.ts +3 -3
- package/dist/templates/{_shared → core}/scripts/status_line.ts +25 -20
- package/dist/templates/core/skills/codex/CLAUDE.md +78 -0
- package/dist/templates/{_shared → core}/skills/codex/SKILL.md +21 -18
- package/dist/templates/{_shared → core}/skills/codex/lib/codex-watcher.ts +76 -103
- package/dist/templates/{_shared → core}/skills/codex/scripts/launch-codex.ts +119 -133
- package/dist/templates/{_shared → core}/skills/codex/scripts/watch-codex.ts +6 -4
- package/dist/templates/core/skills/devin/CLAUDE.md +65 -0
- package/dist/templates/core/skills/devin/SKILL.md +73 -0
- package/dist/templates/core/skills/devin/lib/devin-watcher.ts +280 -0
- package/dist/templates/core/skills/devin/scripts/launch-devin.ts +257 -0
- package/dist/templates/{_shared → core}/skills/handoff-system/CLAUDE.md +436 -433
- package/dist/templates/{_shared → core}/skills/handoff-system/lib/document-generator.ts +9 -7
- package/dist/templates/{_shared → core}/skills/handoff-system/lib/handoff-reader.ts +6 -4
- package/dist/templates/{_shared → core}/skills/handoff-system/scripts/resume_handoff.ts +10 -8
- package/dist/templates/{_shared → core}/skills/handoff-system/scripts/save_handoff.ts +12 -10
- package/dist/templates/{_shared → core}/skills/handoff-system/workflows/handoff-resume.md +2 -2
- package/dist/templates/{_shared → core}/skills/handoff-system/workflows/handoff.md +6 -5
- package/dist/templates/{_shared → core}/skills/meta-plan/CLAUDE.md +2 -1
- package/dist/templates/{_shared → core}/skills/meta-plan/workflows/meta-plan.md +8 -7
- package/oclif.manifest.json +89 -13
- package/package.json +13 -12
- package/dist/templates/_shared/.claude/settings.json +0 -120
- package/dist/templates/_shared/.claude/skills/codex/SKILL.md +0 -35
- package/dist/templates/_shared/.claude/skills/handoff/SKILL.md +0 -13
- package/dist/templates/_shared/.claude/skills/handoff-resume/SKILL.md +0 -13
- package/dist/templates/_shared/.claude/skills/meta-plan/SKILL.md +0 -43
- package/dist/templates/_shared/.codex/workflows/codex.md +0 -11
- package/dist/templates/_shared/.codex/workflows/handoff.md +0 -226
- package/dist/templates/_shared/.codex/workflows/meta-plan.md +0 -347
- package/dist/templates/_shared/hooks-ts/_utils/git-state.ts +0 -2
- package/dist/templates/_shared/hooks-ts/task_create_capture.ts +0 -48
- package/dist/templates/_shared/hooks-ts/user_prompt_submit.ts +0 -93
- package/dist/templates/_shared/lib-ts/base/launchers/tmux-launcher.ts +0 -173
- package/dist/templates/_shared/lib-ts/base/launchers/window-launcher.ts +0 -93
- package/dist/templates/_shared/lib-ts/base/launchers/wt-launcher.ts +0 -64
- package/dist/templates/_shared/lib-ts/base/pane-launcher.ts +0 -55
- package/dist/templates/_shared/lib-ts/base/sentinel-ipc.ts +0 -87
- package/dist/templates/_shared/lib-ts/base/stop-words.ts +0 -184
- package/dist/templates/_shared/lib-ts/base/subprocess-utils.ts +0 -249
- package/dist/templates/_shared/lib-ts/base/tmux-driver.ts +0 -341
- package/dist/templates/_shared/lib-ts/base/tmux-pane-placement.ts +0 -78
- package/dist/templates/_shared/lib-ts/package.json +0 -20
- package/dist/templates/_shared/scripts/resolve-run.ts +0 -62
- package/dist/templates/_shared/skills/codex/CLAUDE.md +0 -70
- /package/dist/templates/{_shared → core}/lib-ts/agent-exec/backends/index.ts +0 -0
|
@@ -3,53 +3,28 @@
|
|
|
3
3
|
* PostToolUse:* hook: Monitor context window usage, trigger mode transitions,
|
|
4
4
|
* and progressive-save state when context runs low.
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
6
|
+
import { getContextBySessionId, saveState } from "../lib-ts/context/context-store.js";
|
|
7
|
+
import { selectWarningMessage } from "../lib-ts/hooks/context-monitor-logic.js";
|
|
7
8
|
import {
|
|
8
9
|
emitContext, getContextPercentRemaining, hookLog,
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
} from "../lib-ts/
|
|
12
|
-
import { nowIso } from "../lib-ts/base/utils.js";
|
|
13
|
-
import { getContextBySessionId, maybeActivate, saveState } from "../lib-ts/context/context-store.js";
|
|
10
|
+
requireBoundSession, logDebug, logDiagnostic, logInfo, runHook, safeMaybeActivate,
|
|
11
|
+
} from "../lib-ts/hooks/hook-utils.js";
|
|
12
|
+
import { nowIso } from "../lib-ts/runtime/utils.js";
|
|
14
13
|
import type { ContextState } from "../lib-ts/types.js";
|
|
15
14
|
|
|
16
15
|
const WRITE_TOOLS = new Set(["Bash", "Edit", "NotebookEdit", "Write"]);
|
|
17
16
|
|
|
18
17
|
const SAVE_STATE_THRESHOLD = 60;
|
|
19
18
|
|
|
20
|
-
|
|
21
|
-
"This session is approaching its context limit. Consider:\n\n" +
|
|
22
|
-
"- Completing your current task, then pausing for the user to decide next steps\n" +
|
|
23
|
-
"- If significant work remains, mention that `/aiwcli-shared:handoff` can capture progress " +
|
|
24
|
-
"for a fresh session\n\n" +
|
|
25
|
-
"Do not rush or cut corners — finish the current task properly. " +
|
|
26
|
-
"Just be aware that starting large new tasks may not complete before context runs out.";
|
|
27
|
-
|
|
28
|
-
const CONTEXT_WARNING_15 = "## Context Window: ~15% Remaining — Wrap Up Now\n\n" +
|
|
29
|
-
"Context is critically low. After completing your current step:\n\n" +
|
|
30
|
-
"1. **Stop taking on new work**\n" +
|
|
31
|
-
"2. Summarize what was accomplished and what remains\n" +
|
|
32
|
-
"3. Offer to run `/aiwcli-shared:handoff` so progress transfers to a fresh session\n\n" +
|
|
33
|
-
"Do not start new multi-step tasks. Focus on clean closure.";
|
|
34
|
-
|
|
35
|
-
const WARNING_THRESHOLDS = [
|
|
36
|
-
{ pct: 15, msg: CONTEXT_WARNING_15 }, // Most urgent first
|
|
37
|
-
{ pct: 30, msg: CONTEXT_WARNING_30 },
|
|
38
|
-
];
|
|
39
|
-
|
|
40
|
-
/** Transition idle/has_plan → active when implementation tools are used. */
|
|
19
|
+
/** Transition idle/has_staged_work → active when implementation tools are used. */
|
|
41
20
|
function checkAndTransitionMode(
|
|
42
|
-
|
|
21
|
+
stateId: string,
|
|
43
22
|
toolName: string | undefined,
|
|
44
23
|
permissionMode: string,
|
|
45
24
|
projectRoot: string,
|
|
46
25
|
): void {
|
|
47
26
|
if (!toolName || !WRITE_TOOLS.has(toolName)) return;
|
|
48
|
-
|
|
49
|
-
maybeActivate(state.id, permissionMode, projectRoot, "context_monitor");
|
|
50
|
-
} catch (error) {
|
|
51
|
-
logWarn("context_monitor", `maybeActivate failed (non-critical): ${error}`);
|
|
52
|
-
}
|
|
27
|
+
safeMaybeActivate(stateId, permissionMode, projectRoot, "context_monitor");
|
|
53
28
|
}
|
|
54
29
|
|
|
55
30
|
/** Save state snapshot at SAVE_STATE_THRESHOLD. */
|
|
@@ -82,38 +57,31 @@ function checkContextWarnings(
|
|
|
82
57
|
state.last_session = {};
|
|
83
58
|
}
|
|
84
59
|
const fired = state.last_session.context_warnings_fired ?? [];
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
|
|
60
|
+
const warning = selectWarningMessage(pctRemaining, fired);
|
|
61
|
+
if (!warning) return;
|
|
62
|
+
|
|
63
|
+
emitContext(warning.msg);
|
|
64
|
+
state.last_session.context_warnings_fired = [...fired, warning.pct];
|
|
65
|
+
saveState(state.id, state, projectRoot);
|
|
66
|
+
logInfo(
|
|
67
|
+
"context_monitor",
|
|
68
|
+
`Context warning emitted at ${warning.pct}% threshold`,
|
|
69
|
+
);
|
|
95
70
|
}
|
|
96
71
|
|
|
97
72
|
function main(): void {
|
|
98
|
-
const
|
|
99
|
-
if (!
|
|
73
|
+
const bound = requireBoundSession("context_monitor");
|
|
74
|
+
if (!bound) return;
|
|
100
75
|
|
|
101
|
-
const sessionId =
|
|
102
|
-
if (!sessionId) return;
|
|
103
|
-
|
|
104
|
-
const projectRoot = getProjectRoot(payload.cwd);
|
|
76
|
+
const { payload, sessionId, projectRoot } = bound;
|
|
105
77
|
const permissionMode = payload.permission_mode ?? "";
|
|
106
78
|
const toolName = payload.tool_name;
|
|
107
79
|
|
|
108
80
|
// Initial context lookup
|
|
109
|
-
let state =
|
|
110
|
-
if (!state) {
|
|
111
|
-
logDebug("context_monitor", `No context for session ${sessionId}`);
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
81
|
+
let state = bound.state;
|
|
114
82
|
|
|
115
83
|
// Phase 1: Mode transition for write tools
|
|
116
|
-
checkAndTransitionMode(state, toolName, permissionMode, projectRoot);
|
|
84
|
+
checkAndTransitionMode(state.id, toolName, permissionMode, projectRoot);
|
|
117
85
|
|
|
118
86
|
// Phase 2: Context window check (log only, no warnings emitted)
|
|
119
87
|
const [pctRemaining, tokensUsed, maxTokens] = getContextPercentRemaining(payload);
|
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
* Outputs a plain JSON array (NOT hookSpecificOutput).
|
|
5
5
|
*/
|
|
6
6
|
import * as fs from "node:fs";
|
|
7
|
-
import
|
|
7
|
+
import path from "node:path";
|
|
8
8
|
|
|
9
|
-
import { getContextFilePath, getContextHandoffsDir, getContextPlansDir, getContextReviewsDir, getProjectRoot } from "../lib-ts/base/constants.js";
|
|
10
|
-
import { loadHookInput, logDebug, logError, runHook } from "../lib-ts/base/hook-utils.js";
|
|
11
9
|
import { getAllContexts, getContextBySessionId } from "../lib-ts/context/context-store.js";
|
|
10
|
+
import { loadHookInput, logDebug, logError, runHook } from "../lib-ts/hooks/hook-utils.js";
|
|
11
|
+
import { getContextFilePath, getContextHandoffsDir, getContextPlansDir, getContextReviewsDir, getProjectRoot } from "../lib-ts/runtime/constants.js";
|
|
12
12
|
import type { ContextState } from "../lib-ts/types.js";
|
|
13
13
|
|
|
14
14
|
/** Get .md files sorted by mtime descending */
|
|
@@ -128,3 +128,4 @@ function main(): void {
|
|
|
128
128
|
}
|
|
129
129
|
|
|
130
130
|
runHook(main, "file-suggestion");
|
|
131
|
+
|
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
* PostToolUse:Write|Edit hook: Run linter on edited files, feed errors to Claude.
|
|
4
4
|
* Uses emitContext() for non-blocking context injection — Claude sees errors and self-corrects.
|
|
5
5
|
*/
|
|
6
|
-
import { getProjectRoot } from "../lib-ts/base/constants.js";
|
|
7
6
|
import {
|
|
8
|
-
emitContext,
|
|
9
|
-
} from "../lib-ts/
|
|
10
|
-
import {
|
|
7
|
+
emitContext, logDebug, requireToolInput, runHook,
|
|
8
|
+
} from "../lib-ts/hooks/hook-utils.js";
|
|
9
|
+
import { getProjectRoot } from "../lib-ts/runtime/constants.js";
|
|
10
|
+
import { formatLintErrors, getLinterForFile, runLinter } from "../lib-ts/runtime/lint-dispatch.js";
|
|
11
11
|
|
|
12
12
|
// Extensions with no lint value
|
|
13
13
|
const SKIP_EXTENSIONS = new Set([
|
|
@@ -31,11 +31,9 @@ function shouldSkip(filePath: string): boolean {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
function main(): void {
|
|
34
|
-
const
|
|
35
|
-
if (!
|
|
36
|
-
|
|
37
|
-
const toolInput = getToolInput(payload);
|
|
38
|
-
if (!toolInput) return;
|
|
34
|
+
const context = requireToolInput("lint_after_edit");
|
|
35
|
+
if (!context) return;
|
|
36
|
+
const { payload, toolInput } = context;
|
|
39
37
|
|
|
40
38
|
const filePath = toolInput.file_path as string | undefined;
|
|
41
39
|
if (!filePath) return;
|
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
* PreCompact hook: Save state.json snapshot before context compaction.
|
|
4
4
|
* Captures git state and session metadata for recovery.
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
7
|
-
import { getGitState } from "../lib-ts/base/git-state.js";
|
|
6
|
+
import { getContextBySessionId, saveState } from "../lib-ts/context/context-store.js";
|
|
8
7
|
import {
|
|
9
8
|
loadHookInput, logDebug, logError, logInfo, runHook,
|
|
10
|
-
} from "../lib-ts/
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
9
|
+
} from "../lib-ts/hooks/hook-utils.js";
|
|
10
|
+
import { getProjectRoot } from "../lib-ts/runtime/constants.js";
|
|
11
|
+
import { getGitState } from "../lib-ts/runtime/git-state.js";
|
|
12
|
+
import { nowIso } from "../lib-ts/runtime/utils.js";
|
|
13
13
|
|
|
14
14
|
function main(): void {
|
|
15
15
|
const payload = loadHookInput();
|
|
@@ -1,22 +1,26 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
/**
|
|
3
3
|
* SessionEnd hook: Save session state, assign plan fields (fallback),
|
|
4
|
-
* stage
|
|
4
|
+
* stage has_staged_work for next session.
|
|
5
5
|
*/
|
|
6
|
-
import * as crypto from "node:crypto";
|
|
7
6
|
import * as fs from "node:fs";
|
|
8
|
-
import
|
|
7
|
+
import path from "node:path";
|
|
9
8
|
|
|
10
|
-
import {
|
|
11
|
-
import { getGitState } from "../lib-ts/base/git-state.js";
|
|
9
|
+
import { saveState, determineArtifactType } from "../lib-ts/context/context-store.js";
|
|
12
10
|
import {
|
|
13
|
-
|
|
14
|
-
} from "../lib-ts/base/hook-utils.js";
|
|
15
|
-
import { nowIso } from "../lib-ts/base/utils.js";
|
|
16
|
-
import { getContextBySessionId, saveState, determineArtifactType } from "../lib-ts/context/context-store.js";
|
|
17
|
-
import {
|
|
18
|
-
findLatestPlan, normalizePlanContent, generatePlanId, extractPlanAnchors,
|
|
11
|
+
findLatestPlan,
|
|
19
12
|
} from "../lib-ts/context/plan-manager.js";
|
|
13
|
+
import {
|
|
14
|
+
requireBoundSession, runHook, logDebug, logInfo, logError, logDiagnostic,
|
|
15
|
+
} from "../lib-ts/hooks/hook-utils.js";
|
|
16
|
+
import {
|
|
17
|
+
buildSessionMetadata,
|
|
18
|
+
computePlanFallback,
|
|
19
|
+
generateArchiveFilename,
|
|
20
|
+
shouldStage,
|
|
21
|
+
} from "../lib-ts/hooks/session-end-logic.js";
|
|
22
|
+
import { getContextDir } from "../lib-ts/runtime/constants.js";
|
|
23
|
+
import { nowIso } from "../lib-ts/runtime/utils.js";
|
|
20
24
|
|
|
21
25
|
/**
|
|
22
26
|
* Archive session transcript to context's session-transcripts/ folder.
|
|
@@ -39,25 +43,10 @@ function archiveTranscript(
|
|
|
39
43
|
const transcriptsDir = path.join(contextDir, "session-transcripts");
|
|
40
44
|
fs.mkdirSync(transcriptsDir, { recursive: true });
|
|
41
45
|
|
|
42
|
-
// 3. Generate archive filename
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const timestamp =
|
|
47
|
-
`${now.getFullYear()}-` +
|
|
48
|
-
`${String(now.getMonth() + 1).padStart(2, "0")}-` +
|
|
49
|
-
`${String(now.getDate()).padStart(2, "0")}-` +
|
|
50
|
-
`${String(now.getHours()).padStart(2, "0")}${String(now.getMinutes()).padStart(2, "0")}`;
|
|
51
|
-
|
|
52
|
-
// 4. Handle collisions (rare, but possible with rapid session churn)
|
|
53
|
-
let archiveName = `${timestamp}-${sessionId}.jsonl`;
|
|
54
|
-
let archivePath = path.join(transcriptsDir, archiveName);
|
|
55
|
-
let counter = 2;
|
|
56
|
-
while (fs.existsSync(archivePath)) {
|
|
57
|
-
archiveName = `${timestamp}-${sessionId}-${counter}.jsonl`;
|
|
58
|
-
archivePath = path.join(transcriptsDir, archiveName);
|
|
59
|
-
counter++;
|
|
60
|
-
}
|
|
46
|
+
// 3. Generate archive filename with collision handling
|
|
47
|
+
const existingNames = new Set(fs.readdirSync(transcriptsDir));
|
|
48
|
+
const archiveName = generateArchiveFilename(sessionId, new Date(), existingNames);
|
|
49
|
+
const archivePath = path.join(transcriptsDir, archiveName);
|
|
61
50
|
|
|
62
51
|
// 5. Copy transcript file
|
|
63
52
|
try {
|
|
@@ -70,46 +59,27 @@ function archiveTranscript(
|
|
|
70
59
|
}
|
|
71
60
|
|
|
72
61
|
function main(): void {
|
|
73
|
-
const
|
|
74
|
-
if (!
|
|
75
|
-
|
|
76
|
-
const sessionId = payload.session_id;
|
|
77
|
-
if (!sessionId) {
|
|
78
|
-
logDebug("session_end", "No session_id, skipping");
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
62
|
+
const bound = requireBoundSession("session_end");
|
|
63
|
+
if (!bound) return;
|
|
81
64
|
|
|
82
|
-
const projectRoot =
|
|
65
|
+
const { payload, sessionId, projectRoot, state } = bound;
|
|
83
66
|
const source = payload.source ?? "unknown";
|
|
84
67
|
const permissionMode = payload.permission_mode ?? "";
|
|
85
68
|
|
|
86
|
-
const state = getContextBySessionId(sessionId, projectRoot);
|
|
87
|
-
if (!state) {
|
|
88
|
-
logDebug("session_end", `No context bound to session ${sessionId}`);
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// Capture git state
|
|
93
|
-
const gitState = getGitState(projectRoot);
|
|
94
|
-
|
|
95
69
|
// Save session metadata
|
|
96
|
-
state.last_session =
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
git_state: gitState,
|
|
102
|
-
};
|
|
70
|
+
state.last_session = buildSessionMetadata(
|
|
71
|
+
sessionId,
|
|
72
|
+
source,
|
|
73
|
+
payload.transcript_path ?? undefined,
|
|
74
|
+
);
|
|
103
75
|
state.last_active = nowIso();
|
|
104
76
|
|
|
105
|
-
// Archive transcript
|
|
106
|
-
// Note: state is a ContextState object (from getContextBySessionId on line 33)
|
|
107
|
-
// state.id is the context ID used to construct paths like _output/contexts/{context_id}/
|
|
77
|
+
// Archive transcript
|
|
108
78
|
if (payload.transcript_path) {
|
|
109
79
|
try {
|
|
110
80
|
const archived = archiveTranscript(
|
|
111
81
|
payload.transcript_path,
|
|
112
|
-
state.id,
|
|
82
|
+
state.id,
|
|
113
83
|
sessionId,
|
|
114
84
|
projectRoot,
|
|
115
85
|
);
|
|
@@ -153,22 +123,12 @@ function main(): void {
|
|
|
153
123
|
const latestPlanPath = findLatestPlan(state.id, projectRoot);
|
|
154
124
|
if (latestPlanPath) {
|
|
155
125
|
try {
|
|
156
|
-
const content = fs.readFileSync(latestPlanPath, "
|
|
157
|
-
const
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
.slice(0, 12);
|
|
163
|
-
|
|
164
|
-
state.plan_hash = planHash;
|
|
165
|
-
state.plan_path = latestPlanPath;
|
|
166
|
-
state.plan_signature = content.slice(0, 200);
|
|
167
|
-
state.plan_id = generatePlanId();
|
|
168
|
-
state.plan_anchors = extractPlanAnchors(content);
|
|
169
|
-
state.work_consumed = state.work_consumed ?? false; // CHANGED: unified flag
|
|
170
|
-
|
|
171
|
-
logInfo("session_end", `Assigned plan fallback: hash=${planHash}`);
|
|
126
|
+
const content = fs.readFileSync(latestPlanPath, "utf8");
|
|
127
|
+
const fallback = computePlanFallback(state, content);
|
|
128
|
+
Object.assign(state, fallback, { plan_path: latestPlanPath });
|
|
129
|
+
if (fallback.plan_hash) {
|
|
130
|
+
logInfo("session_end", `Assigned plan fallback: hash=${fallback.plan_hash}`);
|
|
131
|
+
}
|
|
172
132
|
} catch (error) {
|
|
173
133
|
logError("session_end", `Failed to read plan: ${error}`);
|
|
174
134
|
}
|
|
@@ -177,9 +137,7 @@ function main(): void {
|
|
|
177
137
|
|
|
178
138
|
// Unified staging logic (replaces separate plan/handoff checks)
|
|
179
139
|
const artifactType = determineArtifactType(state);
|
|
180
|
-
|
|
181
|
-
const canStage = state.mode === "active" || permissionMode === "plan";
|
|
182
|
-
if (artifactType && canStage && !state.work_consumed) {
|
|
140
|
+
if (artifactType && shouldStage(state, permissionMode)) {
|
|
183
141
|
state.mode = "has_staged_work"; // CHANGED: unified mode
|
|
184
142
|
state.next_artifact_type = artifactType;
|
|
185
143
|
logInfo("session_end", `Staged ${state.id}: ${state.mode} → has_staged_work (${artifactType})`);
|
|
@@ -195,3 +153,5 @@ function main(): void {
|
|
|
195
153
|
}
|
|
196
154
|
|
|
197
155
|
runHook(main, "session_end");
|
|
156
|
+
|
|
157
|
+
|
|
@@ -3,11 +3,6 @@
|
|
|
3
3
|
* SessionStart hook: Restore context after /clear (plan/handoff) or compaction.
|
|
4
4
|
* Routes by source field to appropriate handler.
|
|
5
5
|
*/
|
|
6
|
-
import { getProjectRoot } from "../lib-ts/base/constants.js";
|
|
7
|
-
import {
|
|
8
|
-
loadHookInput, emitContext, runHookAsync,
|
|
9
|
-
logDebug, logInfo, logWarn, logDiagnostic,
|
|
10
|
-
} from "../lib-ts/base/hook-utils.js";
|
|
11
6
|
import {
|
|
12
7
|
buildRestoreSections, formatHandoffContinuation, getModeDisplay,
|
|
13
8
|
buildContextInventory,
|
|
@@ -15,6 +10,11 @@ import {
|
|
|
15
10
|
import {
|
|
16
11
|
getContextBySessionId, getAllContexts, bindSession, updateMode, determineArtifactType,
|
|
17
12
|
} from "../lib-ts/context/context-store.js";
|
|
13
|
+
import {
|
|
14
|
+
loadHookInput, emitContext, runHookAsync,
|
|
15
|
+
logDebug, logInfo, logWarn, logDiagnostic,
|
|
16
|
+
} from "../lib-ts/hooks/hook-utils.js";
|
|
17
|
+
import { getProjectRoot } from "../lib-ts/runtime/constants.js";
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
/**
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
/**
|
|
3
|
+
* PostToolUse:TaskCreate hook: Persist Claude's TaskCreate calls to state.json.
|
|
4
|
+
*/
|
|
5
|
+
import { addTask } from "../lib-ts/context/task-tracker.js";
|
|
6
|
+
import {
|
|
7
|
+
logError, logInfo, logWarn, requirePersistenceContext, runHook,
|
|
8
|
+
} from "../lib-ts/hooks/hook-utils.js";
|
|
9
|
+
|
|
10
|
+
function main(): void {
|
|
11
|
+
const context = requirePersistenceContext("TaskCreate", "task_create_capture");
|
|
12
|
+
if (!context) return;
|
|
13
|
+
const { toolInput, sessionId, projectRoot, state } = context;
|
|
14
|
+
|
|
15
|
+
const subject = toolInput.subject as string | undefined;
|
|
16
|
+
if (!subject) {
|
|
17
|
+
logWarn("task_create_capture", "TaskCreate missing subject field");
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const description = (toolInput.description as string) ?? "";
|
|
22
|
+
const activeForm = (toolInput.activeForm as string) ?? "";
|
|
23
|
+
|
|
24
|
+
const task = addTask(state.id, subject, description, activeForm, sessionId, projectRoot);
|
|
25
|
+
if (task) {
|
|
26
|
+
logInfo("task_create_capture", `Persisted task ${task.id}: ${subject}`);
|
|
27
|
+
} else {
|
|
28
|
+
logError("task_create_capture", `Failed to persist task: ${subject}`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
runHook(main, "task_create_capture");
|
|
@@ -3,31 +3,15 @@
|
|
|
3
3
|
* PostToolUse:TaskUpdate hook: Persist Claude's TaskUpdate calls to state.json.
|
|
4
4
|
* Maps Claude's ephemeral task IDs to persistent aiw-N IDs.
|
|
5
5
|
*/
|
|
6
|
-
import { getProjectRoot } from "../lib-ts/base/constants.js";
|
|
7
|
-
import {
|
|
8
|
-
checkSkipPersistence, getToolInput, loadHookInput, logDebug,
|
|
9
|
-
logError as _logError, logInfo, logWarn, runHook, validateHookEvent,
|
|
10
|
-
} from "../lib-ts/base/hook-utils.js";
|
|
11
|
-
import { getContextBySessionId } from "../lib-ts/context/context-store.js";
|
|
12
6
|
import { deleteTask, updateTask } from "../lib-ts/context/task-tracker.js";
|
|
7
|
+
import {
|
|
8
|
+
logInfo, logWarn, requirePersistenceContext, runHook,
|
|
9
|
+
} from "../lib-ts/hooks/hook-utils.js";
|
|
13
10
|
|
|
14
11
|
function main(): void {
|
|
15
|
-
const
|
|
16
|
-
if (!
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const toolInput = getToolInput(payload);
|
|
20
|
-
if (!toolInput) return;
|
|
21
|
-
if (checkSkipPersistence(payload, "task_update_capture")) return;
|
|
22
|
-
|
|
23
|
-
const projectRoot = getProjectRoot(payload.cwd);
|
|
24
|
-
const sessionId = payload.session_id ?? "unknown";
|
|
25
|
-
|
|
26
|
-
const state = getContextBySessionId(sessionId, projectRoot);
|
|
27
|
-
if (!state) {
|
|
28
|
-
logDebug("task_update_capture", `No context for session ${sessionId}`);
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
12
|
+
const context = requirePersistenceContext("TaskUpdate", "task_update_capture");
|
|
13
|
+
if (!context) return;
|
|
14
|
+
const { toolInput, sessionId, projectRoot, state } = context;
|
|
31
15
|
|
|
32
16
|
const claudeTaskId = toolInput.taskId as string | undefined;
|
|
33
17
|
if (!claudeTaskId) {
|
|
@@ -36,7 +20,7 @@ function main(): void {
|
|
|
36
20
|
}
|
|
37
21
|
|
|
38
22
|
// Map Claude's ephemeral ID to persistent ID
|
|
39
|
-
const metadata = (toolInput.metadata ?? {}) as Record<string,
|
|
23
|
+
const metadata = (toolInput.metadata ?? {}) as Record<string, unknown>;
|
|
40
24
|
const persistentId = (metadata.persistent_id as string) ?? `aiw-${claudeTaskId}`;
|
|
41
25
|
|
|
42
26
|
const status = toolInput.status as string | undefined;
|
|
@@ -53,7 +37,7 @@ function main(): void {
|
|
|
53
37
|
}
|
|
54
38
|
|
|
55
39
|
if (status) {
|
|
56
|
-
const opts: Record<string,
|
|
40
|
+
const opts: Record<string, unknown> = { status };
|
|
57
41
|
if (metadata.evidence) opts.evidence = metadata.evidence;
|
|
58
42
|
if (metadata.work_summary) opts.work_summary = metadata.work_summary;
|
|
59
43
|
if (metadata.files_changed && Array.isArray(metadata.files_changed)) {
|
|
@@ -72,3 +56,4 @@ function main(): void {
|
|
|
72
56
|
}
|
|
73
57
|
|
|
74
58
|
runHook(main, "task_update_capture");
|
|
59
|
+
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
/**
|
|
3
|
+
* UserPromptSubmit hook: Context enforcement — ensures every prompt belongs
|
|
4
|
+
* to a tracked context. The most complex shared hook.
|
|
5
|
+
*
|
|
6
|
+
* Uses emitContext() for output — context text is passed via hookSpecificOutput JSON.
|
|
7
|
+
* Catches BlockRequest and uses emitBlock() to block the prompt.
|
|
8
|
+
*/
|
|
9
|
+
import {
|
|
10
|
+
loadHookInput, runHookAsync, logDebug, emitContext, emitBlock,
|
|
11
|
+
} from "../lib-ts/hooks/hook-utils.js";
|
|
12
|
+
import { executePromptBinding } from "../lib-ts/hooks/prompt-binding-logic.js";
|
|
13
|
+
import { getProjectRoot } from "../lib-ts/runtime/constants.js";
|
|
14
|
+
|
|
15
|
+
async function asyncMain(): Promise<void> {
|
|
16
|
+
const payload = loadHookInput();
|
|
17
|
+
if (!payload) return;
|
|
18
|
+
|
|
19
|
+
const prompt = (payload as unknown).prompt as string | undefined;
|
|
20
|
+
const sessionId = payload.session_id;
|
|
21
|
+
const permissionMode = payload.permission_mode ?? "";
|
|
22
|
+
const projectRoot = getProjectRoot(payload.cwd);
|
|
23
|
+
|
|
24
|
+
if (!sessionId) {
|
|
25
|
+
logDebug("user_prompt_submit", "No session_id");
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const result = await executePromptBinding(
|
|
30
|
+
prompt,
|
|
31
|
+
sessionId,
|
|
32
|
+
permissionMode,
|
|
33
|
+
projectRoot,
|
|
34
|
+
);
|
|
35
|
+
if (result.blockedReason) {
|
|
36
|
+
emitBlock(result.blockedReason);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (result.outputs.length > 0) {
|
|
41
|
+
emitContext(result.outputs.join("\n\n"));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
runHookAsync(asyncMain, "user_prompt_submit");
|
|
46
|
+
|