aiwcli 0.13.8 → 0.14.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.
Files changed (37) hide show
  1. package/README.md +11 -1
  2. package/dist/commands/launch.d.ts +8 -0
  3. package/dist/commands/launch.js +96 -5
  4. package/dist/templates/_shared/.claude/skills/codex/SKILL.md +42 -0
  5. package/dist/templates/_shared/.claude/skills/codex/prompt.md +10 -0
  6. package/dist/templates/_shared/lib-ts/agent-exec/backends/headless.ts +33 -0
  7. package/dist/templates/_shared/lib-ts/agent-exec/backends/index.ts +6 -0
  8. package/dist/templates/_shared/lib-ts/agent-exec/backends/tmux.ts +145 -0
  9. package/dist/templates/_shared/lib-ts/agent-exec/base-agent.ts +229 -0
  10. package/dist/templates/_shared/lib-ts/agent-exec/execution-backend.ts +50 -0
  11. package/dist/templates/_shared/lib-ts/agent-exec/index.ts +4 -0
  12. package/dist/templates/_shared/lib-ts/base/cli-args.ts +283 -0
  13. package/dist/templates/_shared/lib-ts/base/inference.ts +53 -47
  14. package/dist/templates/_shared/lib-ts/base/models.ts +16 -0
  15. package/dist/templates/_shared/lib-ts/base/preflight.ts +98 -0
  16. package/dist/templates/_shared/lib-ts/base/tmux-driver.ts +381 -0
  17. package/dist/templates/_shared/lib-ts/base/utils.ts +8 -0
  18. package/dist/templates/_shared/lib-ts/context/context-formatter.ts +35 -11
  19. package/dist/templates/_shared/lib-ts/types.ts +17 -0
  20. package/dist/templates/_shared/scripts/status_line.ts +57 -28
  21. package/dist/templates/_shared/skills/prompt-codex/CLAUDE.md +46 -0
  22. package/dist/templates/_shared/skills/prompt-codex/scripts/launch-codex.ts +254 -0
  23. package/dist/templates/cc-native/.claude/settings.json +121 -1
  24. package/dist/templates/cc-native/_cc-native/CLAUDE.md +73 -0
  25. package/dist/templates/cc-native/_cc-native/lib-ts/CLAUDE.md +70 -0
  26. package/dist/templates/cc-native/_cc-native/lib-ts/settings.ts +2 -1
  27. package/dist/templates/cc-native/_cc-native/lib-ts/types.ts +5 -12
  28. package/dist/templates/cc-native/_cc-native/plan-review/lib/preflight.ts +14 -80
  29. package/dist/templates/cc-native/_cc-native/plan-review/lib/reviewers/agent.ts +19 -7
  30. package/dist/templates/cc-native/_cc-native/plan-review/lib/reviewers/base/base-agent.ts +4 -215
  31. package/dist/templates/cc-native/_cc-native/plan-review/lib/reviewers/index.ts +1 -1
  32. package/dist/templates/cc-native/_cc-native/plan-review/lib/reviewers/providers/claude-agent.ts +9 -39
  33. package/dist/templates/cc-native/_cc-native/plan-review/lib/reviewers/providers/codex-agent.ts +19 -22
  34. package/dist/templates/cc-native/_cc-native/plan-review/lib/reviewers/providers/gemini-agent.ts +2 -1
  35. package/dist/templates/cc-native/_cc-native/plan-review/lib/reviewers/providers/orchestrator-claude-agent.ts +13 -15
  36. package/oclif.manifest.json +21 -3
  37. package/package.json +1 -1
