@polydeukes/adapter-claude-code 0.3.0 → 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/dist/index.d.ts CHANGED
@@ -6,74 +6,10 @@
6
6
  * literals live here by design: this package is the boundary where Claude Code's
7
7
  * vocabulary is translated away before it reaches the core.
8
8
  */
9
- import { type CovenantInput } from '@polydeukes/core';
10
9
  export { collectFileChanges } from './file-changes.js';
11
10
  export { evaluatePrecedent } from './precedent.js';
12
11
  export { type DispatchOutcome, runAdapterPath } from './run-adapter-path.js';
13
12
  export { COMMAND_ARGS, MUTATING_TOOLS, SHELL_TOOLS, transcriptPathFromPayload, } from './session-vocabulary.js';
14
13
  export { transcriptFromJsonl, transcriptFromJsonlFile } from './transcript.js';
14
+ export { buildCovenantInput, type ClaudePreToolUsePayload, type TranslatedEvent, translateEvent, } from './up-translate.js';
15
15
  export { type VirtualPostState, virtualPostState } from './virtual-post-state.js';
16
- /**
17
- * `ClaudePreToolUsePayload` — a Claude Code PreToolUse hook payload (PRD §4.1).
18
- *
19
- * Only `tool_name` and `tool_input` are required; the rest is preserved when present.
20
- * The agent/tool literals this package interprets live in the *values* of these fields,
21
- * never in core — this boundary is the package's reason to exist.
22
- */
23
- export type ClaudePreToolUsePayload = {
24
- hook_event_name?: string;
25
- session_id?: string;
26
- transcript_path?: string;
27
- cwd?: string;
28
- tool_name: string;
29
- tool_input: Record<string, unknown>;
30
- };
31
- /**
32
- * `TranslatedEvent` — the result of up-translating one payload (PRD §4.2).
33
- *
34
- * Success carries the IR fragment; failure carries a human-readable `reason`. A `Task`
35
- * with a string `subagent_type` becomes a `subagentSpawn`; every other tool becomes a
36
- * `toolCall`. Classification failure never demotes to a `toolCall` — losing spawn
37
- * evidence is a bypass vector (PRD §4.1).
38
- */
39
- export type TranslatedEvent = {
40
- ok: true;
41
- kind: 'toolCall';
42
- value: {
43
- name: string;
44
- args?: Record<string, unknown>;
45
- };
46
- } | {
47
- ok: true;
48
- kind: 'subagentSpawn';
49
- value: {
50
- kind: string;
51
- };
52
- } | {
53
- ok: false;
54
- reason: string;
55
- };
56
- /**
57
- * Up-translate one Claude Code payload into an IR fragment (pure, PRD §4.2).
58
- *
59
- * Never throws: a payload that cannot be classified — a non-object, a missing/invalid
60
- * `tool_name` or `tool_input`, or a `Task` lacking a string `subagent_type` — resolves
61
- * to `{ ok: false, reason }` (fail-closed, PRD §5.2).
62
- */
63
- export declare function translateEvent(payload: unknown): TranslatedEvent;
64
- /**
65
- * Fold a sequence of payloads into one {@link CovenantInput} (pure, PRD §4.2).
66
- *
67
- * Preserves observation order into `toolCalls` / `subagentSpawns`; `userMessages` is
68
- * always `[]` (ADAPTER-04 supplies witness evidence later). If any payload fails
69
- * classification the whole build fails closed with the blocking exit code — a silent
70
- * drop would be a bypass vector (PRD §5.2/§7).
71
- */
72
- export declare function buildCovenantInput(payloads: unknown[]): {
73
- ok: true;
74
- value: CovenantInput;
75
- } | {
76
- ok: false;
77
- exitCode: 2;
78
- reason: string;
79
- };
package/dist/index.js CHANGED
@@ -6,60 +6,10 @@
6
6
  * literals live here by design: this package is the boundary where Claude Code's
7
7
  * vocabulary is translated away before it reaches the core.
8
8
  */
9
- import { EXIT_BREAK_BLOCKING } from '@polydeukes/core';
10
- import { parsePayloadEnvelope } from './payload-envelope.js';
11
9
  export { collectFileChanges } from './file-changes.js';
12
10
  export { evaluatePrecedent } from './precedent.js';
13
11
  export { runAdapterPath } from './run-adapter-path.js';
14
12
  export { COMMAND_ARGS, MUTATING_TOOLS, SHELL_TOOLS, transcriptPathFromPayload, } from './session-vocabulary.js';
15
13
  export { transcriptFromJsonl, transcriptFromJsonlFile } from './transcript.js';
14
+ export { buildCovenantInput, translateEvent, } from './up-translate.js';
16
15
  export { virtualPostState } from './virtual-post-state.js';
