@njeybe/nativ 2.4.1 → 2.5.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 (139) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +26 -0
  3. package/dist/commands/db/db-formatter.d.ts +5 -0
  4. package/dist/commands/db/db-formatter.js +116 -0
  5. package/dist/commands/db/db-introspect.d.ts +11 -0
  6. package/dist/commands/db/db-introspect.js +84 -0
  7. package/dist/commands/db.js +4 -206
  8. package/dist/commands/profile.d.ts +3 -0
  9. package/dist/commands/profile.js +39 -0
  10. package/dist/commands/task/task-add.d.ts +11 -0
  11. package/dist/commands/task/task-add.js +169 -0
  12. package/dist/commands/task/task-common.d.ts +57 -0
  13. package/dist/commands/task/task-common.js +45 -0
  14. package/dist/commands/task/task-escalate.d.ts +7 -0
  15. package/dist/commands/task/task-escalate.js +119 -0
  16. package/dist/commands/task/task-lifecycle.d.ts +5 -0
  17. package/dist/commands/task/task-lifecycle.js +252 -0
  18. package/dist/commands/task/task-query.d.ts +10 -0
  19. package/dist/commands/task/task-query.js +269 -0
  20. package/dist/commands/task.d.ts +9 -87
  21. package/dist/commands/task.js +8 -850
  22. package/dist/commands/triage/triage-store.d.ts +56 -0
  23. package/dist/commands/triage/triage-store.js +108 -0
  24. package/dist/commands/triage/triage-ui.d.ts +14 -0
  25. package/dist/commands/triage/triage-ui.js +104 -0
  26. package/dist/commands/triage.d.ts +3 -52
  27. package/dist/commands/triage.js +8 -216
  28. package/dist/core/enforcement.d.ts +1 -0
  29. package/dist/core/enforcement.js +19 -0
  30. package/dist/core/human-gate.d.ts +2 -1
  31. package/dist/core/human-gate.js +9 -2
  32. package/dist/core/profiles.d.ts +14 -0
  33. package/dist/core/profiles.js +82 -0
  34. package/dist/core/setup/config-merger.d.ts +59 -0
  35. package/dist/core/setup/config-merger.js +107 -0
  36. package/dist/core/setup/session-context.d.ts +4 -0
  37. package/dist/core/setup/session-context.js +65 -0
  38. package/dist/core/setup/setup-planner.d.ts +14 -0
  39. package/dist/core/setup/setup-planner.js +180 -0
  40. package/dist/core/setup/template-planner.d.ts +8 -0
  41. package/dist/core/setup/template-planner.js +32 -0
  42. package/dist/core/setup/types.d.ts +65 -0
  43. package/dist/core/setup/types.js +55 -0
  44. package/dist/core/setup-assets.d.ts +8 -119
  45. package/dist/core/setup-assets.js +7 -437
  46. package/dist/core/tier1-liaison.d.ts +2 -0
  47. package/dist/core/tier1-liaison.js +64 -3
  48. package/dist/core/verifier/executor.d.ts +5 -0
  49. package/dist/core/verifier/executor.js +62 -0
  50. package/dist/core/verifier/phases.d.ts +5 -0
  51. package/dist/core/verifier/phases.js +71 -0
  52. package/dist/core/verifier/task-verifier.d.ts +37 -0
  53. package/dist/core/verifier/task-verifier.js +233 -0
  54. package/dist/core/verifier/types.d.ts +51 -0
  55. package/dist/core/verifier/types.js +1 -0
  56. package/dist/core/verifier.d.ts +5 -93
  57. package/dist/core/verifier.js +5 -359
  58. package/dist/db/introspector.js +59 -59
  59. package/dist/governor/evaluator.d.ts +4 -64
  60. package/dist/governor/evaluator.js +21 -686
  61. package/dist/governor/patch-applier.d.ts +8 -0
  62. package/dist/governor/patch-applier.js +121 -0
  63. package/dist/governor/self-healing.d.ts +24 -0
  64. package/dist/governor/self-healing.js +351 -0
  65. package/dist/governor/test-integrity.d.ts +41 -0
  66. package/dist/governor/test-integrity.js +237 -0
  67. package/dist/index.js +8 -0
  68. package/dist/mcp/capture.d.ts +4 -0
  69. package/dist/mcp/capture.js +33 -0
  70. package/dist/mcp/resources.d.ts +39 -0
  71. package/dist/mcp/resources.js +44 -0
  72. package/dist/mcp/server.d.ts +11 -0
  73. package/dist/mcp/server.js +14 -89
  74. package/dist/mcp/tools.d.ts +1 -0
  75. package/dist/mcp/tools.js +1 -0
  76. package/dist/runner/agent-supervisor.d.ts +8 -302
  77. package/dist/runner/agent-supervisor.js +41 -1030
  78. package/dist/runner/cli-config.d.ts +84 -0
  79. package/dist/runner/cli-config.js +215 -0
  80. package/dist/runner/native-driver.d.ts +18 -0
  81. package/dist/runner/native-driver.js +208 -0
  82. package/dist/runner/native-engine.d.ts +27 -0
  83. package/dist/runner/native-engine.js +184 -0
  84. package/dist/runner/native-tools.d.ts +31 -0
  85. package/dist/runner/native-tools.js +241 -0
  86. package/dist/runner/process-utils.d.ts +12 -0
  87. package/dist/runner/process-utils.js +96 -0
  88. package/dist/runner/run-lifecycle.d.ts +6 -0
  89. package/dist/runner/run-lifecycle.js +42 -0
  90. package/dist/runner/types.d.ts +215 -0
  91. package/dist/runner/types.js +41 -0
  92. package/dist/scanner/detector.js +42 -663
  93. package/dist/scanner/detectors/ecosystem-detector.d.ts +16 -0
  94. package/dist/scanner/detectors/ecosystem-detector.js +354 -0
  95. package/dist/scanner/detectors/orm-detector.d.ts +5 -0
  96. package/dist/scanner/detectors/orm-detector.js +59 -0
  97. package/dist/scanner/detectors/workspace-detector.d.ts +19 -0
  98. package/dist/scanner/detectors/workspace-detector.js +266 -0
  99. package/dist/server/cli-runner.d.ts +15 -0
  100. package/dist/server/cli-runner.js +43 -0
  101. package/dist/server/event-hub.d.ts +42 -0
  102. package/dist/server/event-hub.js +169 -0
  103. package/dist/server/http-utils.d.ts +15 -0
  104. package/dist/server/http-utils.js +56 -0
  105. package/dist/server/plan-utils.d.ts +9 -0
  106. package/dist/server/plan-utils.js +31 -0
  107. package/dist/server/routes/db-routes.d.ts +57 -0
  108. package/dist/server/routes/db-routes.js +484 -0
  109. package/dist/server/routes/task-routes.d.ts +266 -0
  110. package/dist/server/routes/task-routes.js +285 -0
  111. package/dist/server/routes/telemetry-routes.d.ts +128 -0
  112. package/dist/server/routes/telemetry-routes.js +179 -0
  113. package/dist/server/routes/triage-routes.d.ts +81 -0
  114. package/dist/server/routes/triage-routes.js +244 -0
  115. package/dist/server/routes/worktree-routes.d.ts +31 -0
  116. package/dist/server/routes/worktree-routes.js +144 -0
  117. package/dist/server/studio-server.d.ts +4 -11
  118. package/dist/server/studio-server.js +34 -1578
  119. package/dist/server/studio-ui/shell/pipeline-state.js +2 -0
  120. package/dist/server/studio-ui/shell/triage.js +10 -0
  121. package/package.json +2 -2
  122. package/plugin/.claude-plugin/plugin.json +1 -1
  123. package/plugin/agents/architect.md +4 -2
  124. package/plugin/agents/verifier.md +1 -1
  125. package/plugin/agents/worker.md +7 -4
  126. package/plugin/skills/nativ/SKILL.md +1 -0
  127. package/templates/.claudeignore +62 -45
  128. package/templates/AGENTS.md +1 -0
  129. package/templates/CLAUDE.md +13 -0
  130. package/templates/claude-agents/architect.md +4 -2
  131. package/templates/claude-agents/verifier.md +1 -1
  132. package/templates/claude-agents/worker.md +7 -4
  133. package/templates/dot-ai/api_contracts.json +66 -66
  134. package/templates/dot-ai/context.md +38 -38
  135. package/templates/dot-ai/db_schema.json +39 -39
  136. package/dist/commands/session.d.ts +0 -22
  137. package/dist/commands/session.js +0 -106
  138. package/dist/core/session-memory.d.ts +0 -42
  139. package/dist/core/session-memory.js +0 -121