@@ -0,0 +1,46 @@
1
+ # Prompt Codex Skill
2
+
3
+ Launch Codex CLI in a tmux pane and inject a prompt into its REPL.
4
+
5
+ ## Directory Structure
6
+
7
+ ```
8
+ prompt-codex/
9
+ ├── CLAUDE.md ← This file
10
+ └── scripts/
11
+ └── launch-codex.ts ← CLI entry point
12
+ ```
13
+
14
+ ## Script: launch-codex.ts
15
+
16
+ **Usage:**
17
+ ```bash
18
+ bun .aiwcli/_shared/skills/prompt-codex/scripts/launch-codex.ts [--model <tier|id>] [--sandbox <sandbox-mode>] plan
19
+ bun .aiwcli/_shared/skills/prompt-codex/scripts/launch-codex.ts [--model <tier|id>] [--sandbox <sandbox-mode>] --file <path>
20
+ bun .aiwcli/_shared/skills/prompt-codex/scripts/launch-codex.ts [--model <tier|id>] [--sandbox <sandbox-mode>] <inline text...>
21
+ ```
22
+
23
+ **Args:**
24
+ - `plan` — discover active plan via context system, inject into Codex REPL
25
+ - `--file <path>` — inject file contents into Codex REPL
26
+ - `<text...>` — join remaining args as inline prompt, write to temp file, inject
27
+ - `--model <alias|tier|id>` — Aliases: `spark` → `gpt-5.3-codex-spark`, `codex` → `gpt-5.3-codex`, `gpt` → `gpt-5.2`. Tiers: `fast`/`standard`/`smart` (resolved via `resolveModelForProvider()`). Or any full model ID. Aliases are checked first (local `CODEX_ALIASES` constant in `launch-codex.ts`), then tiers, then pass-through. Omitted = Codex default.
28
+ - `--sandbox <mode>` — `read-only`, `workspace-write`, or `danger-full-access`. Default is `danger-full-access` for implementation handoffs.
29
+
30
+ **Plan discovery order:**
31
+ 1. `CLAUDE_SESSION_ID` env → `getContextBySessionId()` → `findLatestPlan(contextId)`
32
+ 2. Fallback: scan `_output/contexts/*/plans/*.md` by mtime (inline, no `_cc-native` import)
33
+
34
+ **Dependencies (all from `_shared/lib-ts/`):**
35
+ - `base/tmux-driver.ts` — `launchDriverInTmuxOrFallback()`, `getTmuxAvailability()`
36
+ - `base/cli-args.ts` — `resolveCodexModel()`, `codexReplSpec()`, `buildCliInvocation()`, `isCodexSandbox()`
37
+ - `base/logger.ts` — `logDebug()`, `logWarn()` (injection diagnostics)
38
+ - `context/context-store.ts` — `getContextBySessionId()`
39
+ - `context/context-formatter.ts` — `buildExternalAgentContext()` (orientation header for Codex)
40
+ - `context/plan-manager.ts` — `findLatestPlan()`
41
+
42
+ **Design decisions:**
43
+ - Always creates a new tmux pane (no pane reuse/tracking)
44
+ - No exec fallback — REPL mode requires tmux
45
+ - `_shared` only — never imports from `_cc-native`
46
+ - Temp file cleanup after injection confirmed
@@ -0,0 +1,254 @@
1
+ #!/usr/bin/env bun
2
+ /**
3
+ * Launch Codex in a tmux pane and inject a prompt into its REPL.
4
+ *
5
+ * Usage:
6
+ * bun launch-codex.ts [--model fast|standard|smart|<model-id>] [--sandbox read-only|workspace-write|danger-full-access] [--context <id>] plan
7
+ * bun launch-codex.ts [--model fast|standard|smart|<model-id>] [--sandbox read-only|workspace-write|danger-full-access] [--context <id>] --file <path>
8
+ * bun launch-codex.ts [--model fast|standard|smart|<model-id>] [--sandbox read-only|workspace-write|danger-full-access] [--context <id>] <inline text...>
9
+ */
10
+ import * as fs from "node:fs";
11
+ import * as os from "node:os";
12
+ import * as path from "node:path";
13
+
14
+ import {
15
+ getTmuxAvailability,
16
+ launchDriverInTmuxOrFallback,
17
+ } from "../../../lib-ts/base/tmux-driver.js";
18
+ import { getProjectRoot } from "../../../lib-ts/base/constants.js";
19
+ import { resolveCodexModel, codexReplSpec, buildCliInvocation, isCodexSandbox, type CodexSandbox } from "../../../lib-ts/base/cli-args.js";
20
+ import { CODEX_MODELS } from "../../../lib-ts/base/models.js";
21
+ import { logDebug, logWarn } from "../../../lib-ts/base/logger.js";
22
+ import { displayPath } from "../../../lib-ts/base/utils.js";
23
+ import { getContextBySessionId, getContext } from "../../../lib-ts/context/context-store.js";
24
+ import { buildExternalAgentContext } from "../../../lib-ts/context/context-formatter.js";
25
+ import { findLatestPlan } from "../../../lib-ts/context/plan-manager.js";
26
+ import type { ContextState } from "../../../lib-ts/types.js";
27
+
28
+ /** Codex-specific model abbreviations. Checked before tier resolution. */
29
+ const CODEX_ALIASES: Record<string, string> = {
30
+ spark: CODEX_MODELS.spark,
31
+ codex: CODEX_MODELS.codex,
32
+ gpt: CODEX_MODELS.gpt,
33
+ };
34
+
35
+ // ---------------------------------------------------------------------------
36
+ // Helpers
37
+ // ---------------------------------------------------------------------------
38
+
39
+ function eprint(...args: unknown[]): void {
40
+ process.stderr.write(args.map(String).join(" ") + "\n");
41
+ }
42
+
43
+ /** Fallback plan discovery: scan all context plan dirs by mtime. */
44
+ function findLatestPlanByMtime(projectRoot: string): string | null {
45
+ const contextsDir = path.join(projectRoot, "_output", "contexts");
46
+ if (!fs.existsSync(contextsDir)) return null;
47
+
48
+ let best: { path: string; mtime: number } | null = null;
49
+
50
+ for (const ctxEntry of fs.readdirSync(contextsDir)) {
51
+ if (ctxEntry.startsWith("_")) continue;
52
+ const plansDir = path.join(contextsDir, ctxEntry, "plans");
53
+ if (!fs.existsSync(plansDir)) continue;
54
+
55
+ for (const file of fs.readdirSync(plansDir)) {
56
+ if (!file.endsWith(".md")) continue;
57
+ const fullPath = path.join(plansDir, file);
58
+ try {
59
+ const mtime = fs.statSync(fullPath).mtimeMs;
60
+ if (!best || mtime > best.mtime) {
61
+ best = { path: fullPath, mtime };
62
+ }
63
+ } catch { /* skip unreadable */ }
64
+ }
65
+ }
66
+
67
+ return best?.path ?? null;
68
+ }
69
+
70
+ // ---------------------------------------------------------------------------
71
+ // Arg parsing
72
+ // ---------------------------------------------------------------------------
73
+
74
+ const rawArgs = process.argv.slice(2);
75
+
76
+ if (rawArgs.length === 0) {
77
+ eprint("Usage: launch-codex.ts [--model <model>] [--sandbox <mode>] [--context <id>] plan | --file <path> | <text...>");
78
+ process.exit(1);
79
+ }
80
+
81
+ // Extract --model, --sandbox, and --context flags before mode dispatch
82
+ let modelFlag: string | undefined;
83
+ let sandboxFlag: CodexSandbox | undefined;
84
+ let contextFlag: string | undefined;
85
+ const args: string[] = [];
86
+
87
+ for (let i = 0; i < rawArgs.length; i++) {
88
+ if (rawArgs[i] === "--model" && i + 1 < rawArgs.length) {
89
+ modelFlag = rawArgs[++i];
90
+ } else if (rawArgs[i] === "--sandbox" && i + 1 < rawArgs.length) {
91
+ const val = rawArgs[++i];
92
+ if (!isCodexSandbox(val)) {
93
+ eprint(`Error: Invalid sandbox mode "${val}". Valid: read-only, workspace-write, danger-full-access`);
94
+ process.exit(1);
95
+ }
96
+ sandboxFlag = val;
97
+ } else if (rawArgs[i] === "--context" && i + 1 < rawArgs.length) {
98
+ contextFlag = rawArgs[++i];
99
+ } else {
100
+ args.push(rawArgs[i]);
101
+ }
102
+ }
103
+
104
+ if (args.length === 0) {
105
+ eprint("Usage: launch-codex.ts [--model <model>] [--sandbox <mode>] [--context <id>] plan | --file <path> | <text...>");
106
+ process.exit(1);
107
+ }
108
+
109
+ // Resolve model: alias first, then tier/pass-through via shared resolver
110
+ let resolvedModel: string | undefined;
111
+ if (modelFlag) {
112
+ const lower = modelFlag.toLowerCase();
113
+ resolvedModel = lower in CODEX_ALIASES
114
+ ? CODEX_ALIASES[lower]
115
+ : resolveCodexModel(modelFlag);
116
+ }
117
+
118
+ let promptPath: string | null = null;
119
+ let tempFile: string | null = null;
120
+
121
+ const projectRoot = getProjectRoot(process.cwd());
122
+
123
+ // Context lookup — available for all modes (orientation header + plan discovery)
124
+ // --context flag preferred (passed by skill caller); CLAUDE_SESSION_ID as fallback (hooks only)
125
+ let ctx: ContextState | null = null;
126
+ if (contextFlag) {
127
+ ctx = getContext(contextFlag, projectRoot) ?? null;
128
+ } else {
129
+ const sessionId = process.env.CLAUDE_SESSION_ID;
130
+ if (sessionId) {
131
+ ctx = getContextBySessionId(sessionId, projectRoot) ?? null;
132
+ }
133
+ }
134
+
135
+ if (args[0] === "plan") {
136
+ // Plan discovery: context system first, mtime fallback second
137
+ let planPath: string | null = null;
138
+
139
+ if (ctx) {
140
+ planPath = findLatestPlan(ctx.id, projectRoot);
141
+ }
142
+
143
+ if (!planPath) {
144
+ planPath = findLatestPlanByMtime(projectRoot);
145
+ }
146
+
147
+ if (!planPath) {
148
+ eprint("Error: No plan found. Create a plan first (use plan mode), then run this command.");
149
+ process.exit(1);
150
+ }
151
+
152
+ promptPath = planPath;
153
+ console.log(`Found plan: ${displayPath(planPath)}`);
154
+
155
+ } else if (args[0] === "--file") {
156
+ if (!args[1]) {
157
+ eprint("Error: --file requires a path argument.");
158
+ process.exit(1);
159
+ }
160
+ const filePath = path.resolve(args[1]);
161
+ if (!fs.existsSync(filePath)) {
162
+ eprint(`Error: File not found: ${filePath}`);
163
+ process.exit(1);
164
+ }
165
+ promptPath = filePath;
166
+
167
+ } else {
168
+ // Inline text: join args, write to temp file
169
+ const text = args.join(" ");
170
+ tempFile = path.join(os.tmpdir(), `codex-prompt-${Date.now()}.md`);
171
+ fs.writeFileSync(tempFile, text, "utf-8");
172
+ promptPath = tempFile;
173
+ }
174
+
175
+ // Prepend context orientation if available — graceful degradation on failure
176
+ if (ctx && promptPath) {
177
+ try {
178
+ const orientation = buildExternalAgentContext(ctx, projectRoot);
179
+ const original = fs.readFileSync(promptPath, "utf-8");
180
+ const combined = `${orientation}\n\n---\n\n${original}`;
181
+ const contextPromptPath = path.join(os.tmpdir(), `codex-ctx-prompt-${Date.now()}.md`);
182
+ fs.writeFileSync(contextPromptPath, combined, "utf-8");
183
+ if (tempFile) {
184
+ try { fs.unlinkSync(tempFile); } catch { /* ignore */ }
185
+ }
186
+ promptPath = contextPromptPath;
187
+ tempFile = contextPromptPath;
188
+ } catch {
189
+ logWarn("codex-skill", `Context orientation prepend failed for ${ctx.id}, continuing without header`);
190
+ }
191
+ }
192
+
193
+ // ---------------------------------------------------------------------------
194
+ // Pre-flight: tmux required
195
+ // ---------------------------------------------------------------------------
196
+
197
+ const tmux = getTmuxAvailability();
198
+ if (!tmux.available) {
199
+ eprint(`Error: tmux is required for Codex REPL mode. ${tmux.reason ?? ""}`);
200
+ if (tempFile) try { fs.unlinkSync(tempFile); } catch { /* ignore */ }
201
+ process.exit(1);
202
+ }
203
+
204
+ // ---------------------------------------------------------------------------
205
+ // Launch Codex REPL in tmux pane
206
+ // ---------------------------------------------------------------------------
207
+
208
+ // Build args via centralized CLI builder
209
+ const codexArgs = buildCliInvocation(codexReplSpec(resolvedModel, sandboxFlag)).args;
210
+ if (sandboxFlag) console.log(`Sandbox: ${sandboxFlag}`);
211
+ if (resolvedModel) console.log(`Model: ${resolvedModel}${modelFlag !== resolvedModel ? ` (from "${modelFlag}")` : ""}`);
212
+
213
+ logDebug("codex-skill", `Launching: model=${resolvedModel ?? "default"}, sandbox=${sandboxFlag ?? "default"}, source=${args[0]}, bytes=${promptPath ? fs.statSync(promptPath).size : 0}`);
214
+
215
+ const result = await launchDriverInTmuxOrFallback({
216
+ toolName: "codex",
217
+ mode: "repl",
218
+ args: codexArgs,
219
+ promptPath,
220
+ sendPromptInRepl: true,
221
+ allowExecFallback: false,
222
+ });
223
+
224
+ // Cleanup temp file after injection
225
+ if (tempFile) {
226
+ try { fs.unlinkSync(tempFile); } catch { /* ignore */ }
227
+ }
228
+
229
+ if (!result.launched) {
230
+ logWarn("codex-skill", `Launch failed: ${result.reason}`);
231
+ eprint(`Error: Failed to launch Codex. ${result.reason ?? ""}`);
232
+ process.exit(1);
233
+ }
234
+
235
+ // Log injection diagnostics
236
+ const diag = result.sendDiagnostics;
237
+ if (diag) {
238
+ if (diag.success) {
239
+ logDebug("codex-skill", `Injection OK: promptWait=${diag.promptWaitMs}ms, retrySent=${diag.retrySent}`);
240
+ } else {
241
+ logWarn("codex-skill", `Injection failed at ${diag.failedAt}: wait=${diag.promptWaitMs}ms, stderr=${diag.tmuxStderr ?? "none"}, paneTail=${diag.paneTailOnTimeout ?? "none"}`);
242
+ }
243
+ }
244
+
245
+ if (result.paneId) {
246
+ console.log(`Codex launched in tmux pane: ${result.paneId}`);
247
+ } else {
248
+ console.log("Codex launched in tmux pane.");
249
+ }
250
+
251
+ if (result.reason) {
252
+ // Partial success (e.g., launched but prompt injection failed)
253
+ eprint(`Warning: ${result.reason}`);
254
+ }
@@ -1,6 +1,23 @@
1
1
  {
2
+ "statusLine": {
3
+ "type": "command",
4
+ "command": "NO_COLOR= FORCE_COLOR=2 bun ~/.aiwcli/bin/resolve-run.ts .aiwcli/_shared/scripts/status_line.ts"
5
+ },
6
+ "fileSuggestion": {
7
+ "type": "command",
8
+ "command": "bun ~/.aiwcli/bin/resolve-run.ts .aiwcli/_shared/hooks-ts/file-suggestion.ts"
9
+ },
2
10
  "hooks": {
3
11
  "UserPromptSubmit": [
12
+ {
13
+ "hooks": [
14
+ {
15
+ "type": "command",
16
+ "command": "bun ~/.aiwcli/bin/resolve-run.ts .aiwcli/_shared/hooks-ts/user_prompt_submit.ts",
17
+ "timeout": 10000
18
+ }
19
+ ]
20
+ },
4
21
  {
5
22
  "hooks": [
6
23
  {
@@ -12,6 +29,56 @@
12
29
  }
13
30
  ],
14
31
  "PostToolUse": [
32
+ {
33
+ "matcher": "*",
34
+ "hooks": [
35
+ {
36
+ "type": "command",
37
+ "command": "bun ~/.aiwcli/bin/resolve-run.ts .aiwcli/_shared/hooks-ts/context_monitor.ts",
38
+ "timeout": 5000
39
+ }
40
+ ]
41
+ },
42
+ {
43
+ "matcher": "TaskCreate",
44
+ "hooks": [
45
+ {
46
+ "type": "command",
47
+ "command": "bun ~/.aiwcli/bin/resolve-run.ts .aiwcli/_shared/hooks-ts/task_create_capture.ts",
48
+ "timeout": 3000
49
+ }
50
+ ]
51
+ },
52
+ {
53
+ "matcher": "TaskUpdate",
54
+ "hooks": [
55
+ {
56
+ "type": "command",
57
+ "command": "bun ~/.aiwcli/bin/resolve-run.ts .aiwcli/_shared/hooks-ts/task_update_capture.ts",
58
+ "timeout": 3000
59
+ }
60
+ ]
61
+ },
62
+ {
63
+ "matcher": "ExitPlanMode",
64
+ "hooks": [
65
+ {
66
+ "type": "command",
67
+ "command": "bun ~/.aiwcli/bin/resolve-run.ts .aiwcli/_shared/hooks-ts/archive_plan.ts",
68
+ "timeout": 5000
69
+ }
70
+ ]
71
+ },
72
+ {
73
+ "matcher": "Write|Edit",
74
+ "hooks": [
75
+ {
76
+ "type": "command",
77
+ "command": "bun ~/.aiwcli/bin/resolve-run.ts .aiwcli/_shared/hooks-ts/lint_after_edit.ts",
78
+ "timeout": 10000
79
+ }
80
+ ]
81
+ },
15
82
  {
16
83
  "matcher": "AskUserQuestion",
17
84
  "hooks": [
@@ -44,6 +111,51 @@
44
111
  ]
45
112
  }
46
113
  ],
114
+ "SessionStart": [
115
+ {
116
+ "hooks": [
117
+ {
118
+ "type": "command",
119
+ "command": "bun ~/.aiwcli/bin/resolve-run.ts .aiwcli/_shared/hooks-ts/session_start.ts",
120
+ "timeout": 5000
121
+ }
122
+ ]
123
+ }
124
+ ],
125
+ "SessionEnd": [
126
+ {
127
+ "hooks": [
128
+ {
129
+ "type": "command",
130
+ "command": "bun ~/.aiwcli/bin/resolve-run.ts .aiwcli/_shared/hooks-ts/session_end.ts",
131
+ "timeout": 5000
132
+ }
133
+ ]
134
+ }
135
+ ],
136
+ "PreCompact": [
137
+ {
138
+ "hooks": [
139
+ {
140
+ "type": "command",
141
+ "command": "bun ~/.aiwcli/bin/resolve-run.ts .aiwcli/_shared/hooks-ts/pre_compact.ts",
142
+ "timeout": 5000
143
+ }
144
+ ]
145
+ }
146
+ ],
147
+ "PermissionRequest": [
148
+ {
149
+ "matcher": "ExitPlanMode",
150
+ "hooks": [
151
+ {
152
+ "type": "command",
153
+ "command": "bun ~/.aiwcli/bin/resolve-run.ts .aiwcli/_shared/hooks-ts/archive_plan.ts",
154
+ "timeout": 5000
155
+ }
156
+ ]
157
+ }
158
+ ],
47
159
  "PreToolUse": [
48
160
  {
49
161
  "matcher": "^TaskCreate$",
@@ -83,5 +195,13 @@
83
195
  "env": {
84
196
  "CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS": "1"
85
197
  },
86
- "enabledPlugins": {}
198
+ "enabledPlugins": {},
199
+ "methods": {
200
+ "cc-native": {
201
+ "ides": [
202
+ "claude"
203
+ ],
204
+ "installedAt": "2026-02-21T16:59:33.520Z"
205
+ }
206
+ }
87
207
  }
@@ -0,0 +1,73 @@
1
+ # CC-Native Method
2
+
3
+ **Location:** `.aiwcli/_cc-native/` — Claude Code-specific plan review, artifacts, and agent orchestration.
4
+
5
+ ---
6
+
7
+ ## Subsystems
8
+
9
+ | Directory | Purpose | CLAUDE.md |
10
+ |-----------|---------|-----------|
11
+ | `agents/` | Plan review agent roster and specs | `agents/CLAUDE.md` |
12
+ | `artifacts/` | Review artifact generation and tracking | `artifacts/CLAUDE.md` |
13
+ | `hooks/` | CC-native hook entry points (plan review triggers) | `hooks/CLAUDE.md` |
14
+ | `lib-ts/` | Shared TypeScript library for cc-native subsystems | `lib-ts/CLAUDE.md` |
15
+ | `lib-ts/rlm/` | Retrieval-augmented learning memory | `lib-ts/rlm/CLAUDE.md` |
16
+ | `plan-review/` | Multi-agent plan review pipeline | `plan-review/CLAUDE.md` |
17
+
18
+ ---
19
+
20
+ ## Shared Infrastructure (`_shared/lib-ts/`)
21
+
22
+ CC-native code depends heavily on shared infrastructure. Full API details: `_shared/lib-ts/CLAUDE.md`.
23
+
24
+ | Module | Capability | Use When |
25
+ |--------|-----------|----------|
26
+ | `base/hook-utils` | Hook lifecycle (load input, run, emit context) | Writing hooks |
27
+ | `base/logger` | Structured logging (debug/info/warn/error) | Any hook or lib module |
28
+ | `base/constants` | Project paths, context dirs, sanitization | Resolving file locations |
29
+ | `base/subprocess-utils` | Find executables, exec with env, shell quoting | Spawning agent CLIs |
30
+ | `base/cli-args` | CLI invocation builder, review spec construction | Launching review agents |
31
+ | `base/atomic-write` | Crash-safe file writes | Writing state or artifacts |
32
+ | `base/state-io` | State read/write helpers | Context state persistence |
33
+ | `base/inference` | Claude CLI subprocess calls | AI inference from hooks |
34
+ | `context/context-store` | Context CRUD (get by session, list all) | Session/context binding |
35
+ | `context/plan-manager` | Plan lifecycle (archive, hash, sign) | Plan discovery and hashing |
36
+ | `types` | Shared type definitions (`ContextState`, etc.) | Type imports |
37
+
38
+ ---
39
+
40
+ ## Import Patterns
41
+
42
+ **Import direction:** `hooks/` → `lib-ts/` → `_shared/lib-ts/`. Never the reverse.
43
+
44
+ ```typescript
45
+ // From hooks/ (2 levels up to _shared):
46
+ import { runHook, logInfo } from "../../_shared/lib-ts/base/hook-utils.js";
47
+ import { loadConfig } from "../lib-ts/config.js";
48
+
49
+ // From lib-ts/ (2 levels up to _shared):
50
+ import { logDebug } from "../../_shared/lib-ts/base/logger.js";
51
+ import { atomicWrite } from "../../_shared/lib-ts/base/atomic-write.js";
52
+
53
+ // From plan-review/lib/ (3 levels up to _shared):
54
+ import { logInfo } from "../../../_shared/lib-ts/base/logger.js";
55
+ ```
56
+
57
+ ---
58
+
59
+ ## Context Maintenance
60
+
61
+ **After modifying files in this directory:** scan the entries above — if any claim is now
62
+ false or incomplete, update this file before ending the task. Do not defer.
63
+
64
+ **Add** an entry only if an agent would fail without knowing it, it is not obvious from
65
+ the code, and it belongs at this scope.
66
+
67
+ **Remove** any entry that fails the falsifiability test: if removing it would not change
68
+ how an agent acts here, remove it.
69
+
70
+ **Staleness anchor:** This file assumes `lib-ts/index.ts` exists. If it doesn't, this file
71
+ is stale — update or regenerate before relying on it.
72
+
73
+ <!-- context-layer: generated=2026-03-01 | last-audited=2026-03-01 | version=1 | dir-commits-at-audit=15 -->
@@ -0,0 +1,70 @@
1
+ # CC-Native Library
2
+
3
+ **Location:** `_cc-native/lib-ts/` — TypeScript modules for plan review, state, and agent orchestration.
4
+
5
+ **Import direction:** `hooks/` → `lib-ts/` → `_shared/lib-ts/`. Never the reverse.
6
+
7
+ ---
8
+
9
+ ## Module Reference
10
+
11
+ The barrel `index.ts` re-exports most modules. Three files are **not** re-exported and must be imported directly: `plan-discovery.ts`, `plan-enhancement.ts`, `settings.ts`.
12
+
13
+ | File | Purpose | Key Exports |
14
+ |------|---------|-------------|
15
+ | `aggregate-agents.ts` | Agent frontmatter parser — loads agent configs from markdown | `aggregateAgents`, `extractBody`, `extractFrontmatter` |
16
+ | `cc-native-state.ts` | CC-native state accessor for context `state.json` | `getCcNativeState`, `saveCcNativeState`, `isPlanAlreadyReviewed`, `markPlanReviewed`, `markQuestionsAsked` |
17
+ | `cli-output-parser.ts` | Unified Claude CLI JSON output parser | `parseCliOutput` |
18
+ | `config.ts` | Configuration loading from `cc-native.config.json` | `loadConfig`, `getDisplaySettings` |
19
+ | `constants.ts` | Feature flags, security limits, path validation | `ENABLE_ROBUST_PLAN_WRITES`, `PLANS_DIR`, `validatePlanPath`, `MAX_RETRY_ATTEMPTS` |
20
+ | `debug.ts` | Per-context debug logging (thin layer over shared logger) | `debugLog`, `debugRaw`, `getDebugDir`, `cleanupDebugFolder` |
21
+ | `index.ts` | Barrel — re-exports public API from all modules | (see individual modules) |
22
+ | `json-parser.ts` | JSON parsing with recovery for LLM responses | `parseJsonMaybe`, `coerceToReview` |
23
+ | `plan-discovery.ts` | Plan file discovery, reading, and hashing | *(not re-exported)* — import directly |
24
+ | `plan-enhancement.ts` | Plan quality guidance prompt for context emission | *(not re-exported)* — import directly |
25
+ | `settings.ts` | Settings loading, defaults, agent library management | *(not re-exported)* — import directly |
26
+ | `state.ts` | Iteration state management for plan review cycles | `loadState`, `saveStateToPlan`, `getIterationState`, `shouldContinueIterating` |
27
+ | `types.ts` | All cc-native type definitions and prompt constants | `Verdict`, `ReviewData`, `AgentConfig`, `PlanReviewConfig`, `REVIEW_SCHEMA` |
28
+
29
+ **Subfolder:** `rlm/` — retrieval-augmented learning memory. Has its own `rlm/CLAUDE.md`.
30
+
31
+ ---
32
+
33
+ ## Shared Dependencies
34
+
35
+ These `_shared/lib-ts` modules are used across cc-native lib-ts:
36
+
37
+ | Shared Module | Used By |
38
+ |--------------|---------|
39
+ | `base/logger` | All modules (logging) |
40
+ | `base/atomic-write` | `state.ts` (crash-safe writes) |
41
+ | `base/utils` | `cc-native-state.ts` (`nowIso`) |
42
+ | `context/context-store` | `cc-native-state.ts` (state access) |
43
+ | `context/plan-manager` | `plan-discovery.ts` (plan path lookup) |
44
+ | `types` | `types.ts` (re-exports `ContextState`, `HookInput`, `HookOutput`) |
45
+
46
+ ---
47
+
48
+ ## Import Direction
49
+
50
+ ```
51
+ hooks/ (entry points — import from lib-ts/ and _shared/)
52
+
53
+ lib-ts/ (this directory — import from _shared/ only)
54
+
55
+ _shared/lib-ts/ (cross-method infrastructure — no reverse imports)
56
+ ```
57
+
58
+ Never import from `hooks/` or `plan-review/` into `lib-ts/`. The one exception noted in `aggregate-agents.ts`: it stays in `lib-ts/` because both `settings.ts` and `plan-review/` depend on it.
59
+
60
+ ---
61
+
62
+ ## Context Maintenance
63
+
64
+ **After modifying files in this directory:** scan the entries above — if any claim is now
65
+ false or incomplete, update this file before ending the task. Do not defer.
66
+
67
+ **Staleness anchor:** This file assumes `index.ts` exists with 13 sibling `.ts` files. If the
68
+ count changes, update the Module Reference table.
69
+
70
+ <!-- context-layer: generated=2026-03-01 | last-audited=2026-03-01 | version=1 | dir-commits-at-audit=15 -->
@@ -16,6 +16,7 @@ import type {
16
16
  } from "./types.js";
17
17
  import { DEFAULT_DISPLAY, DEFAULT_SANITIZATION } from "./types.js";
18
18
  import { logInfo } from "../../_shared/lib-ts/base/logger.js";
19
+ import { CODEX_MODELS } from "../../_shared/lib-ts/base/models.js";
19
20
 
20
21
  const HOOK = "settings";
21
22
 
@@ -71,7 +72,7 @@ export const DEFAULT_COMPLEXITY_CATEGORIES = ["code", "infrastructure", "documen
71
72
  export const DEFAULT_MODELS_CONFIG: ModelsConfig = {
72
73
  providers: {
73
74
  claude: { enabled: false, models: ["sonnet"] },
74
- codex: { enabled: true, models: ["gpt-5.2"] },
75
+ codex: { enabled: true, models: [CODEX_MODELS.codex] },
75
76
  },
76
77
  };
77
78
 
@@ -7,6 +7,10 @@
7
7
  // Re-export shared types used by cc-native consumers
8
8
  export type { ContextState, HookInput, HookOutput } from "../../_shared/lib-ts/types.js";
9
9
 
10
+ // Import AgentConfig for local use and re-export
11
+ import type { AgentConfig as _AgentConfig } from "../../_shared/lib-ts/types.js";
12
+ export type AgentConfig = _AgentConfig;
13
+
10
14
  // ---------------------------------------------------------------------------
11
15
  // Verdict & Decision Types
12
16
  // ---------------------------------------------------------------------------
@@ -118,17 +122,7 @@ export interface ReviewDecisionResult {
118
122
  // Agent & Orchestrator Configuration
119
123
  // ---------------------------------------------------------------------------
120
124
 
121
- /** Configuration for a Claude Code review agent */
122
- export interface AgentConfig {
123
- name: string;
124
- model: string;
125
- provider: string; // e.g. "claude" | "codex" — assigned at runtime by assignModelsToAgents()
126
- focus: string;
127
- categories: string[];
128
- description: string;
129
- system_prompt: string; // Markdown body content for --system-prompt
130
- reasoningEffort?: string; // e.g. "low", "medium", "high" — passed to codex -c model_reasoning_effort
131
- }
125
+ // AgentConfig re-exported from _shared/lib-ts/types.ts above
132
126
 
133
127
  /** Configuration for the plan orchestrator */
134
128
  export interface OrchestratorConfig {
@@ -141,7 +135,6 @@ export interface OrchestratorConfig {
141
135
  export interface ProviderConfig {
142
136
  enabled: boolean;
143
137
  models: string[];
144
- reasoningEffort?: string; // e.g. "low", "medium", "high" — codex model_reasoning_effort
145
138
  }
146
139
 
147
140
  /** Model provider pool configuration */