intentdna 1.2.1 → 1.2.3

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 (180) hide show
  1. package/dist/audit/index.d.ts +0 -1
  2. package/dist/audit/index.js +0 -1
  3. package/dist/cli/commands/compile.d.ts +0 -1
  4. package/dist/cli/commands/compile.js +0 -1
  5. package/dist/cli/commands/epigenetic.d.ts +0 -1
  6. package/dist/cli/commands/epigenetic.js +0 -1
  7. package/dist/cli/commands/evolve.d.ts +0 -1
  8. package/dist/cli/commands/evolve.js +0 -1
  9. package/dist/cli/commands/guard.d.ts +0 -1
  10. package/dist/cli/commands/guard.js +0 -3
  11. package/dist/cli/commands/import.d.ts +0 -1
  12. package/dist/cli/commands/import.js +0 -1
  13. package/dist/cli/commands/init.d.ts +0 -1
  14. package/dist/cli/commands/init.js +0 -1
  15. package/dist/cli/commands/run.d.ts +0 -1
  16. package/dist/cli/commands/run.js +4 -27
  17. package/dist/cli/commands/show.d.ts +0 -1
  18. package/dist/cli/commands/show.js +0 -1
  19. package/dist/cli/commands/sync.d.ts +1 -1
  20. package/dist/cli/commands/sync.js +100 -33
  21. package/dist/cli/commands/validate.d.ts +0 -1
  22. package/dist/cli/commands/validate.js +0 -1
  23. package/dist/cli/commands/verify.d.ts +0 -1
  24. package/dist/cli/commands/verify.js +0 -1
  25. package/dist/cli/index.d.ts +0 -1
  26. package/dist/cli/index.js +2 -1
  27. package/dist/cli/util/format.d.ts +0 -1
  28. package/dist/cli/util/format.js +0 -1
  29. package/dist/cli/util/prompt.d.ts +0 -1
  30. package/dist/cli/util/prompt.js +0 -1
  31. package/dist/compiler/activate.d.ts +0 -1
  32. package/dist/compiler/activate.js +0 -1
  33. package/dist/compiler/cascade.d.ts +1 -3
  34. package/dist/compiler/cascade.js +1 -10
  35. package/dist/compiler/compile.d.ts +0 -1
  36. package/dist/compiler/compile.js +3 -17
  37. package/dist/compiler/index.d.ts +0 -1
  38. package/dist/compiler/index.js +0 -1
  39. package/dist/compiler/workflow.d.ts +0 -1
  40. package/dist/compiler/workflow.js +0 -2
  41. package/dist/evolution/collector.d.ts +0 -1
  42. package/dist/evolution/collector.js +0 -1
  43. package/dist/evolution/fitness.d.ts +0 -1
  44. package/dist/evolution/fitness.js +0 -1
  45. package/dist/evolution/index.d.ts +0 -1
  46. package/dist/evolution/index.js +0 -1
  47. package/dist/evolution/marker-gen.d.ts +0 -1
  48. package/dist/evolution/marker-gen.js +0 -1
  49. package/dist/evolution/store.d.ts +0 -1
  50. package/dist/evolution/store.js +0 -1
  51. package/dist/evolution/types.d.ts +0 -1
  52. package/dist/evolution/types.js +0 -1
  53. package/dist/hooks/cli.d.ts +17 -0
  54. package/dist/hooks/cli.js +134 -0
  55. package/dist/hooks/enforce.d.ts +68 -0
  56. package/dist/hooks/enforce.js +332 -0
  57. package/dist/hooks/index.d.ts +9 -0
  58. package/dist/hooks/index.js +12 -0
  59. package/dist/hooks/protocol.d.ts +70 -0
  60. package/dist/hooks/protocol.js +91 -0
  61. package/dist/hooks/state.d.ts +53 -0
  62. package/dist/hooks/state.js +93 -0
  63. package/dist/index.d.ts +0 -1
  64. package/dist/index.js +0 -1
  65. package/dist/log/logger.d.ts +0 -1
  66. package/dist/log/logger.js +0 -1
  67. package/dist/runtime/agent-md.d.ts +0 -1
  68. package/dist/runtime/agent-md.js +95 -105
  69. package/dist/runtime/claude-sdk.d.ts +0 -1
  70. package/dist/runtime/claude-sdk.js +0 -1
  71. package/dist/runtime/index.d.ts +3 -3
  72. package/dist/runtime/index.js +2 -2
  73. package/dist/runtime/markdown.d.ts +0 -1
  74. package/dist/runtime/markdown.js +0 -1
  75. package/dist/runtime/plugin-adapter.d.ts +42 -0
  76. package/dist/runtime/plugin-adapter.js +77 -0
  77. package/dist/runtime/settings-adapter.d.ts +8 -9
  78. package/dist/runtime/settings-adapter.js +57 -46
  79. package/dist/runtime/skill-adapter.d.ts +0 -1
  80. package/dist/runtime/skill-adapter.js +94 -71
  81. package/dist/runtime/workflow-runner.d.ts +0 -1
  82. package/dist/runtime/workflow-runner.js +0 -14
  83. package/dist/schema/index.d.ts +0 -1
  84. package/dist/schema/index.js +0 -1
  85. package/dist/schema/types.d.ts +14 -20
  86. package/dist/schema/types.js +0 -1
  87. package/dist/schema/validate.d.ts +0 -1
  88. package/dist/schema/validate.js +3 -19
  89. package/dist/schema/yaml-parser.d.ts +0 -1
  90. package/dist/schema/yaml-parser.js +0 -1
  91. package/dist/templates/code-review-pipeline.dna.yaml +0 -11
  92. package/dist/templates/flutter-behavior-lock.dna.yaml +0 -16
  93. package/dist/templates/flutter-refactoring-rescue.dna.yaml +0 -12
  94. package/dist/templates/flutter-rewrite.dna.yaml +0 -27
  95. package/dist/templates/full-pipeline.dna.yaml +0 -25
  96. package/dist/templates/multi-perspective-review.dna.yaml +0 -12
  97. package/dist/templates/subagent-parallel.dna.yaml +0 -16
  98. package/package.json +3 -2
  99. package/dist/audit/index.d.ts.map +0 -1
  100. package/dist/audit/index.js.map +0 -1
  101. package/dist/cli/commands/compile.d.ts.map +0 -1
  102. package/dist/cli/commands/compile.js.map +0 -1
  103. package/dist/cli/commands/epigenetic.d.ts.map +0 -1
  104. package/dist/cli/commands/epigenetic.js.map +0 -1
  105. package/dist/cli/commands/evolve.d.ts.map +0 -1
  106. package/dist/cli/commands/evolve.js.map +0 -1
  107. package/dist/cli/commands/guard.d.ts.map +0 -1
  108. package/dist/cli/commands/guard.js.map +0 -1
  109. package/dist/cli/commands/import.d.ts.map +0 -1
  110. package/dist/cli/commands/import.js.map +0 -1
  111. package/dist/cli/commands/init.d.ts.map +0 -1
  112. package/dist/cli/commands/init.js.map +0 -1
  113. package/dist/cli/commands/run.d.ts.map +0 -1
  114. package/dist/cli/commands/run.js.map +0 -1
  115. package/dist/cli/commands/show.d.ts.map +0 -1
  116. package/dist/cli/commands/show.js.map +0 -1
  117. package/dist/cli/commands/sync.d.ts.map +0 -1
  118. package/dist/cli/commands/sync.js.map +0 -1
  119. package/dist/cli/commands/validate.d.ts.map +0 -1
  120. package/dist/cli/commands/validate.js.map +0 -1
  121. package/dist/cli/commands/verify.d.ts.map +0 -1
  122. package/dist/cli/commands/verify.js.map +0 -1
  123. package/dist/cli/index.d.ts.map +0 -1
  124. package/dist/cli/index.js.map +0 -1
  125. package/dist/cli/util/format.d.ts.map +0 -1
  126. package/dist/cli/util/format.js.map +0 -1
  127. package/dist/cli/util/prompt.d.ts.map +0 -1
  128. package/dist/cli/util/prompt.js.map +0 -1
  129. package/dist/compiler/activate.d.ts.map +0 -1
  130. package/dist/compiler/activate.js.map +0 -1
  131. package/dist/compiler/cascade.d.ts.map +0 -1
  132. package/dist/compiler/cascade.js.map +0 -1
  133. package/dist/compiler/compile.d.ts.map +0 -1
  134. package/dist/compiler/compile.js.map +0 -1
  135. package/dist/compiler/index.d.ts.map +0 -1
  136. package/dist/compiler/index.js.map +0 -1
  137. package/dist/compiler/workflow.d.ts.map +0 -1
  138. package/dist/compiler/workflow.js.map +0 -1
  139. package/dist/evolution/collector.d.ts.map +0 -1
  140. package/dist/evolution/collector.js.map +0 -1
  141. package/dist/evolution/fitness.d.ts.map +0 -1
  142. package/dist/evolution/fitness.js.map +0 -1
  143. package/dist/evolution/index.d.ts.map +0 -1
  144. package/dist/evolution/index.js.map +0 -1
  145. package/dist/evolution/marker-gen.d.ts.map +0 -1
  146. package/dist/evolution/marker-gen.js.map +0 -1
  147. package/dist/evolution/store.d.ts.map +0 -1
  148. package/dist/evolution/store.js.map +0 -1
  149. package/dist/evolution/types.d.ts.map +0 -1
  150. package/dist/evolution/types.js.map +0 -1
  151. package/dist/index.d.ts.map +0 -1
  152. package/dist/index.js.map +0 -1
  153. package/dist/log/logger.d.ts.map +0 -1
  154. package/dist/log/logger.js.map +0 -1
  155. package/dist/runtime/agent-md.d.ts.map +0 -1
  156. package/dist/runtime/agent-md.js.map +0 -1
  157. package/dist/runtime/claude-sdk.d.ts.map +0 -1
  158. package/dist/runtime/claude-sdk.js.map +0 -1
  159. package/dist/runtime/hooks.d.ts +0 -67
  160. package/dist/runtime/hooks.d.ts.map +0 -1
  161. package/dist/runtime/hooks.js +0 -785
  162. package/dist/runtime/hooks.js.map +0 -1
  163. package/dist/runtime/index.d.ts.map +0 -1
  164. package/dist/runtime/index.js.map +0 -1
  165. package/dist/runtime/markdown.d.ts.map +0 -1
  166. package/dist/runtime/markdown.js.map +0 -1
  167. package/dist/runtime/settings-adapter.d.ts.map +0 -1
  168. package/dist/runtime/settings-adapter.js.map +0 -1
  169. package/dist/runtime/skill-adapter.d.ts.map +0 -1
  170. package/dist/runtime/skill-adapter.js.map +0 -1
  171. package/dist/runtime/workflow-runner.d.ts.map +0 -1
  172. package/dist/runtime/workflow-runner.js.map +0 -1
  173. package/dist/schema/index.d.ts.map +0 -1
  174. package/dist/schema/index.js.map +0 -1
  175. package/dist/schema/types.d.ts.map +0 -1
  176. package/dist/schema/types.js.map +0 -1
  177. package/dist/schema/validate.d.ts.map +0 -1
  178. package/dist/schema/validate.js.map +0 -1
  179. package/dist/schema/yaml-parser.d.ts.map +0 -1
  180. package/dist/schema/yaml-parser.js.map +0 -1
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Intent DNA — Hook Protocol Types
3
+ *
4
+ * TypeScript types for Claude Code hook I/O and stdin/stdout utilities.
5
+ * All hooks read JSON from stdin and write JSON to stdout.
6
+ *
7
+ * Protocol reference: docs/references/cc-source-analysis.md §2
8
+ */
9
+ export type HookEvent = "PreToolUse" | "PostToolUse" | "UserPromptSubmit" | "SubagentStop" | "PreCompact" | "Notification" | "Stop" | "SessionStart";
10
+ /** Base fields present in all hook inputs */
11
+ export interface HookInputBase {
12
+ cwd?: string;
13
+ sessionId?: string;
14
+ }
15
+ export interface PreToolUseInput extends HookInputBase {
16
+ tool_name: string;
17
+ tool_input: Record<string, unknown>;
18
+ agent_type?: string;
19
+ }
20
+ export interface PostToolUseInput extends HookInputBase {
21
+ tool_name: string;
22
+ tool_input: Record<string, unknown>;
23
+ tool_output?: string;
24
+ agent_type?: string;
25
+ }
26
+ export interface UserPromptSubmitInput extends HookInputBase {
27
+ prompt?: string;
28
+ }
29
+ export interface SubagentStopInput extends HookInputBase {
30
+ agent_name?: string;
31
+ agent_type?: string;
32
+ }
33
+ export interface PreCompactInput extends HookInputBase {
34
+ }
35
+ export interface NotificationInput extends HookInputBase {
36
+ title?: string;
37
+ message?: string;
38
+ }
39
+ export interface StopInput extends HookInputBase {
40
+ stop_reason?: string;
41
+ }
42
+ export type HookInput = PreToolUseInput | PostToolUseInput | UserPromptSubmitInput | SubagentStopInput | PreCompactInput | NotificationInput | StopInput;
43
+ export interface HookOutput {
44
+ continue: boolean;
45
+ decision?: "block" | "allow";
46
+ reason?: string;
47
+ suppressOutput?: boolean;
48
+ hookSpecificOutput?: {
49
+ hookEventName?: string;
50
+ additionalContext?: string;
51
+ permissionDecision?: "ask" | "allow" | "deny";
52
+ };
53
+ }
54
+ /** Create an allow output, optionally injecting text into the conversation. */
55
+ export declare function allowOutput(additionalContext?: string): HookOutput;
56
+ /** Create a block output with reason. */
57
+ export declare function blockOutput(reason: string): HookOutput;
58
+ /** Create an escalate output (ask user for permission). */
59
+ export declare function escalateOutput(reason: string): HookOutput;
60
+ /** Create a silent allow output (no visible output to user). */
61
+ export declare function silentOutput(): HookOutput;
62
+ /**
63
+ * Read JSON from stdin with timeout protection.
64
+ * Returns parsed object on success, empty object on failure (fail-open).
65
+ */
66
+ export declare function readStdin(timeoutMs?: number): Promise<Record<string, unknown>>;
67
+ /**
68
+ * Write hook output to stdout as JSON.
69
+ */
70
+ export declare function writeOutput(output: HookOutput): void;
@@ -0,0 +1,91 @@
1
+ /**
2
+ * Intent DNA — Hook Protocol Types
3
+ *
4
+ * TypeScript types for Claude Code hook I/O and stdin/stdout utilities.
5
+ * All hooks read JSON from stdin and write JSON to stdout.
6
+ *
7
+ * Protocol reference: docs/references/cc-source-analysis.md §2
8
+ */
9
+ // ── Output Helpers ─────────────────────────────────────────
10
+ /** Create an allow output, optionally injecting text into the conversation. */
11
+ export function allowOutput(additionalContext) {
12
+ if (additionalContext) {
13
+ return {
14
+ continue: true,
15
+ hookSpecificOutput: { additionalContext },
16
+ };
17
+ }
18
+ return { continue: true };
19
+ }
20
+ /** Create a block output with reason. */
21
+ export function blockOutput(reason) {
22
+ return {
23
+ continue: false,
24
+ decision: "block",
25
+ reason,
26
+ };
27
+ }
28
+ /** Create an escalate output (ask user for permission). */
29
+ export function escalateOutput(reason) {
30
+ return {
31
+ continue: true,
32
+ hookSpecificOutput: {
33
+ permissionDecision: "ask",
34
+ additionalContext: reason,
35
+ },
36
+ };
37
+ }
38
+ /** Create a silent allow output (no visible output to user). */
39
+ export function silentOutput() {
40
+ return { continue: true, suppressOutput: true };
41
+ }
42
+ // ── Stdin/Stdout I/O ───────────────────────────────────────
43
+ /**
44
+ * Read JSON from stdin with timeout protection.
45
+ * Returns parsed object on success, empty object on failure (fail-open).
46
+ */
47
+ export function readStdin(timeoutMs = 5000) {
48
+ return new Promise((resolve) => {
49
+ const chunks = [];
50
+ let settled = false;
51
+ const finish = (data) => {
52
+ if (settled)
53
+ return;
54
+ settled = true;
55
+ clearTimeout(timer);
56
+ process.stdin.removeAllListeners("data");
57
+ process.stdin.removeAllListeners("end");
58
+ process.stdin.removeAllListeners("error");
59
+ resolve(data);
60
+ };
61
+ const timer = setTimeout(() => finish({}), timeoutMs);
62
+ process.stdin.on("data", (chunk) => {
63
+ chunks.push(chunk);
64
+ });
65
+ process.stdin.on("end", () => {
66
+ try {
67
+ const raw = Buffer.concat(chunks).toString("utf-8").trim();
68
+ if (!raw) {
69
+ finish({});
70
+ return;
71
+ }
72
+ const parsed = JSON.parse(raw);
73
+ finish(typeof parsed === "object" && parsed !== null ? parsed : {});
74
+ }
75
+ catch {
76
+ finish({});
77
+ }
78
+ });
79
+ process.stdin.on("error", () => finish({}));
80
+ // If stdin is already ended (piped and closed)
81
+ if (process.stdin.readableEnded) {
82
+ finish({});
83
+ }
84
+ });
85
+ }
86
+ /**
87
+ * Write hook output to stdout as JSON.
88
+ */
89
+ export function writeOutput(output) {
90
+ process.stdout.write(JSON.stringify(output) + "\n");
91
+ }
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Intent DNA — Hook State System
3
+ *
4
+ * Manages `.dna/state/` directory for runtime state tracking:
5
+ * - Workflow state (current workflow, step, role — read by hooks)
6
+ * - Audit log (violation records in JSON Lines format)
7
+ * - Session isolation (per-session state directories)
8
+ *
9
+ * All read operations are fail-safe (return null on error, never throw).
10
+ * All write operations use atomic temp+rename pattern.
11
+ */
12
+ /** Workflow state written by runtime and read by hooks */
13
+ export interface DNAWorkflowState {
14
+ active: boolean;
15
+ workflow: string;
16
+ current_step: string;
17
+ current_role: string;
18
+ iteration: number;
19
+ session_id: string;
20
+ started_at: string;
21
+ }
22
+ /** Audit log entry (one per line in JSON Lines format) */
23
+ export interface AuditEntry {
24
+ timestamp: string;
25
+ event: string;
26
+ tool_name?: string;
27
+ agent_type?: string;
28
+ message: string;
29
+ session_id?: string;
30
+ }
31
+ /**
32
+ * Resolve state directory path.
33
+ * With session isolation: `.dna/state/sessions/<sessionId>/`
34
+ * Without: `.dna/state/`
35
+ */
36
+ export declare function resolveStateDir(projectDir: string, sessionId?: string): string;
37
+ /**
38
+ * Read current workflow state. Returns null if not found or stale.
39
+ */
40
+ export declare function readWorkflowState(projectDir: string, sessionId?: string, stalenessMs?: number): Promise<DNAWorkflowState | null>;
41
+ /**
42
+ * Write workflow state atomically.
43
+ */
44
+ export declare function writeWorkflowState(projectDir: string, state: DNAWorkflowState, sessionId?: string): Promise<void>;
45
+ /**
46
+ * Clear workflow state (workflow complete).
47
+ */
48
+ export declare function clearWorkflowState(projectDir: string, sessionId?: string): Promise<void>;
49
+ /**
50
+ * Append an entry to the audit log.
51
+ * Log file: `.dna/audit/violations-YYYY-MM-DD.log` (JSON Lines format)
52
+ */
53
+ export declare function appendAudit(projectDir: string, entry: AuditEntry): Promise<void>;
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Intent DNA — Hook State System
3
+ *
4
+ * Manages `.dna/state/` directory for runtime state tracking:
5
+ * - Workflow state (current workflow, step, role — read by hooks)
6
+ * - Audit log (violation records in JSON Lines format)
7
+ * - Session isolation (per-session state directories)
8
+ *
9
+ * All read operations are fail-safe (return null on error, never throw).
10
+ * All write operations use atomic temp+rename pattern.
11
+ */
12
+ import { readFile, writeFile, rename, mkdir, appendFile, unlink } from "node:fs/promises";
13
+ import { join, dirname } from "node:path";
14
+ // ── Constants ──────────────────────────────────────────────
15
+ const WORKFLOW_FILE = "workflow.json";
16
+ const DEFAULT_STALENESS_MS = 2 * 60 * 60 * 1000; // 2 hours
17
+ // ── Path Resolution ────────────────────────────────────────
18
+ /**
19
+ * Resolve state directory path.
20
+ * With session isolation: `.dna/state/sessions/<sessionId>/`
21
+ * Without: `.dna/state/`
22
+ */
23
+ export function resolveStateDir(projectDir, sessionId) {
24
+ const base = join(projectDir, ".dna", "state");
25
+ if (sessionId) {
26
+ return join(base, "sessions", sessionId);
27
+ }
28
+ return base;
29
+ }
30
+ // ── Workflow State ─────────────────────────────────────────
31
+ /**
32
+ * Read current workflow state. Returns null if not found or stale.
33
+ */
34
+ export async function readWorkflowState(projectDir, sessionId, stalenessMs = DEFAULT_STALENESS_MS) {
35
+ const stateDir = resolveStateDir(projectDir, sessionId);
36
+ const filePath = join(stateDir, WORKFLOW_FILE);
37
+ try {
38
+ const raw = await readFile(filePath, "utf-8");
39
+ const state = JSON.parse(raw);
40
+ // Staleness check based on started_at
41
+ if (stalenessMs > 0 && state.started_at) {
42
+ const age = Date.now() - new Date(state.started_at).getTime();
43
+ if (age > stalenessMs)
44
+ return null;
45
+ }
46
+ return state;
47
+ }
48
+ catch {
49
+ return null;
50
+ }
51
+ }
52
+ /**
53
+ * Write workflow state atomically.
54
+ */
55
+ export async function writeWorkflowState(projectDir, state, sessionId) {
56
+ const stateDir = resolveStateDir(projectDir, sessionId);
57
+ await mkdir(stateDir, { recursive: true });
58
+ const workflowPath = join(stateDir, WORKFLOW_FILE);
59
+ await atomicWrite(workflowPath, JSON.stringify(state, null, 2));
60
+ }
61
+ /**
62
+ * Clear workflow state (workflow complete).
63
+ */
64
+ export async function clearWorkflowState(projectDir, sessionId) {
65
+ const stateDir = resolveStateDir(projectDir, sessionId);
66
+ const workflowPath = join(stateDir, WORKFLOW_FILE);
67
+ try {
68
+ await unlink(workflowPath);
69
+ }
70
+ catch {
71
+ // Already gone or never existed
72
+ }
73
+ }
74
+ // ── Audit Log ──────────────────────────────────────────────
75
+ /**
76
+ * Append an entry to the audit log.
77
+ * Log file: `.dna/audit/violations-YYYY-MM-DD.log` (JSON Lines format)
78
+ */
79
+ export async function appendAudit(projectDir, entry) {
80
+ const auditDir = join(projectDir, ".dna", "audit");
81
+ await mkdir(auditDir, { recursive: true });
82
+ const date = entry.timestamp.slice(0, 10); // YYYY-MM-DD
83
+ const logPath = join(auditDir, `violations-${date}.log`);
84
+ await appendFile(logPath, JSON.stringify(entry) + "\n", "utf-8");
85
+ }
86
+ // ── Internal ───────────────────────────────────────────────
87
+ /** Atomic write: write to temp file then rename. */
88
+ async function atomicWrite(filePath, data) {
89
+ const tmpPath = filePath + ".tmp." + process.pid;
90
+ await mkdir(dirname(filePath), { recursive: true });
91
+ await writeFile(tmpPath, data, "utf-8");
92
+ await rename(tmpPath, filePath);
93
+ }
package/dist/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
1
  export * from "./schema/index.js";