@@ -0,0 +1,215 @@
1
+ import type { ChildProcess } from 'node:child_process';
2
+ import type Anthropic from '@anthropic-ai/sdk';
3
+ import type { ActualTokenUsage } from '../core/telemetry.js';
4
+ import type { MasterPlanTask } from '../scanner/types.js';
5
+ /**
6
+ * Lifecycle phases broadcast on the `runner_status` channel. These mirror the
7
+ * phases declared in .ai/api_contracts.json (sseChannels → runner_status).
8
+ */
9
+ export type RunnerStatus = 'spawning_worktree' | 'running' | 'verifying' | 'merging' | 'completed' | 'failed' | 'aborted';
10
+ export declare const ACTIVE_RUNNER_STATUSES: readonly RunnerStatus[];
11
+ export declare function isActiveStatus(status: RunnerStatus): boolean;
12
+ /**
13
+ * `native` drives the Messages API in-process with local bash/editor tools;
14
+ * `cli` spawns a runner command (Claude Code by default).
15
+ */
16
+ export type RunnerEngine = 'native' | 'cli';
17
+ export type ThinkingEffort = 'low' | 'medium' | 'high' | 'xhigh' | 'max';
18
+ export interface RunnerThinking {
19
+ /** The dispatch's `thinkingBudget`, echoed back; null when unset. */
20
+ budget: number | null;
21
+ /** `output_config.effort` sent to adaptive-thinking models; null otherwise. */
22
+ effort: ThinkingEffort | null;
23
+ /** Literal `budget_tokens` (legacy models) or `MAX_THINKING_TOKENS` (cli); null otherwise. */
24
+ budgetTokens: number | null;
25
+ }
26
+ /** Payload of the `runner_token_usage` channel, emitted after every native turn. */
27
+ export interface RunnerTokenUsageEvent {
28
+ runId: string;
29
+ taskId: string;
30
+ /** Model that served this turn (differs from the requested one after a refusal fallback). */
31
+ model: string;
32
+ turn: number;
33
+ delta: ActualTokenUsage;
34
+ total: ActualTokenUsage & {
35
+ cacheHitRate: number;
36
+ };
37
+ at: string;
38
+ }
39
+ /** Persisted, serializable state of a single agent execution. */
40
+ export interface RunnerRecord {
41
+ runId: string;
42
+ taskId: string;
43
+ status: RunnerStatus;
44
+ engine: RunnerEngine;
45
+ /** Requested model; null for cli runs that keep the runner's own default. */
46
+ model: string | null;
47
+ thinking: RunnerThinking | null;
48
+ /** API-reported usage accumulated across turns; null for cli runs. */
49
+ usage: ActualTokenUsage | null;
50
+ /** PID of the spawned process-group leader; null before spawn and after exit. */
51
+ pid: number | null;
52
+ /** Branch backing the isolated worktree, or null when running in place. */
53
+ branch: string | null;
54
+ /** Absolute worktree path, or the project root when `useWorktree` is false. */
55
+ worktreeDir: string;
56
+ command: string;
57
+ startedAt: string;
58
+ endedAt: string | null;
59
+ durationMs: number | null;
60
+ exitCode: number | null;
61
+ signal: string | null;
62
+ timeoutSeconds: number;
63
+ timedOut: boolean;
64
+ logBytes: number;
65
+ logFile: string;
66
+ error: string | null;
67
+ abortReason: string | null;
68
+ verification: {
69
+ command: string;
70
+ success: boolean;
71
+ exitCode: number;
72
+ durationMs: number;
73
+ skipped: boolean;
74
+ /** Why it failed: a named phase, an unreadable config, or the code-shape block. */
75
+ error?: string;
76
+ phases?: Array<{
77
+ name: string;
78
+ success: boolean;
79
+ durationMs: number;
80
+ }>;
81
+ } | null;
82
+ }
83
+ export interface DispatchOptions {
84
+ taskId: string;
85
+ /** Defaults to the supervisor's `defaultEngine` (`cli` unless configured). */
86
+ runnerEngine?: RunnerEngine;
87
+ /** Shell command that launches the agent (cli engine only). Defaults to `defaultRunnerCommand`. */
88
+ runnerCommand?: string;
89
+ /**
90
+ * Reasoning budget in tokens. Adaptive-thinking models receive it as an
91
+ * `effort` level (they reject `budget_tokens`); legacy models receive it
92
+ * literally; the Claude Code CLI receives it as `MAX_THINKING_TOKENS`.
93
+ */
94
+ thinkingBudget?: number;
95
+ /** Model ID. Native runs default to `defaultNativeModel`; cli runs pass it as `--model`. */
96
+ model?: string;
97
+ /** Killswitch budget in seconds. Defaults to the supervisor's `defaultTimeoutSeconds`. */
98
+ timeoutSeconds?: number;
99
+ /** Run inside `.worktrees/task-<id>` on branch `agent/task-<id>`. Default true. */
100
+ useWorktree?: boolean;
101
+ /** Run the task's `verificationCommand` after a clean exit. Default false. */
102
+ verify?: boolean;
103
+ /** Merge the agent branch back after a passing verification. Default false. */
104
+ autoMerge?: boolean;
105
+ /** Extra environment variables handed to the child (never logged or persisted). */
106
+ env?: Record<string, string>;
107
+ /** Extra permission rules for the default cli runner, e.g. `Bash(pnpm test *)`. Added to the per-task allowlist. */
108
+ allowedTools?: string[];
109
+ }
110
+ export interface AbortResult {
111
+ taskId: string;
112
+ runId: string;
113
+ status: 'aborted';
114
+ message: string;
115
+ }
116
+ export interface LogSlice {
117
+ taskId: string;
118
+ runId: string | null;
119
+ status: RunnerStatus | null;
120
+ totalBytes: number;
121
+ log: string;
122
+ truncated: boolean;
123
+ }
124
+ export interface ListRunsQuery {
125
+ taskId?: string;
126
+ activeOnly?: boolean;
127
+ }
128
+ export interface AgentSupervisorOptions {
129
+ /** Directory used to resolve the project root holding `.ai/`. Defaults to `process.cwd()`. */
130
+ cwd?: string;
131
+ defaultRunnerCommand?: string;
132
+ defaultTimeoutSeconds?: number;
133
+ /** Hard cap on the in-memory log ring buffer per run. */
134
+ maxLogBufferBytes?: number;
135
+ /** Grace period between SIGTERM and the forced kill during abort/timeout. */
136
+ killGraceMs?: number;
137
+ /**
138
+ * Inactivity watchdog: terminate a run that emits no output for this many seconds. Defaults to
139
+ * `NATIV_RUNNER_IDLE_TIMEOUT`, then `DEFAULT_IDLE_TIMEOUT_SECONDS`; 0 disables it.
140
+ */
141
+ idleTimeoutSeconds?: number;
142
+ /** How many finished runs to keep in memory. */
143
+ maxHistory?: number;
144
+ /** Engine used when a dispatch omits `runnerEngine`. Defaults to `NATIV_RUNNER_ENGINE`, then `cli`. */
145
+ defaultEngine?: RunnerEngine;
146
+ /** Model used by native runs that omit `model`. Defaults to `NATIV_NATIVE_MODEL`, then `DEFAULT_NATIVE_MODEL`. */
147
+ defaultNativeModel?: string;
148
+ /** Hard cap on API round-trips per native run. */
149
+ nativeMaxTurns?: number;
150
+ /** Per-command budget for the native bash tool. */
151
+ nativeToolTimeoutMs?: number;
152
+ /** Executables the native bash tool may invoke. */
153
+ nativeAllowedCommands?: readonly string[];
154
+ /** Builds the Claude API client for native runs; injectable for tests. */
155
+ anthropicClientFactory?: () => Anthropic;
156
+ /**
157
+ * Shell for the native bash tool: a path to bash, or `true` for the platform default shell.
158
+ * Defaults to NATIV_BASH_PATH, then Git Bash on Windows, then /bin/bash.
159
+ */
160
+ nativeShell?: string | boolean;
161
+ }
162
+ /** Structured failure carrying the `{ code, message }` shape used by the pipeline API. */
163
+ export declare class SupervisorError extends Error {
164
+ readonly code: string;
165
+ readonly status: number;
166
+ constructor(code: string, message: string, status?: number);
167
+ }
168
+ export declare const DEFAULT_RUNNER_COMMAND = "claude";
169
+ /** Hard cap per run. Real agent tasks routinely take tens of minutes; hung runs are caught by the idle watchdog. */
170
+ export declare const DEFAULT_TIMEOUT_SECONDS = 3600;
171
+ /** A run that produces no output (log lines, tool activity, API turns) for this long is treated as hung. */
172
+ export declare const DEFAULT_IDLE_TIMEOUT_SECONDS = 900;
173
+ export declare const DEFAULT_MAX_LOG_BUFFER_BYTES: number;
174
+ export declare const DEFAULT_KILL_GRACE_MS = 5000;
175
+ export declare const DEFAULT_MAX_HISTORY = 50;
176
+ export declare const DEFAULT_RUNNER_ENGINE: RunnerEngine;
177
+ export declare const DEFAULT_NATIVE_MODEL = "claude-opus-5-5";
178
+ export declare const DEFAULT_NATIVE_EFFORT: ThinkingEffort;
179
+ export declare const DEFAULT_NATIVE_MAX_TURNS = 150;
180
+ export declare const DEFAULT_NATIVE_TOOL_TIMEOUT_MS: number;
181
+ export declare const NATIVE_MAX_OUTPUT_TOKENS = 64000;
182
+ /** Characters of tool output handed back to the model per call. */
183
+ export declare const NATIVE_TOOL_OUTPUT_LIMIT = 30000;
184
+ export declare const DEFAULT_NATIVE_ALLOWED_COMMANDS: readonly string[];
185
+ export interface NativeRunState {
186
+ client: Anthropic;
187
+ model: string;
188
+ thinking: RunnerThinking;
189
+ controller: AbortController;
190
+ /** Dispatch-supplied env for tool commands; secret-looking keys are still filtered out. */
191
+ env?: Record<string, string>;
192
+ }
193
+ export interface ActiveRun {
194
+ record: RunnerRecord;
195
+ task: MasterPlanTask;
196
+ child: ChildProcess | null;
197
+ timer: NodeJS.Timeout | null;
198
+ killTimer: NodeJS.Timeout | null;
199
+ buffer: string;
200
+ aborting: boolean;
201
+ /** Set once the run reaches a terminal status; later exits and callbacks are ignored. */
202
+ settled: boolean;
203
+ native: NativeRunState | null;
204
+ /** PID of the native bash tool's current command, if one is executing. */
205
+ toolPid: number | null;
206
+ /** Epoch ms of the last output; drives the inactivity watchdog. */
207
+ lastActivity: number;
208
+ idleTimer: NodeJS.Timeout | null;
209
+ /** The runner prints Claude Code stream-json events, one JSON object per line. */
210
+ streamJson: boolean;
211
+ /** Incomplete trailing line of stream-json stdout. */
212
+ lineBuffer: string;
213
+ /** Model reported by the stream's init event (cli runs without an explicit model). */
214
+ streamModel: string | null;
215
+ }
@@ -0,0 +1,41 @@
1
+ export const ACTIVE_RUNNER_STATUSES = [
2
+ 'spawning_worktree',
3
+ 'running',
4
+ 'verifying',
5
+ 'merging',
6
+ ];
7
+ export function isActiveStatus(status) {
8
+ return ACTIVE_RUNNER_STATUSES.includes(status);
9
+ }
10
+ /** Structured failure carrying the `{ code, message }` shape used by the pipeline API. */
11
+ export class SupervisorError extends Error {
12
+ code;
13
+ status;
14
+ constructor(code, message, status = 400) {
15
+ super(message);
16
+ this.code = code;
17
+ this.status = status;
18
+ this.name = 'SupervisorError';
19
+ }
20
+ }
21
+ export const DEFAULT_RUNNER_COMMAND = 'claude';
22
+ /** Hard cap per run. Real agent tasks routinely take tens of minutes; hung runs are caught by the idle watchdog. */
23
+ export const DEFAULT_TIMEOUT_SECONDS = 3600;
24
+ /** A run that produces no output (log lines, tool activity, API turns) for this long is treated as hung. */
25
+ export const DEFAULT_IDLE_TIMEOUT_SECONDS = 900;
26
+ export const DEFAULT_MAX_LOG_BUFFER_BYTES = 512 * 1024;
27
+ export const DEFAULT_KILL_GRACE_MS = 5_000;
28
+ export const DEFAULT_MAX_HISTORY = 50;
29
+ export const DEFAULT_RUNNER_ENGINE = 'cli';
30
+ export const DEFAULT_NATIVE_MODEL = 'claude-opus-5-5';
31
+ export const DEFAULT_NATIVE_EFFORT = 'high';
32
+ export const DEFAULT_NATIVE_MAX_TURNS = 150;
33
+ export const DEFAULT_NATIVE_TOOL_TIMEOUT_MS = 10 * 60 * 1000;
34
+ export const NATIVE_MAX_OUTPUT_TOKENS = 64_000;
35
+ /** Characters of tool output handed back to the model per call. */
36
+ export const NATIVE_TOOL_OUTPUT_LIMIT = 30_000;
37
+ export const DEFAULT_NATIVE_ALLOWED_COMMANDS = [
38
+ 'nativ', 'node', 'npm', 'npx', 'tsx', 'tsc', 'git',
39
+ 'cd', 'ls', 'dir', 'pwd', 'cat', 'head', 'tail', 'grep', 'rg', 'find', 'wc', 'diff', 'sort', 'uniq',
40
+ 'echo', 'printf', 'mkdir', 'touch', 'cp', 'mv', 'rm', 'sed', 'awk', 'test', 'true', 'false',
41
+ ];