17
- /**
18
- * Up-translate one Claude Code payload into an IR fragment (pure, PRD §4.2).
19
- *
20
- * Never throws: a payload that cannot be classified — a non-object, a missing/invalid
21
- * `tool_name` or `tool_input`, or a `Task` lacking a string `subagent_type` — resolves
22
- * to `{ ok: false, reason }` (fail-closed, PRD §5.2).
23
- */
24
- export function translateEvent(payload) {
25
- const envelope = parsePayloadEnvelope(payload);
26
- if (envelope.ok !== true) {
27
- return { ok: false, reason: envelope.reason };
28
- }
29
- const { toolName, toolInput } = envelope;
30
- if (toolName === 'Task') {
31
- if (typeof toolInput.subagent_type !== 'string') {
32
- return { ok: false, reason: 'Task payload is missing a string subagent_type' };
33
- }
34
- return { ok: true, kind: 'subagentSpawn', value: { kind: toolInput.subagent_type } };
35
- }
36
- return { ok: true, kind: 'toolCall', value: { name: toolName, args: toolInput } };
37
- }
38
- /**
39
- * Fold a sequence of payloads into one {@link CovenantInput} (pure, PRD §4.2).
40
- *
41
- * Preserves observation order into `toolCalls` / `subagentSpawns`; `userMessages` is
42
- * always `[]` (ADAPTER-04 supplies witness evidence later). If any payload fails
43
- * classification the whole build fails closed with the blocking exit code — a silent
44
- * drop would be a bypass vector (PRD §5.2/§7).
45
- */
46
- export function buildCovenantInput(payloads) {
47
- const input = { toolCalls: [], subagentSpawns: [], userMessages: [] };
48
- for (let index = 0; index < payloads.length; index++) {
49
- const translated = translateEvent(payloads[index]);
50
- if (translated.ok !== true) {
51
- return {
52
- ok: false,
53
- exitCode: EXIT_BREAK_BLOCKING,
54
- reason: `payload at index ${index} failed classification: ${translated.reason}`,
55
- };
56
- }
57
- if (translated.kind === 'toolCall') {
58
- input.toolCalls.push(translated.value);
59
- }
60
- else {
61
- input.subagentSpawns.push(translated.value);
62
- }
63
- }
64
- return { ok: true, value: input };
65
- }
@@ -9,7 +9,7 @@
9
9
  import { readFileSync } from 'node:fs';
10
10
  import { appendRecordFailOpen, EXIT_BREAK_BLOCKING, EXIT_UPHOLD } from '@polydeukes/core';
11
11
  import { collectFileChanges } from './file-changes.js';
12
- import { buildCovenantInput } from './index.js';
12
+ import { buildCovenantInput } from './up-translate.js';
13
13
  /** Default label for adapter-level telemetry records. */
14
14
  const DEFAULT_ADAPTER_LABEL = 'adapter-claude-code';