2
2
  export * from "./compiler/index.js";
3
3
  export * from "./runtime/index.js";
4
- //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,4 +1,3 @@
1
1
  export * from "./schema/index.js";
2
2
  export * from "./compiler/index.js";
3
3
  export * from "./runtime/index.js";
4
- //# sourceMappingURL=index.js.map
@@ -12,4 +12,3 @@ export declare class OutcomeLogger {
12
12
  log(outcome: ExecutionOutcome): Promise<void>;
13
13
  readAll(): Promise<ExecutionOutcome[]>;
14
14
  }
15
- //# sourceMappingURL=logger.d.ts.map
@@ -33,4 +33,3 @@ export class OutcomeLogger {
33
33
  }
34
34
  }
35
35
  }
36
- //# sourceMappingURL=logger.js.map
@@ -53,4 +53,3 @@ export declare function writeAgentMDFiles(results: AgentMDResult[], outputDir: s
53
53
  * Returns number of files removed.
54
54
  */
55
55
  export declare function removeAgentMDFiles(outputDir: string): Promise<number>;
56
- //# sourceMappingURL=agent-md.d.ts.map
@@ -50,99 +50,17 @@ function escapeYamlString(s) {
50
50
  return s.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
51
51
  }
52
52
  /**
53
- * Render scope section if scope is defined.
53
+ * Render constraints from ConstraintIR prompt_directives as bullet points.
54
54
  */
55
- function renderScope(scope) {
55
+ function renderConstraints(ir) {
56
56
  const lines = [];
57
- lines.push("## Scope\n");
58
- if (scope.read && scope.read.length > 0) {
59
- lines.push(`- Read: ${scope.read.join(", ")}`);
60
- }
61
- if (scope.write && scope.write.length > 0) {
62
- lines.push(`- Write: ${scope.write.join(", ")}`);
57
+ for (const d of ir.prompt_directives) {
58
+ lines.push(`- ${d.text}`);
63
59
  }
64
60
  return lines.join("\n");
65
61
  }
66
62
  /**
67
- * Render behavioral guidelines from ConstraintIR prompt_directives.
68
- */
69
- function renderGuidelines(ir) {
70
- if (ir.prompt_directives.length === 0)
71
- return "";
72
- const lines = [];
73
- lines.push("## Behavioral Guidelines\n");
74
- // Group by priority
75
- const high = ir.prompt_directives.filter((d) => d.priority === "high");
76
- const medium = ir.prompt_directives.filter((d) => d.priority === "medium");
77
- const low = ir.prompt_directives.filter((d) => d.priority === "low");
78
- if (high.length > 0) {
79
- lines.push("### Critical");
80
- for (const d of high) {
81
- lines.push(`- **${d.text}**`);
82
- }
83
- lines.push("");
84
- }
85
- if (medium.length > 0) {
86
- lines.push("### Standard");
87
- for (const d of medium) {
88
- lines.push(`- ${d.text}`);
89
- }
90
- lines.push("");
91
- }
92
- if (low.length > 0) {
93
- lines.push("### Preferences");
94
- for (const d of low) {
95
- lines.push(`- ${d.text}`);
96
- }
97
- lines.push("");
98
- }
99
- return lines.join("\n").trimEnd();
100
- }
101
- /**
102
- * Render instructions section as a numbered list.
103
- */
104
- function renderInstructions(instructions) {
105
- const lines = [];
106
- lines.push("## Instructions\n");
107
- for (let i = 0; i < instructions.length; i++) {
108
- lines.push(`${i + 1}. ${instructions[i]}`);
109
- }
110
- return lines.join("\n");
111
- }
112
- /**
113
- * Render output schema section.
114
- */
115
- function renderOutputSchema(schema) {
116
- const lines = [];
117
- lines.push("## Output Format\n");
118
- if (schema.path) {
119
- lines.push(`- Output path: \`${schema.path}\``);
120
- }
121
- if (schema.format && schema.format !== "markdown") {
122
- lines.push(`- Final format: ${schema.format}`);
123
- }
124
- if (schema.required_sections && schema.required_sections.length > 0) {
125
- lines.push("");
126
- lines.push("Required sections:");
127
- for (const section of schema.required_sections) {
128
- lines.push(`- \`## ${section}\``);
129
- }
130
- }
131
- return lines.join("\n");
132
- }
133
- /**
134
- * Render post checks section.
135
- */
136
- function renderPostChecks(checks) {
137
- const lines = [];
138
- lines.push("## Post Checks\n");
139
- for (const check of checks) {
140
- lines.push(`- ${check}`);
141
- }
142
- return lines.join("\n");
143
- }
144
- /**
145
- * Render the full markdown body.
63
+ * Render the full XML body inside Agent_Prompt.
146
64
  */
147
65
  function renderBody(name, role, ir, options) {
148
66
  const prefix = options?.namePrefix ?? "dna-";
@@ -154,35 +72,108 @@ function renderBody(name, role, ir, options) {
154
72
  sections.push(SENTINEL_COMMENT);
155
73
  sections.push(`<!-- Compiled: ${compiledAt} -->`);
156
74
  sections.push("");
157
- // Title + description
158
- sections.push(`# ${fullName}`);
159
- sections.push("");
75
+ // Open Agent_Prompt
76
+ sections.push("<Agent_Prompt>");
77
+ // Role section
78
+ sections.push("<Role>");
160
79
  sections.push(role.description);
161
- // Instructions
80
+ sections.push("</Role>");
81
+ sections.push("");
82
+ // Constraints — from IR prompt_directives
83
+ const hasConstraints = includeDNA && ir && ir.prompt_directives.length > 0;
84
+ sections.push("<Constraints>");
85
+ if (hasConstraints) {
86
+ sections.push(renderConstraints(ir));
87
+ }
88
+ sections.push("</Constraints>");
89
+ sections.push("");
90
+ // Steps — instructions or fallback
91
+ sections.push("<Steps>");
162
92
  if (role.instructions && role.instructions.length > 0) {
163
- sections.push("");
164
- sections.push(renderInstructions(role.instructions));
93
+ for (let i = 0; i < role.instructions.length; i++) {
94
+ sections.push(`${i + 1}. ${role.instructions[i]}`);
95
+ }
96
+ }
97
+ else {
98
+ sections.push("Follow the task prompt.");
165
99
  }
100
+ sections.push("</Steps>");
101
+ sections.push("");
102
+ // Tool_Usage
103
+ const allowedTools = role.tool_permissions?.allow && role.tool_permissions.allow.length > 0
104
+ ? role.tool_permissions.allow.join(", ")
105
+ : "all";
106
+ const deniedTools = role.tool_permissions?.deny && role.tool_permissions.deny.length > 0
107
+ ? role.tool_permissions.deny.join(", ")
108
+ : "none";
109
+ sections.push("<Tool_Usage>");
110
+ sections.push(`- Allowed: ${allowedTools}`);
111
+ sections.push(`- Denied: ${deniedTools}`);
112
+ sections.push("</Tool_Usage>");
113
+ sections.push("");
166
114
  // Scope
167
- if (role.scope) {
115
+ const readPaths = role.scope?.read && role.scope.read.length > 0
116
+ ? role.scope.read.join(", ")
117
+ : "all files";
118
+ const writePaths = role.scope?.write && role.scope.write.length > 0
119
+ ? role.scope.write.join(", ")
120
+ : "none";
121
+ sections.push("<Scope>");
122
+ sections.push(`- Read: ${readPaths}`);
123
+ sections.push(`- Write: ${writePaths}`);
124
+ sections.push("</Scope>");
125
+ // Output_Format — only when structured output_schema present
126
+ if (role.output_schema && typeof role.output_schema !== "string") {
127
+ const schema = role.output_schema;
128
+ const lines = [];
129
+ if (schema.path) {
130
+ lines.push(`- Output path: \`${schema.path}\``);
131
+ }
132
+ if (schema.format && schema.format !== "markdown") {
133
+ lines.push(`- Final format: ${schema.format}`);
134
+ }
135
+ if (schema.required_sections && schema.required_sections.length > 0) {
136
+ lines.push("");
137
+ lines.push("Required sections:");
138
+ for (const section of schema.required_sections) {
139
+ lines.push(`- \`## ${section}\``);
140
+ }
141
+ }
168
142
  sections.push("");
169
- sections.push(renderScope(role.scope));
143
+ sections.push("<Output_Format>");
144
+ sections.push(lines.join("\n"));
145
+ sections.push("</Output_Format>");
170
146
  }
171
- // Behavioral guidelines from IR
172
- if (includeDNA && ir && ir.prompt_directives.length > 0) {
147
+ // Final_Checklist post_checks
148
+ if (role.post_checks && role.post_checks.length > 0) {
173
149
  sections.push("");
174
- sections.push(renderGuidelines(ir));
150
+ sections.push("<Final_Checklist>");
151
+ for (const check of role.post_checks) {
152
+ sections.push(`- ${check}`);
153
+ }
154
+ sections.push("</Final_Checklist>");
175
155
  }
176
- // Output format
177
- if (role.output_schema && typeof role.output_schema !== "string") {
156
+ // Success_Criteria — optional field
157
+ if (role.success_criteria && role.success_criteria.length > 0) {
178
158
  sections.push("");
179
- sections.push(renderOutputSchema(role.output_schema));
159
+ sections.push("<Success_Criteria>");
160
+ for (const criterion of role.success_criteria) {
161
+ sections.push(`- ${criterion}`);
162
+ }
163
+ sections.push("</Success_Criteria>");
180
164
  }
181
- // Post checks
182
- if (role.post_checks && role.post_checks.length > 0) {
165
+ // Failure_Modes — optional field
166
+ if (role.failure_modes && role.failure_modes.length > 0) {
183
167
  sections.push("");
184
- sections.push(renderPostChecks(role.post_checks));
168
+ sections.push("<Failure_Modes>");
169
+ for (const mode of role.failure_modes) {
170
+ sections.push(`- ${mode}`);
171
+ }
172
+ sections.push("</Failure_Modes>");
185
173
  }
174
+ // Close Agent_Prompt
175
+ sections.push("");
176
+ sections.push("</Agent_Prompt>");
186
177
  return sections.join("\n") + "\n";
187
178
  }
188
179
  // ── Core Functions ─────────────────────────────────────────
@@ -254,4 +245,3 @@ export async function removeAgentMDFiles(outputDir) {
254
245
  }
255
246
  return removed;
256
247
  }
257
- //# sourceMappingURL=agent-md.js.map
@@ -48,4 +48,3 @@ export interface PostToolRule {
48
48
  * Compile Constraint IR to Claude Agent SDK configuration.
49
49
  */
50
50
  export declare function compileForClaude(ir: ConstraintIR): ClaudeDNAConfig;
51
- //# sourceMappingURL=claude-sdk.d.ts.map
@@ -75,4 +75,3 @@ export function compileForClaude(ir) {
75
75
  compiled_at: ir.compiled_at,
76
76
  };
77
77
  }
78
- //# sourceMappingURL=claude-sdk.js.map
@@ -1,9 +1,9 @@
1
1
  export { compileForClaude } from "./claude-sdk.js";
2
2
  export type { ClaudeDNAConfig, PreToolRule, PostToolRule } from "./claude-sdk.js";
3
- export { compileToHooks, writeHookScripts, removeHookScripts, generateSettingsSnippet, } from "./hooks.js";
4
- export type { HookScripts, HookCompileOptions } from "./hooks.js";
5
3
  export { compileRoleToAgentMD, compileAllRolesToAgentMD, writeAgentMDFiles, removeAgentMDFiles, toKebabCase, } from "./agent-md.js";
6
4
  export type { AgentMDOptions, AgentMDResult } from "./agent-md.js";
7
5
  export { compileWorkflowToShell, writeWorkflowScript, removeWorkflowScripts, } from "./workflow-runner.js";
8
6
  export type { WorkflowShellOptions, WorkflowShellResult } from "./workflow-runner.js";
9
- //# sourceMappingURL=index.d.ts.map
7
+ export { createCompiledIR, writeCompiledIR, loadCompiledIR, removeCompiledIR, } from "./plugin-adapter.js";
8
+ export type { CompiledIRFile } from "./plugin-adapter.js";
9
+ export { compilePluginSettings, detectEnabledEvents, } from "./settings-adapter.js";
@@ -1,5 +1,5 @@
1
1
  export { compileForClaude } from "./claude-sdk.js";
2
- export { compileToHooks, writeHookScripts, removeHookScripts, generateSettingsSnippet, } from "./hooks.js";
3
2
  export { compileRoleToAgentMD, compileAllRolesToAgentMD, writeAgentMDFiles, removeAgentMDFiles, toKebabCase, } from "./agent-md.js";
4
3
  export { compileWorkflowToShell, writeWorkflowScript, removeWorkflowScripts, } from "./workflow-runner.js";
5
- //# sourceMappingURL=index.js.map
4
+ export { createCompiledIR, writeCompiledIR, loadCompiledIR, removeCompiledIR, } from "./plugin-adapter.js";
5
+ export { compilePluginSettings, detectEnabledEvents, } from "./settings-adapter.js";
@@ -33,4 +33,3 @@ export declare function injectIntoFile(filePath: string, content: string): Promi
33
33
  * Returns true if block was found and removed.
34
34
  */
35
35
  export declare function removeFromFile(filePath: string): Promise<boolean>;
36
- //# sourceMappingURL=markdown.d.ts.map
@@ -211,4 +211,3 @@ function renderSystemPrompt(ir) {
211
211
  }
212
212
  return lines.join("\n");
213
213
  }
214
- //# sourceMappingURL=markdown.js.map
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Intent DNA — Plugin Adapter
3
+ *
4
+ * Serializes compiled ConstraintIR to .dna/compiled/ir.json for
5
+ * the Node.js hook runtime (`dna-hook`) to read at enforcement time.
6
+ *
7
+ * This is the bridge between compile-time (dna sync) and runtime (hook execution).
8
+ */
9
+ import type { ConstraintIR, RoleDef } from "../schema/types.js";
10
+ /** Wrapper around ConstraintIR with versioning metadata */
11
+ export interface CompiledIRFile {
12
+ /** Schema version for forward compatibility */
13
+ ir_version: 1;
14
+ /** When the IR was compiled */
15
+ compiled_at: string;
16
+ /** Source DNA file IDs */
17
+ source_dna_ids: string[];
18
+ /** The compiled Constraint IR */
19
+ ir: ConstraintIR;
20
+ /** Cascaded role definitions (for output_schema enforcement) */
21
+ roles?: Record<string, RoleDef>;
22
+ }
23
+ /**
24
+ * Create a CompiledIRFile wrapper around a ConstraintIR.
25
+ */
26
+ export declare function createCompiledIR(ir: ConstraintIR, roles?: Record<string, RoleDef>): CompiledIRFile;
27
+ /**
28
+ * Write compiled IR to .dna/compiled/ir.json.
29
+ * Creates the directory if needed.
30
+ * Returns the absolute path written.
31
+ */
32
+ export declare function writeCompiledIR(projectDir: string, compiled: CompiledIRFile): Promise<string>;
33
+ /**
34
+ * Load a CompiledIRFile from disk.
35
+ * Returns null if not found or invalid.
36
+ */
37
+ export declare function loadCompiledIR(irPath: string): Promise<CompiledIRFile | null>;
38
+ /**
39
+ * Remove compiled IR file.
40
+ * Returns true if removed, false if not found.
41
+ */
42
+ export declare function removeCompiledIR(projectDir: string): Promise<boolean>;