duckhunt-runner 0.3.1 → 0.4.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/README.md +78 -3
- package/dist/claim.d.ts +86 -0
- package/dist/claim.d.ts.map +1 -0
- package/dist/claim.js +180 -0
- package/dist/claim.js.map +1 -0
- package/dist/claude-args.d.ts +23 -0
- package/dist/claude-args.d.ts.map +1 -0
- package/dist/claude-args.js +59 -0
- package/dist/claude-args.js.map +1 -0
- package/dist/claude.d.ts +22 -3
- package/dist/claude.d.ts.map +1 -1
- package/dist/claude.js +17 -6
- package/dist/claude.js.map +1 -1
- package/dist/config.d.ts +1 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +3 -1
- package/dist/config.js.map +1 -1
- package/dist/conversation-gc.d.ts +22 -0
- package/dist/conversation-gc.d.ts.map +1 -0
- package/dist/conversation-gc.js +72 -0
- package/dist/conversation-gc.js.map +1 -0
- package/dist/daemon.d.ts +16 -5
- package/dist/daemon.d.ts.map +1 -1
- package/dist/daemon.js +371 -171
- package/dist/daemon.js.map +1 -1
- package/dist/event-uploader.d.ts +31 -0
- package/dist/event-uploader.d.ts.map +1 -0
- package/dist/event-uploader.js +124 -0
- package/dist/event-uploader.js.map +1 -0
- package/dist/feed.d.ts +29 -0
- package/dist/feed.d.ts.map +1 -0
- package/dist/feed.js +142 -0
- package/dist/feed.js.map +1 -0
- package/dist/index.js +14 -4
- package/dist/index.js.map +1 -1
- package/dist/oauth.d.ts.map +1 -1
- package/dist/oauth.js +5 -2
- package/dist/oauth.js.map +1 -1
- package/dist/scrub-env.d.ts +3 -0
- package/dist/scrub-env.d.ts.map +1 -0
- package/dist/scrub-env.js +59 -0
- package/dist/scrub-env.js.map +1 -0
- package/dist/secret-mask.d.ts +4 -0
- package/dist/secret-mask.d.ts.map +1 -0
- package/dist/secret-mask.js +34 -0
- package/dist/secret-mask.js.map +1 -0
- package/dist/status-report.d.ts +30 -0
- package/dist/status-report.d.ts.map +1 -0
- package/dist/status-report.js +61 -0
- package/dist/status-report.js.map +1 -0
- package/dist/status.d.ts.map +1 -1
- package/dist/status.js +2 -0
- package/dist/status.js.map +1 -1
- package/dist/version.d.ts +3 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +21 -0
- package/dist/version.js.map +1 -0
- package/dist/worktree.d.ts +29 -0
- package/dist/worktree.d.ts.map +1 -0
- package/dist/worktree.js +190 -0
- package/dist/worktree.js.map +1 -0
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -7,9 +7,13 @@ queues an *agent run*. This daemon claims it and launches **Claude Code headless
|
|
|
7
7
|
machine**, so the agent works with your Claude login, your git checkouts and your AWS CLI. It
|
|
8
8
|
writes the verdict back to duckhunt as a work note, which reaches you as a push notification.
|
|
9
9
|
|
|
10
|
+
You can also start a run yourself: the *Agents* page in duckhunt is a chat with an agent running
|
|
11
|
+
on this machine, in a checkout of one of your repos (see [Prompt runs](#prompt-runs)).
|
|
12
|
+
|
|
10
13
|
The server never sees your credentials, your filesystem paths or your git tokens. It only ever
|
|
11
14
|
learns a repo's `workspace/slug` key and, optionally, an AWS account id — never where they live on
|
|
12
|
-
disk.
|
|
15
|
+
disk. With the progress feed on, it also receives what the agent says and one line per tool call
|
|
16
|
+
(see [Progress feed](#progress-feed)), never file contents or command output.
|
|
13
17
|
|
|
14
18
|
## Requirements
|
|
15
19
|
|
|
@@ -42,7 +46,10 @@ That is the whole thing. Step by step:
|
|
|
42
46
|
| `start [--verbose]` | Starts the claim loop. |
|
|
43
47
|
|
|
44
48
|
Configuration lives in `~/.duckhunt-runner.json`. It holds the base URL, the OAuth credential, the
|
|
45
|
-
repo and AWS maps, and optional defaults (`model`, `maxBudgetUsd`).
|
|
49
|
+
repo and AWS maps, and optional defaults (`model`, `maxBudgetUsd`). Set `DUCKHUNT_RUNNER_CONFIG` to use
|
|
50
|
+
another file (a second account, a test instance) and `DUCKHUNT_RUNNER_HOME` to move the state
|
|
51
|
+
directory (`~/.duckhunt-runner`: the scratch directory and `--verbose` logs). `--version` prints the
|
|
52
|
+
daemon version.
|
|
46
53
|
|
|
47
54
|
### Keeping it running
|
|
48
55
|
|
|
@@ -62,6 +69,9 @@ Restart=always
|
|
|
62
69
|
WantedBy=default.target
|
|
63
70
|
```
|
|
64
71
|
|
|
72
|
+
Stopping the daemon (`ctrl-c`, `SIGTERM`) stops the run in progress, including anything its shell
|
|
73
|
+
commands started, and reports it as failed. A second signal exits immediately.
|
|
74
|
+
|
|
65
75
|
## How a run works
|
|
66
76
|
|
|
67
77
|
1. **A run is queued** from duckhunt: the *investigate with agent* action on an entry, the same
|
|
@@ -76,7 +86,8 @@ WantedBy=default.target
|
|
|
76
86
|
|
|
77
87
|
### What an agent is allowed to touch
|
|
78
88
|
|
|
79
|
-
|
|
89
|
+
For automation runs, permission is derived from the conversation, and the server enforces it on the
|
|
90
|
+
run's token:
|
|
80
91
|
|
|
81
92
|
| The run | Can |
|
|
82
93
|
| --- | --- |
|
|
@@ -87,6 +98,70 @@ Permission is derived from the conversation, and the server enforces it on the r
|
|
|
87
98
|
So an unattended run can never change anything, and anything that leaves duckhunt needs you to have
|
|
88
99
|
said yes to that specific action, spelled out with the literal command.
|
|
89
100
|
|
|
101
|
+
## Prompt runs
|
|
102
|
+
|
|
103
|
+
A prompt run is a conversation you start from the *Agents* page: you pick one of the repos mapped
|
|
104
|
+
on this runner (or none), optionally a branch, and write what you want. The daemon runs it like any
|
|
105
|
+
other run, with your Claude login, and every reply or follow-up resumes the same Claude session.
|
|
106
|
+
Requires daemon 0.4.0+ and a Claude CLI that supports `--permission-mode`, `--strict-mcp-config`,
|
|
107
|
+
`--disallowedTools` and `--setting-sources`; otherwise the daemon does not offer prompt runs and is
|
|
108
|
+
never handed one.
|
|
109
|
+
|
|
110
|
+
### Profiles
|
|
111
|
+
|
|
112
|
+
Each conversation has a profile, chosen when it starts. The Claude CLI enforces it (tool allowlist,
|
|
113
|
+
deny list and an explicit `--permission-mode dontAsk`), not the prompt, and the daemon refuses a
|
|
114
|
+
`read` claim that would allow `Bash`, `Edit`, `Write` or `NotebookEdit`:
|
|
115
|
+
|
|
116
|
+
| Profile | Built-in tools | Also |
|
|
117
|
+
| --- | --- | --- |
|
|
118
|
+
| `read` | `Read`, `Grep`, `Glob` | duckhunt tools (notes, tasks, questions). No shell, no edits. Runs with `--setting-sources user`: your own settings, hooks and plugins apply, but the checked-out branch's `.claude/` settings and hooks do not (the agent reads the repo's `CLAUDE.md` with `Read` instead). |
|
|
119
|
+
| `edit` | `Read`, `Grep`, `Glob`, `Bash`, `Edit`, `Write` | Git included: the agent commits, pushes or opens a pull request only when your prompt asks for it. Starting an `edit` conversation, and every later message or answer to it, asks you to confirm your identity again; its notifications have no reply buttons. |
|
|
120
|
+
|
|
121
|
+
Every prompt run uses `--strict-mcp-config`, so a `.mcp.json` in the checkout never loads.
|
|
122
|
+
Settings → Agents can force `read` for everything (read-only mode) or per repo, pause the runner,
|
|
123
|
+
or stop it from accepting prompt runs. Read-only mode applies to existing `edit` conversations from
|
|
124
|
+
their next step on. A per-repo `read` lock covers conversations on that repo; it is not a sandbox,
|
|
125
|
+
since an `edit` conversation on another repo (or none) still has a shell. Prompt runs have no turn or budget limit: each step is capped
|
|
126
|
+
at 30 minutes of wall-clock time, and the model is your `defaults.model` (or the CLI default).
|
|
127
|
+
`worktree: false` and `--dangerously-skip-permissions` in the repo map only apply to automation runs.
|
|
128
|
+
|
|
129
|
+
### One worktree per conversation
|
|
130
|
+
|
|
131
|
+
A prompt run works in its own git worktree, `<checkout>/.duckhunt/worktrees/conv-<id>`. It is
|
|
132
|
+
created detached on `origin/<branch>` right after a `git fetch`; if the branch does not exist yet,
|
|
133
|
+
on the remote's default branch, and the agent creates the branch if you ask for one. A branch name
|
|
134
|
+
that `git check-ref-format` rejects falls back to the default branch, with a note in the feed. The
|
|
135
|
+
worktree survives between steps, so edits are still there when you answer a question or send a
|
|
136
|
+
follow-up; if you delete its directory by hand, the next step recreates it.
|
|
137
|
+
|
|
138
|
+
Each claim carries a step number that the daemon sends back with every heartbeat, progress update,
|
|
139
|
+
feed batch and status report. When you stop a conversation, write to it again, or duckhunt gives up
|
|
140
|
+
on a step, the next heartbeat tells the daemon the run is no longer its own and it kills Claude and
|
|
141
|
+
its whole process group; a late report from that step never closes the step that replaced it.
|
|
142
|
+
|
|
143
|
+
Between runs (at most every 30 minutes) the daemon removes the worktrees of conversations that
|
|
144
|
+
duckhunt reports as closed, and any worktree unused for 7 days. It never removes one with
|
|
145
|
+
uncommitted changes or with commits that no branch or remote contains: those are kept and logged, and
|
|
146
|
+
you can remove them with `git worktree remove` when you are done. Worktrees kept from failed
|
|
147
|
+
automation runs (`run-<id>`) expire after the same 7 days.
|
|
148
|
+
|
|
149
|
+
### Progress feed
|
|
150
|
+
|
|
151
|
+
While a run works, the daemon streams a short feed to duckhunt with what the agent says and one line
|
|
152
|
+
per tool call: the tool name and a short argument (a path relative to the worktree, a search
|
|
153
|
+
pattern, the first line of a shell command, the task or entry a duckhunt tool touches). It never
|
|
154
|
+
sends tool results, file contents or command output. Paths are shortened (`.` for the worktree, `~`
|
|
155
|
+
for your home; a file opened outside the worktree shows only its name) and anything that looks like
|
|
156
|
+
a secret (AWS keys, GitHub, Slack, Atlassian, Bitbucket and Anthropic tokens, credentials in a remote
|
|
157
|
+
URL, `password=`/`token=`-style assignments, `Bearer` headers, private keys) is masked before it
|
|
158
|
+
leaves the machine, also in the final result, error and stderr; the server masks it again. Set *progress feed* to *counter only* in Settings → Agents to send just the
|
|
159
|
+
tool-call count.
|
|
160
|
+
|
|
161
|
+
The daemon also strips variables of the Claude Code session it may have been started from
|
|
162
|
+
(`CLAUDECODE`, `CLAUDE_CODE_SESSION_ID`…), empty `ANTHROPIC_*` values and a dead `SSH_AUTH_SOCK` from
|
|
163
|
+
the environment of each run, and disables git's terminal prompts.
|
|
164
|
+
|
|
90
165
|
## Licence
|
|
91
166
|
|
|
92
167
|
Copyright © 2026 miermontoto.
|
package/dist/claim.d.ts
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
export declare const RUNNER_CAPABILITY: {
|
|
2
|
+
readonly aws: "aws";
|
|
3
|
+
readonly prompt: "prompt";
|
|
4
|
+
readonly events: "events";
|
|
5
|
+
};
|
|
6
|
+
export type RunnerCapability = (typeof RUNNER_CAPABILITY)[keyof typeof RUNNER_CAPABILITY];
|
|
7
|
+
export declare const RUN_KIND: {
|
|
8
|
+
readonly investigate: "investigate";
|
|
9
|
+
readonly resume: "resume";
|
|
10
|
+
readonly prompt: "prompt";
|
|
11
|
+
};
|
|
12
|
+
export declare const PROMPT_PROFILE: {
|
|
13
|
+
readonly read: "read";
|
|
14
|
+
readonly edit: "edit";
|
|
15
|
+
};
|
|
16
|
+
export type PromptProfile = (typeof PROMPT_PROFILE)[keyof typeof PROMPT_PROFILE];
|
|
17
|
+
export declare const ALLOWED_PERMISSION_MODES: readonly string[];
|
|
18
|
+
export declare const EVENTS_DEFAULTS: {
|
|
19
|
+
readonly nextSeq: 1;
|
|
20
|
+
readonly flushMs: 1000;
|
|
21
|
+
readonly flushCount: 20;
|
|
22
|
+
readonly batchMax: 50;
|
|
23
|
+
readonly bodyMaxChars: 4000;
|
|
24
|
+
readonly toolArgMaxChars: 200;
|
|
25
|
+
};
|
|
26
|
+
export declare const BRANCH_RE: RegExp;
|
|
27
|
+
export declare const PROMPT_PERMISSION_MODE = "dontAsk";
|
|
28
|
+
export declare const READ_FORBIDDEN_TOOLS: readonly string[];
|
|
29
|
+
export declare const REPO_KEY_RE: RegExp;
|
|
30
|
+
export interface ClaimedRun {
|
|
31
|
+
id: number;
|
|
32
|
+
kind: string;
|
|
33
|
+
entryId: number;
|
|
34
|
+
workspaceId: number;
|
|
35
|
+
repo: string | null;
|
|
36
|
+
branch: string | null;
|
|
37
|
+
repoSource: string;
|
|
38
|
+
repoAvailable: boolean;
|
|
39
|
+
aws: {
|
|
40
|
+
accountId: string | null;
|
|
41
|
+
region: string | null;
|
|
42
|
+
} | null;
|
|
43
|
+
sessionId: string | null;
|
|
44
|
+
parentRunId: number | null;
|
|
45
|
+
profile: PromptProfile | null;
|
|
46
|
+
segment: number | null;
|
|
47
|
+
}
|
|
48
|
+
export interface EventsConfig {
|
|
49
|
+
enabled: boolean;
|
|
50
|
+
nextSeq: number;
|
|
51
|
+
flushMs: number;
|
|
52
|
+
flushCount: number;
|
|
53
|
+
batchMax: number;
|
|
54
|
+
bodyMaxChars: number;
|
|
55
|
+
toolArgMaxChars: number;
|
|
56
|
+
}
|
|
57
|
+
export interface ClaimResponse {
|
|
58
|
+
run: ClaimedRun;
|
|
59
|
+
prompt: string;
|
|
60
|
+
fallbackPrompt: string | null;
|
|
61
|
+
tier: string | null;
|
|
62
|
+
tools: {
|
|
63
|
+
allowed: string[];
|
|
64
|
+
disallowed: string[];
|
|
65
|
+
};
|
|
66
|
+
permissionMode: string;
|
|
67
|
+
maxTurns: number | null;
|
|
68
|
+
maxBudgetUsd: number | null;
|
|
69
|
+
timeoutMs: number;
|
|
70
|
+
heartbeatMs: number;
|
|
71
|
+
events: EventsConfig | null;
|
|
72
|
+
mcp: {
|
|
73
|
+
serverName: string;
|
|
74
|
+
url: string;
|
|
75
|
+
token: string;
|
|
76
|
+
expiresAt: number;
|
|
77
|
+
};
|
|
78
|
+
warnings: string[];
|
|
79
|
+
}
|
|
80
|
+
/** id de run válido para paths y logs (entero positivo), o null. sirve para fallar un claim roto. */
|
|
81
|
+
export declare function claimRunId(raw: unknown): number | null;
|
|
82
|
+
/** cordura mínima de una rama para pasarla a git (git check-ref-format decide aparte). */
|
|
83
|
+
export declare function isValidBranchName(branch: string): boolean;
|
|
84
|
+
/** valida y normaliza la respuesta 200 del claim. lanza con el motivo si algo no es seguro. */
|
|
85
|
+
export declare function parseClaim(raw: unknown): ClaimResponse;
|
|
86
|
+
//# sourceMappingURL=claim.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claim.d.ts","sourceRoot":"","sources":["../src/cla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rato 42 + prompts libres t#378) y su validación
|
|
2
|
+
// local. el daemon ejecuta lo que el server compone, pero lo que acaba en paths o en argv (id del
|
|
3
|
+
// run, sesión, rama, permission mode, ids de tools) se valida aquí: ni un server comprometido ni un
|
|
4
|
+
// bug suyo deben poder colar un flag en `claude`/`git` ni un `..` en un path.
|
|
5
|
+
// decisiones:
|
|
6
|
+
// - una rama inutilizable NO tumba el claim: se ignora con un aviso y el worktree cae en la base por
|
|
7
|
+
// defecto (las ramas de prs de bitbucket/github llevan ñ, '+', '#'…; quien decide es
|
|
8
|
+
// `git check-ref-format`, y todo argumento de git va tras `--end-of-options`).
|
|
9
|
+
// - el perfil read de un prompt run se hace cumplir AQUÍ también: permission mode dontAsk, nada de
|
|
10
|
+
// Bash/Edit/Write/NotebookEdit en las permitidas y las cuatro forzadas en las denegadas. un bug o
|
|
11
|
+
// una deriva del server nunca le da Bash a una lectura.
|
|
12
|
+
// - `run.segment` es la identidad del proceso: viaja de vuelta en heartbeat/progress/events/status.
|
|
13
|
+
// capacidades que el daemon anuncia en el claim. el server entrega kind=prompt solo a quien
|
|
14
|
+
// anuncia `prompt` y pide el feed de progreso solo a quien anuncia `events`.
|
|
15
|
+
export const RUNNER_CAPABILITY = {
|
|
16
|
+
aws: 'aws',
|
|
17
|
+
prompt: 'prompt',
|
|
18
|
+
events: 'events',
|
|
19
|
+
};
|
|
20
|
+
export const RUN_KIND = {
|
|
21
|
+
investigate: 'investigate',
|
|
22
|
+
resume: 'resume',
|
|
23
|
+
prompt: 'prompt',
|
|
24
|
+
};
|
|
25
|
+
export const PROMPT_PROFILE = {
|
|
26
|
+
read: 'read',
|
|
27
|
+
edit: 'edit',
|
|
28
|
+
};
|
|
29
|
+
// techo local de permission modes: el server manda dontAsk; bypassPermissions nunca se acepta
|
|
30
|
+
// desde fuera (el opt-in a saltarse permisos es solo local, `repos add --dangerously-skip-permissions`).
|
|
31
|
+
export const ALLOWED_PERMISSION_MODES = ['dontAsk', 'default', 'acceptEdits', 'plan'];
|
|
32
|
+
// si el server omite timeoutMs/heartbeatMs (espejo de AGENT_HARNESS_RUN_TIMEOUT_MS y
|
|
33
|
+
// RUN_HEARTBEAT_INTERVAL_MS del server).
|
|
34
|
+
const DEFAULT_TIMEOUT_MS = 30 * 60_000;
|
|
35
|
+
const DEFAULT_HEARTBEAT_MS = 20_000;
|
|
36
|
+
// defaults del feed si el server no los manda (espejo de AGENT_RUN_EVENT_* del server).
|
|
37
|
+
export const EVENTS_DEFAULTS = {
|
|
38
|
+
nextSeq: 1,
|
|
39
|
+
flushMs: 1000,
|
|
40
|
+
flushCount: 20,
|
|
41
|
+
batchMax: 50,
|
|
42
|
+
bodyMaxChars: 4000,
|
|
43
|
+
toolArgMaxChars: 200,
|
|
44
|
+
};
|
|
45
|
+
// cordura mínima de una rama ANTES de tocar git: sin '-' inicial (no puede parecer una opción), sin
|
|
46
|
+
// espacios ni caracteres de control, acotada. quien decide de verdad es `git check-ref-format --branch`.
|
|
47
|
+
export const BRANCH_RE = /^(?!-)[^\s\x00-\x1f\x7f]{1,250}$/;
|
|
48
|
+
// permission mode que exige un prompt run (el server lo manda siempre; sin él heredaría el del usuario).
|
|
49
|
+
export const PROMPT_PERMISSION_MODE = 'dontAsk';
|
|
50
|
+
// built-in que un prompt run de lectura nunca puede tener (ni con patrón: `Bash(git log:*)`).
|
|
51
|
+
export const READ_FORBIDDEN_TOOLS = ['Bash', 'Edit', 'Write', 'NotebookEdit'];
|
|
52
|
+
// longitud con la que una rama descartada aparece en el aviso.
|
|
53
|
+
const WARNING_BRANCH_CHARS = 80;
|
|
54
|
+
// workspace/slug u owner/repo (REPO_KEY_RE del server).
|
|
55
|
+
export const REPO_KEY_RE = /^[^/\s]+\/[^/\s]+$/;
|
|
56
|
+
// session id de claude (uuid): va tras --resume, nunca debe parecer un flag.
|
|
57
|
+
const SESSION_ID_RE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
|
|
58
|
+
// id de tool para --allowedTools/--disallowedTools (`Read`, `Bash(git log:*)`, `mcp__duckhunt__x`):
|
|
59
|
+
// empieza por letra (nunca '-') y sin comas ni saltos (se unen con ',' en un solo argumento).
|
|
60
|
+
const TOOL_ID_RE = /^[A-Za-z_][^,\n\r]{0,199}$/;
|
|
61
|
+
// nombre del servidor mcp: clave del mcp-config y prefijo mcp__<name>__ de las tools.
|
|
62
|
+
const MCP_SERVER_NAME_RE = /^[A-Za-z0-9_-]{1,64}$/;
|
|
63
|
+
const isObj = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
64
|
+
const str = (v) => (typeof v === 'string' ? v : null);
|
|
65
|
+
const posInt = (v) => (typeof v === 'number' && Number.isSafeInteger(v) && v > 0 ? v : null);
|
|
66
|
+
const posNum = (v) => (typeof v === 'number' && Number.isFinite(v) && v > 0 ? v : null);
|
|
67
|
+
/** id de run válido para paths y logs (entero positivo), o null. sirve para fallar un claim roto. */
|
|
68
|
+
export function claimRunId(raw) {
|
|
69
|
+
return isObj(raw) && isObj(raw.run) ? posInt(raw.run.id) : null;
|
|
70
|
+
}
|
|
71
|
+
/** cordura mínima de una rama para pasarla a git (git check-ref-format decide aparte). */
|
|
72
|
+
export function isValidBranchName(branch) {
|
|
73
|
+
return BRANCH_RE.test(branch);
|
|
74
|
+
}
|
|
75
|
+
// ¿una tool permitida es (o acota) una de las prohibidas en lectura? `Bash` y `Bash(git:*)` lo son.
|
|
76
|
+
const isForbiddenInRead = (tool) => READ_FORBIDDEN_TOOLS.some((f) => tool === f || tool.startsWith(`${f}(`));
|
|
77
|
+
function toolList(v, field) {
|
|
78
|
+
if (v === undefined || v === null)
|
|
79
|
+
return [];
|
|
80
|
+
if (!Array.isArray(v) || !v.every((t) => typeof t === 'string' && TOOL_ID_RE.test(t))) {
|
|
81
|
+
throw new Error(`claim inválido: ${field} con ids de tool no válidos`);
|
|
82
|
+
}
|
|
83
|
+
return v;
|
|
84
|
+
}
|
|
85
|
+
function eventsConfig(v) {
|
|
86
|
+
if (!isObj(v))
|
|
87
|
+
return null;
|
|
88
|
+
return {
|
|
89
|
+
enabled: v.enabled === true,
|
|
90
|
+
nextSeq: posInt(v.nextSeq) ?? EVENTS_DEFAULTS.nextSeq,
|
|
91
|
+
flushMs: posNum(v.flushMs) ?? EVENTS_DEFAULTS.flushMs,
|
|
92
|
+
flushCount: posInt(v.flushCount) ?? EVENTS_DEFAULTS.flushCount,
|
|
93
|
+
batchMax: posInt(v.batchMax) ?? EVENTS_DEFAULTS.batchMax,
|
|
94
|
+
bodyMaxChars: posInt(v.bodyMaxChars) ?? EVENTS_DEFAULTS.bodyMaxChars,
|
|
95
|
+
toolArgMaxChars: posInt(v.toolArgMaxChars) ?? EVENTS_DEFAULTS.toolArgMaxChars,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
/** valida y normaliza la respuesta 200 del claim. lanza con el motivo si algo no es seguro. */
|
|
99
|
+
export function parseClaim(raw) {
|
|
100
|
+
if (!isObj(raw) || !isObj(raw.run))
|
|
101
|
+
throw new Error('claim inválido: falta run');
|
|
102
|
+
const r = raw.run;
|
|
103
|
+
const id = posInt(r.id);
|
|
104
|
+
if (id === null)
|
|
105
|
+
throw new Error('claim inválido: run.id no es un entero positivo');
|
|
106
|
+
const kind = str(r.kind);
|
|
107
|
+
if (!kind)
|
|
108
|
+
throw new Error('claim inválido: run.kind ausente');
|
|
109
|
+
const repo = str(r.repo);
|
|
110
|
+
if (repo !== null && !REPO_KEY_RE.test(repo))
|
|
111
|
+
throw new Error(`claim inválido: repo "${repo}"`);
|
|
112
|
+
const warnings = [];
|
|
113
|
+
const rawBranch = str(r.branch);
|
|
114
|
+
const branch = rawBranch !== null && isValidBranchName(rawBranch) ? rawBranch : null;
|
|
115
|
+
if (rawBranch !== null && branch === null) {
|
|
116
|
+
warnings.push(`rama ${JSON.stringify(rawBranch.slice(0, WARNING_BRANCH_CHARS))} ignorada (nombre no utilizable): worktree sobre la rama por defecto`);
|
|
117
|
+
}
|
|
118
|
+
const sessionId = str(r.sessionId);
|
|
119
|
+
if (sessionId !== null && !SESSION_ID_RE.test(sessionId))
|
|
120
|
+
throw new Error('claim inválido: sessionId con formato inesperado');
|
|
121
|
+
const profile = r.profile === PROMPT_PROFILE.read || r.profile === PROMPT_PROFILE.edit ? r.profile : null;
|
|
122
|
+
if (kind === RUN_KIND.prompt && profile === null)
|
|
123
|
+
throw new Error('claim inválido: prompt run sin perfil read|edit');
|
|
124
|
+
const prompt = str(raw.prompt);
|
|
125
|
+
if (!prompt || !prompt.trim())
|
|
126
|
+
throw new Error('claim inválido: prompt vacío');
|
|
127
|
+
const permissionMode = str(raw.permissionMode) ?? '';
|
|
128
|
+
if (!ALLOWED_PERMISSION_MODES.includes(permissionMode)) {
|
|
129
|
+
throw new Error(`claim inválido: permission mode "${permissionMode}" fuera del techo local (${ALLOWED_PERMISSION_MODES.join(', ')})`);
|
|
130
|
+
}
|
|
131
|
+
if (kind === RUN_KIND.prompt && permissionMode !== PROMPT_PERMISSION_MODE) {
|
|
132
|
+
throw new Error(`claim inválido: un prompt run exige permission mode ${PROMPT_PERMISSION_MODE} (llegó "${permissionMode}")`);
|
|
133
|
+
}
|
|
134
|
+
const tools = isObj(raw.tools) ? raw.tools : {};
|
|
135
|
+
const allowed = toolList(tools.allowed, 'tools.allowed');
|
|
136
|
+
const readPrompt = kind === RUN_KIND.prompt && profile === PROMPT_PROFILE.read;
|
|
137
|
+
const leaked = readPrompt ? allowed.filter(isForbiddenInRead) : [];
|
|
138
|
+
if (leaked.length > 0)
|
|
139
|
+
throw new Error(`claim inválido: un prompt run de lectura no puede permitir ${leaked.join(', ')}`);
|
|
140
|
+
const disallowed = Array.from(new Set([...toolList(tools.disallowed, 'tools.disallowed'), ...(readPrompt ? READ_FORBIDDEN_TOOLS : [])]));
|
|
141
|
+
const mcp = isObj(raw.mcp) ? raw.mcp : {};
|
|
142
|
+
const serverName = str(mcp.serverName) ?? '';
|
|
143
|
+
const url = str(mcp.url) ?? '';
|
|
144
|
+
const token = str(mcp.token) ?? '';
|
|
145
|
+
if (!MCP_SERVER_NAME_RE.test(serverName) || !/^https?:\/\//i.test(url) || !token) {
|
|
146
|
+
throw new Error('claim inválido: bloque mcp incompleto');
|
|
147
|
+
}
|
|
148
|
+
const aws = isObj(r.aws) ? { accountId: str(r.aws.accountId), region: str(r.aws.region) } : null;
|
|
149
|
+
const numOrNull = (v) => (typeof v === 'number' && Number.isFinite(v) ? v : null);
|
|
150
|
+
return {
|
|
151
|
+
run: {
|
|
152
|
+
id,
|
|
153
|
+
kind,
|
|
154
|
+
entryId: posInt(r.entryId) ?? 0,
|
|
155
|
+
workspaceId: posInt(r.workspaceId) ?? 0,
|
|
156
|
+
repo,
|
|
157
|
+
branch,
|
|
158
|
+
repoSource: str(r.repoSource) ?? 'none',
|
|
159
|
+
repoAvailable: r.repoAvailable === true,
|
|
160
|
+
aws,
|
|
161
|
+
sessionId,
|
|
162
|
+
parentRunId: posInt(r.parentRunId),
|
|
163
|
+
profile,
|
|
164
|
+
segment: posInt(r.segment),
|
|
165
|
+
},
|
|
166
|
+
prompt,
|
|
167
|
+
fallbackPrompt: str(raw.fallbackPrompt),
|
|
168
|
+
tier: str(raw.tier),
|
|
169
|
+
tools: { allowed, disallowed },
|
|
170
|
+
permissionMode,
|
|
171
|
+
maxTurns: numOrNull(raw.maxTurns),
|
|
172
|
+
maxBudgetUsd: numOrNull(raw.maxBudgetUsd),
|
|
173
|
+
timeoutMs: posNum(raw.timeoutMs) ?? DEFAULT_TIMEOUT_MS,
|
|
174
|
+
heartbeatMs: posNum(raw.heartbeatMs) ?? DEFAULT_HEARTBEAT_MS,
|
|
175
|
+
events: eventsConfig(raw.events),
|
|
176
|
+
mcp: { serverName, url, token, expiresAt: numOrNull(mcp.expiresAt) ?? 0 },
|
|
177
|
+
warnings,
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
//# sourceMappingURL=claim.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claim.js","sourceRoot":"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QACvC,IAAI,EAAE,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC;QACnB,KAAK,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE;QAC9B,cAAc;QACd,QAAQ,EAAE,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC;QACjC,YAAY,EAAE,SAAS,CAAC,GAAG,CAAC,YAAY,CAAC;QACzC,SAAS,EAAE,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,kBAAkB;QACtD,WAAW,EAAE,MAAM,CAAC,GAAG,CAAC,WAAW,CAAC,IAAI,oBAAoB;QAC5D,MAAM,EAAE,YAAY,CAAC,GAAG,CAAC,MAAM,CAAC;QAChC,GAAG,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE;QACzE,QAAQ;KACT,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type ClaimResponse, type PromptProfile } from './claim.js';
|
|
2
|
+
import type { OptionalFlag } from './claude.js';
|
|
3
|
+
export interface ClaudeArgsInput {
|
|
4
|
+
claim: Pick<ClaimResponse, 'tools' | 'permissionMode' | 'maxTurns' | 'maxBudgetUsd'> & {
|
|
5
|
+
run: {
|
|
6
|
+
kind: string;
|
|
7
|
+
profile: PromptProfile | null;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
prompt: string;
|
|
11
|
+
mcpConfigFile: string;
|
|
12
|
+
supported: ReadonlySet<OptionalFlag>;
|
|
13
|
+
resumeSessionId: string | null;
|
|
14
|
+
model?: string;
|
|
15
|
+
configBudgetUsd?: number;
|
|
16
|
+
skipPermissions: boolean;
|
|
17
|
+
payingWithApiKey: boolean;
|
|
18
|
+
}
|
|
19
|
+
/** flags sin los que el cli no puede cumplir un prompt run (el daemon solo anuncia `prompt` si los tiene todos). */
|
|
20
|
+
export declare const PROMPT_REQUIRED_FLAGS: readonly OptionalFlag[];
|
|
21
|
+
/** argv de `claude` (sin el binario). lanza si el cli no puede cumplir el perfil del run. */
|
|
22
|
+
export declare function buildClaudeArgs(i: ClaudeArgsInput): string[];
|
|
23
|
+
//# sourceMappingURL=claude-args.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claude-args.d.ts","sourceRoot":"","sources":["../src/claude-args.ts"],"names":[],"mappings":"AAgBA,OAAO,EAA4B,KAAK,aAAa,EAAE,KAAK,aAAa,EAAE,MAAM,YAAY,CAAC;AAC9F,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,IAAI,CAAC,aAAa,EAAE,OAAO,GAAG,gBAAgB,GAAG,UAAU,GAAG,cAAc,CAAC,GAAG;QAAE,GAAG,EAAE;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,OAAO,EAAE,aAAa,GAAG,IAAI,CAAA;SAAE,CAAA;KAAE,CAAC;IAChJ,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,MAAM,CAAC;IAEtB,SAAS,EAAE,WAAW,CAAC,YAAY,CAAC,CAAC;IACrC,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAE/B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,eAAe,EAAE,OAAO,CAAC;IAEzB,gBAAgB,EAAE,OAAO,CAAC;CAC3B;AAED,oHAAoH;AACpH,eAAO,MAAM,qBAAqB,EAAE,SAAS,YAAY,EAA2F,CAAC;AAErJ,6FAA6F;AAC7F,wBAAgB,eAAe,CAAC,CAAC,EAAE,eAAe,GAAG,MAAM,EAAE,CAsC5D"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// argv de `claude -p` para un run. pura (sin env ni fs) para poder probarla: quien la llama resuelve
|
|
2
|
+
// antes la config local y los flags que soporta el cli instalado.
|
|
3
|
+
// decisiones: el permission mode viaja SIEMPRE (omitido heredaría el defaultMode del usuario, que
|
|
4
|
+
// puede ser bypassPermissions) y sin él el run no arranca; los prompt runs (t#378) no llevan
|
|
5
|
+
// --max-turns ni --max-budget-usd (el tope es el wall clock por segmento) ni el opt-in local
|
|
6
|
+
// --dangerously-skip-permissions (su perfil read|edit lo fija el server y debe cumplirse); el prompt
|
|
7
|
+
// va el último tras `--`, así un texto que empiece por '-' nunca se lee como flag.
|
|
8
|
+
// un prompt run SIEMPRE lleva --strict-mcp-config (un .mcp.json del checkout no carga nada). uno de
|
|
9
|
+
// LECTURA además lleva `--setting-sources user`: corre en un checkout de origin/<rama> que puede
|
|
10
|
+
// haber empujado cualquiera, y su .claude/settings.json (hooks, apiKeyHelper, statusLine…) se
|
|
11
|
+
// ejecutaría sin preguntar, y lectura promete que no se ejecuta código del repo. verificado con el
|
|
12
|
+
// cli 2.1.281: sin el flag el hook SessionStart del repo corre; con él no (y tampoco carga el
|
|
13
|
+
// CLAUDE.md del proyecto: el prompt de lectura le pide leerlo con Read). los settings, hooks y
|
|
14
|
+
// plugins del USUARIO se conservan (sin --restricted, decisión de t#378). edición no lo lleva: ya
|
|
15
|
+
// ejecuta código del repo con Bash tras la verificación escalonada, y necesita su CLAUDE.md.
|
|
16
|
+
import { PROMPT_PROFILE, RUN_KIND } from './claim.js';
|
|
17
|
+
/** flags sin los que el cli no puede cumplir un prompt run (el daemon solo anuncia `prompt` si los tiene todos). */
|
|
18
|
+
export const PROMPT_REQUIRED_FLAGS = ['--permission-mode', '--strict-mcp-config', '--disallowedTools', '--setting-sources'];
|
|
19
|
+
/** argv de `claude` (sin el binario). lanza si el cli no puede cumplir el perfil del run. */
|
|
20
|
+
export function buildClaudeArgs(i) {
|
|
21
|
+
const { claim } = i;
|
|
22
|
+
const has = (f) => i.supported.has(f);
|
|
23
|
+
const isPrompt = claim.run.kind === RUN_KIND.prompt;
|
|
24
|
+
const readPrompt = isPrompt && claim.run.profile === PROMPT_PROFILE.read;
|
|
25
|
+
if (!has('--permission-mode')) {
|
|
26
|
+
throw new Error('el claude instalado no soporta --permission-mode: actualiza claude code (sin él heredaría tus permisos por defecto)');
|
|
27
|
+
}
|
|
28
|
+
const missing = isPrompt ? PROMPT_REQUIRED_FLAGS.filter((f) => !has(f)) : [];
|
|
29
|
+
if (missing.length > 0) {
|
|
30
|
+
throw new Error(`el claude instalado no soporta ${missing.join(', ')}: actualiza claude code (sin ellos un prompt run no cumple su perfil)`);
|
|
31
|
+
}
|
|
32
|
+
// presupuesto: solo tiene sentido cuando el coste es REAL (api key). con login de suscripción el
|
|
33
|
+
// cli lo aplicaría sobre un coste nominal que nadie paga y mata runs legítimos (el guard contra
|
|
34
|
+
// loops es el timeout). config manda: número = forzar, 0 = nunca. prompt runs: nunca.
|
|
35
|
+
const budget = isPrompt ? 0 : (i.configBudgetUsd ?? (i.payingWithApiKey ? (claim.maxBudgetUsd ?? 0) : 0));
|
|
36
|
+
const maxTurns = isPrompt ? 0 : (claim.maxTurns ?? 0);
|
|
37
|
+
return [
|
|
38
|
+
'-p',
|
|
39
|
+
'--output-format',
|
|
40
|
+
'stream-json',
|
|
41
|
+
...(has('--verbose') ? ['--verbose'] : []),
|
|
42
|
+
'--mcp-config',
|
|
43
|
+
i.mcpConfigFile,
|
|
44
|
+
...(has('--strict-mcp-config') ? ['--strict-mcp-config'] : []),
|
|
45
|
+
...(readPrompt ? ['--setting-sources', 'user'] : []),
|
|
46
|
+
...(claim.tools.allowed.length > 0 ? ['--allowedTools', claim.tools.allowed.join(',')] : []),
|
|
47
|
+
...(has('--disallowedTools') && claim.tools.disallowed.length > 0 ? ['--disallowedTools', claim.tools.disallowed.join(',')] : []),
|
|
48
|
+
'--permission-mode',
|
|
49
|
+
claim.permissionMode,
|
|
50
|
+
...(has('--max-turns') && maxTurns > 0 ? ['--max-turns', String(maxTurns)] : []),
|
|
51
|
+
...(has('--max-budget-usd') && budget > 0 ? ['--max-budget-usd', String(budget)] : []),
|
|
52
|
+
...(i.model ? ['--model', i.model] : []),
|
|
53
|
+
...(i.skipPermissions && !isPrompt ? ['--dangerously-skip-permissions'] : []),
|
|
54
|
+
...(i.resumeSessionId ? ['--resume', i.resumeSessionId] : []),
|
|
55
|
+
'--',
|
|
56
|
+
i.prompt,
|
|
57
|
+
];
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=claude-args.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claude-args.js","sourceRoot":"","sources":["../src/claude-args.ts"],"names":[],"mappings":"AAAA,qGAAqG;AACrG,kEAAkE;AAClE,kGAAkG;AAClG,6FAA6F;AAC7F,6FAA6F;AAC7F,qGAAqG;AACrG,mFAAmF;AACnF,oGAAoG;AACpG,iGAAiG;AACjG,8FAA8F;AAC9F,mGAAmG;AACnG,8FAA8F;AAC9F,+FAA+F;AAC/F,kGAAkG;AAClG,6FAA6F;AAE7F,OAAO,EAAE,cAAc,EAAE,QAAQ,EAA0C,MAAM,YAAY,CAAC;AAkB9F,oHAAoH;AACpH,MAAM,CAAC,MAAM,qBAAqB,GAA4B,CAAC,mBAAmB,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,mBAAmB,CAAC,CAAC;AAErJ,6FAA6F;AAC7F,MAAM,UAAU,eAAe,CAAC,CAAkB;IAChD,MAAM,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC;IACpB,MAAM,GAAG,GAAG,CAAC,CAAe,EAAW,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IAC7D,MAAM,QAAQ,GAAG,KAAK,CAAC,GAAG,CAAC,IAAI,KAAK,QAAQ,CAAC,MAAM,CAAC;IACpD,MAAM,UAAU,GAAG,QAAQ,IAAI,KAAK,CAAC,GAAG,CAAC,OAAO,KAAK,cAAc,CAAC,IAAI,CAAC;IACzE,IAAI,CAAC,GAAG,CAAC,mBAAmB,CAAC,EAAE,CAAC;QAC9B,MAAM,IAAI,KAAK,CAAC,q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 -1,4 +1,4 @@
|
|
|
1
|
-
export declare const OPTIONAL_FLAGS: readonly ["--max-turns", "--max-budget-usd", "--strict-mcp-config", "--permission-mode", "--disallowedTools", "--verbose"];
|
|
1
|
+
export declare const OPTIONAL_FLAGS: readonly ["--max-turns", "--max-budget-usd", "--strict-mcp-config", "--permission-mode", "--disallowedTools", "--verbose", "--setting-sources"];
|
|
2
2
|
export type OptionalFlag = (typeof OPTIONAL_FLAGS)[number];
|
|
3
3
|
export interface ClaudeInfo {
|
|
4
4
|
version: string | null;
|
|
@@ -22,6 +22,25 @@ export interface StreamState {
|
|
|
22
22
|
result: StreamResult | null;
|
|
23
23
|
}
|
|
24
24
|
export declare function newStreamState(): StreamState;
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
export interface StreamContent {
|
|
26
|
+
type?: string;
|
|
27
|
+
text?: string;
|
|
28
|
+
name?: string;
|
|
29
|
+
input?: unknown;
|
|
30
|
+
}
|
|
31
|
+
export interface StreamLine {
|
|
32
|
+
type?: string;
|
|
33
|
+
subtype?: string;
|
|
34
|
+
session_id?: string;
|
|
35
|
+
is_error?: boolean;
|
|
36
|
+
result?: unknown;
|
|
37
|
+
total_cost_usd?: unknown;
|
|
38
|
+
num_turns?: unknown;
|
|
39
|
+
modelUsage?: Record<string, unknown>;
|
|
40
|
+
message?: {
|
|
41
|
+
content?: StreamContent[] | string;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/** consume una línea de stdout (stream-json) y devuelve el evento parseado; null si no es json. */
|
|
45
|
+
export declare function consumeStreamLine(state: StreamState, line: string): StreamLine | null;
|
|
27
46
|
//# sourceMappingURL=claude.d.ts.map
|
package/dist/claude.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"claude.d.ts","sourceRoot":"","sources":["../src/claude.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"claude.d.ts","sourceRoot":"","sources":["../src/claude.ts"],"names":[],"mappings":"AAYA,eAA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,CAAC;IACzB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,OAAO,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,aAAa,EAAE,GAAG,MAAM,CAAA;KAAE,CAAC;CAClD;AAMD,mGAAmG;AACnG,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,IAAI,CA6BrF"}
|
package/dist/claude.js
CHANGED
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
// integración con el cli de claude code: detección de flags soportados (el cli cambia entre
|
|
2
2
|
// versiones; los flags opcionales se pasan solo si `claude --help` los lista) y parseo del
|
|
3
|
-
// stream-json de un run headless (contadores de tool calls, objeto result final).
|
|
3
|
+
// stream-json de un run headless (contadores de tool calls, objeto result final). el evento
|
|
4
|
+
// parseado se devuelve para que el feed de progreso (feed.ts) lo lea sin volver a parsear.
|
|
4
5
|
import { execFile } from 'node:child_process';
|
|
5
6
|
import { promisify } from 'node:util';
|
|
6
7
|
const execFileP = promisify(execFile);
|
|
7
8
|
// flags que el daemon quiere pasar pero que no todas las versiones del cli aceptan; un flag
|
|
8
9
|
// desconocido aborta el proceso, así que se detectan una vez por arranque.
|
|
9
|
-
export const OPTIONAL_FLAGS = [
|
|
10
|
+
export const OPTIONAL_FLAGS = [
|
|
11
|
+
'--max-turns',
|
|
12
|
+
'--max-budget-usd',
|
|
13
|
+
'--strict-mcp-config',
|
|
14
|
+
'--permission-mode',
|
|
15
|
+
'--disallowedTools',
|
|
16
|
+
'--verbose',
|
|
17
|
+
'--setting-sources',
|
|
18
|
+
];
|
|
10
19
|
/** `claude --version` + flags soportados según `claude --help`. version null si el cli no arranca. */
|
|
11
20
|
export async function detectClaude() {
|
|
12
21
|
const supported = new Set();
|
|
@@ -32,16 +41,17 @@ export function newStreamState() {
|
|
|
32
41
|
function num(v) {
|
|
33
42
|
return typeof v === 'number' && Number.isFinite(v) ? v : null;
|
|
34
43
|
}
|
|
35
|
-
/** consume una línea de stdout (stream-json)
|
|
44
|
+
/** consume una línea de stdout (stream-json) y devuelve el evento parseado; null si no es json. */
|
|
36
45
|
export function consumeStreamLine(state, line) {
|
|
37
46
|
if (!line.startsWith('{'))
|
|
38
|
-
return;
|
|
47
|
+
return null;
|
|
39
48
|
let ev;
|
|
40
49
|
try {
|
|
41
50
|
ev = JSON.parse(line);
|
|
42
51
|
}
|
|
43
52
|
catch {
|
|
44
|
-
|
|
53
|
+
// línea que empieza por '{' pero no es json (salida corrupta o cortada): no es un evento.
|
|
54
|
+
return null;
|
|
45
55
|
}
|
|
46
56
|
if (typeof ev.session_id === 'string' && ev.session_id)
|
|
47
57
|
state.sessionId = ev.session_id;
|
|
@@ -50,7 +60,7 @@ export function consumeStreamLine(state, line) {
|
|
|
50
60
|
const content = ev.message?.content;
|
|
51
61
|
if (Array.isArray(content))
|
|
52
62
|
state.toolCalls += content.filter((c) => c?.type === 'tool_use').length;
|
|
53
|
-
return;
|
|
63
|
+
return ev;
|
|
54
64
|
}
|
|
55
65
|
if (ev.type === 'result') {
|
|
56
66
|
const models = ev.modelUsage ? Object.keys(ev.modelUsage) : [];
|
|
@@ -64,5 +74,6 @@ export function consumeStreamLine(state, line) {
|
|
|
64
74
|
model: models[0] ?? null,
|
|
65
75
|
};
|
|
66
76
|
}
|
|
77
|
+
return ev;
|
|
67
78
|
}
|
|
68
79
|
//# sourceMappingURL=claude.js.map
|
package/dist/claude.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"claude.js","sourceRoot":"","sources":["../src/claude.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,2FAA2F;AAC3F,
|
|
1
|
+
{"version":3,"file":"claude.js","sourceRoot":"","sources":["../src/claude.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,2FAA2F;AAC3F,4FAA4F;AAC5F,2FAA2F;AAE3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CAAC,CAAC,MAAM,CAAC;QACpG,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,IAAI,EAAE,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QACzB,MAAM,MAAM,GAAG,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAC/D,KAAK,CAAC,MAAM,GAAG;YACb,OAAO,EAAE,EAAE,CAAC,OAAO,IAAI,IAAI;YAC3B,OAAO,EAAE,EAAE,CAAC,QAAQ,KAAK,IAAI;YAC7B,MAAM,EAAE,OAAO,EAAE,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI;YACxD,OAAO,EAAE,GAAG,CAAC,EAAE,CAAC,cAAc,CAAC;YAC/B,QAAQ,EAAE,GAAG,CAAC,EAAE,CAAC,SAAS,CAAC;YAC3B,SAAS,EAAE,OAAO,EAAE,CAAC,UAAU,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS;YAC9E,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,IAAI,IAAI;SACzB,CAAC;IACJ,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC"}
|
package/dist/config.d.ts
CHANGED
|
@@ -22,6 +22,7 @@ export interface RunnerConfig {
|
|
|
22
22
|
aws: Record<string, AwsAccountConfig>;
|
|
23
23
|
defaults: RunnerDefaults;
|
|
24
24
|
}
|
|
25
|
+
/** fichero de config: DUCKHUNT_RUNNER_CONFIG o ~/.duckhunt-runner.json. */
|
|
25
26
|
export declare function configPath(): string;
|
|
26
27
|
/** directorio de estado del daemon (scratch + logs). */
|
|
27
28
|
export declare function runnerHome(): string;
|