15
15
  /**
@@ -0,0 +1,78 @@
1
+ /**
2
+ * up-translate — Claude Code PreToolUse payloads into the agent-neutral IR (ADAPTER-01
3
+ * PRD §4.1–§4.2).
4
+ *
5
+ * Pure translation only — no I/O, no process spawning. Agent and tool literals live in
6
+ * this package by design: it is the boundary where Claude Code's vocabulary is
7
+ * translated away before it reaches the core.
8
+ *
9
+ * These live outside the barrel because `run-adapter-path.ts` consumes
10
+ * `buildCovenantInput` and the barrel re-exports `run-adapter-path`: importing through
11
+ * the barrel is an initialization cycle (CLEANUP-01 F1). The barrel re-exports this
12
+ * module, so every consumer outside the package still reaches it at the same path.
13
+ */
14
+ import { type CovenantInput } from '@polydeukes/core';
15
+ /**
16
+ * `ClaudePreToolUsePayload` — a Claude Code PreToolUse hook payload (PRD §4.1).
17
+ *
18
+ * Only `tool_name` and `tool_input` are required; the rest is preserved when present.
19
+ * The agent/tool literals this package interprets live in the *values* of these fields,
20
+ * never in core — this boundary is the package's reason to exist.
21
+ */
22
+ export type ClaudePreToolUsePayload = {
23
+ hook_event_name?: string;
24
+ session_id?: string;
25
+ transcript_path?: string;
26
+ cwd?: string;
27
+ tool_name: string;
28
+ tool_input: Record<string, unknown>;
29
+ };
30
+ /**
31
+ * `TranslatedEvent` — the result of up-translating one payload (PRD §4.2).
32
+ *
33
+ * Success carries the IR fragment; failure carries a human-readable `reason`. A `Task`
34
+ * with a string `subagent_type` becomes a `subagentSpawn`; every other tool becomes a
35
+ * `toolCall`. Classification failure never demotes to a `toolCall` — losing spawn
36
+ * evidence is a bypass vector (PRD §4.1).
37
+ */
38
+ export type TranslatedEvent = {
39
+ ok: true;
40
+ kind: 'toolCall';
41
+ value: {
42
+ name: string;
43
+ args?: Record<string, unknown>;
44
+ };
45
+ } | {
46
+ ok: true;
47
+ kind: 'subagentSpawn';
48
+ value: {
49
+ kind: string;
50
+ };
51
+ } | {
52
+ ok: false;
53
+ reason: string;
54
+ };
55
+ /**
56
+ * Up-translate one Claude Code payload into an IR fragment (pure, PRD §4.2).
57
+ *
58
+ * Never throws: a payload that cannot be classified — a non-object, a missing/invalid
59
+ * `tool_name` or `tool_input`, or a `Task` lacking a string `subagent_type` — resolves
60
+ * to `{ ok: false, reason }` (fail-closed, PRD §5.2).
61
+ */
62
+ export declare function translateEvent(payload: unknown): TranslatedEvent;
63
+ /**
64
+ * Fold a sequence of payloads into one {@link CovenantInput} (pure, PRD §4.2).
65
+ *
66
+ * Preserves observation order into `toolCalls` / `subagentSpawns`; `userMessages` is
67
+ * always `[]` (ADAPTER-04 supplies witness evidence later). If any payload fails
68
+ * classification the whole build fails closed with the blocking exit code — a silent
69
+ * drop would be a bypass vector (PRD §5.2/§7).
70
+ */
71
+ export declare function buildCovenantInput(payloads: unknown[]): {
72
+ ok: true;
73
+ value: CovenantInput;
74
+ } | {
75
+ ok: false;
76
+ exitCode: 2;
77
+ reason: string;
78
+ };
@@ -0,0 +1,64 @@
1
+ /**
2
+ * up-translate — Claude Code PreToolUse payloads into the agent-neutral IR (ADAPTER-01
3
+ * PRD §4.1–§4.2).
4
+ *
5
+ * Pure translation only — no I/O, no process spawning. Agent and tool literals live in
6
+ * this package by design: it is the boundary where Claude Code's vocabulary is
7
+ * translated away before it reaches the core.
8
+ *
9
+ * These live outside the barrel because `run-adapter-path.ts` consumes
10
+ * `buildCovenantInput` and the barrel re-exports `run-adapter-path`: importing through
11
+ * the barrel is an initialization cycle (CLEANUP-01 F1). The barrel re-exports this
12
+ * module, so every consumer outside the package still reaches it at the same path.
13
+ */
14
+ import { EXIT_BREAK_BLOCKING } from '@polydeukes/core';
15
+ import { parsePayloadEnvelope } from './payload-envelope.js';
16
+ /**
17
+ * Up-translate one Claude Code payload into an IR fragment (pure, PRD §4.2).
18
+ *
19
+ * Never throws: a payload that cannot be classified — a non-object, a missing/invalid
20
+ * `tool_name` or `tool_input`, or a `Task` lacking a string `subagent_type` — resolves
21
+ * to `{ ok: false, reason }` (fail-closed, PRD §5.2).
22
+ */
23
+ export function translateEvent(payload) {
24
+ const envelope = parsePayloadEnvelope(payload);
25
+ if (envelope.ok !== true) {
26
+ return { ok: false, reason: envelope.reason };
27
+ }
28
+ const { toolName, toolInput } = envelope;
29
+ if (toolName === 'Task') {
30
+ if (typeof toolInput.subagent_type !== 'string') {
31
+ return { ok: false, reason: 'Task payload is missing a string subagent_type' };
32
+ }
33
+ return { ok: true, kind: 'subagentSpawn', value: { kind: toolInput.subagent_type } };
34
+ }
35
+ return { ok: true, kind: 'toolCall', value: { name: toolName, args: toolInput } };
36
+ }
37
+ /**
38
+ * Fold a sequence of payloads into one {@link CovenantInput} (pure, PRD §4.2).
39
+ *
40
+ * Preserves observation order into `toolCalls` / `subagentSpawns`; `userMessages` is
41
+ * always `[]` (ADAPTER-04 supplies witness evidence later). If any payload fails
42
+ * classification the whole build fails closed with the blocking exit code — a silent
43
+ * drop would be a bypass vector (PRD §5.2/§7).
44
+ */
45
+ export function buildCovenantInput(payloads) {
46
+ const input = { toolCalls: [], subagentSpawns: [], userMessages: [] };
47
+ for (let index = 0; index < payloads.length; index++) {
48
+ const translated = translateEvent(payloads[index]);
49
+ if (translated.ok !== true) {
50
+ return {
51
+ ok: false,
52
+ exitCode: EXIT_BREAK_BLOCKING,
53
+ reason: `payload at index ${index} failed classification: ${translated.reason}`,
54
+ };
55
+ }
56
+ if (translated.kind === 'toolCall') {
57
+ input.toolCalls.push(translated.value);
58
+ }
59
+ else {
60
+ input.subagentSpawns.push(translated.value);
61
+ }
62
+ }
63
+ return { ok: true, value: input };
64
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polydeukes/adapter-claude-code",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "Polydeukes adapter for Claude Code — up-translates PreToolUse hook payloads into the agent-neutral covenant input IR. Alpha.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -29,7 +29,7 @@
29
29
  "access": "public"
30
30
  },
31
31
  "dependencies": {
32
- "@polydeukes/core": "^0.3.0"
32
+ "@polydeukes/core": "^0.4.0"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@types/node": "^24.0.0",