intentdna 1.2.2 → 1.3.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/.claude-plugin/hooks/hooks.json +12 -0
- package/.claude-plugin/plugin.json +5 -0
- package/dist/audit/index.d.ts +0 -1
- package/dist/audit/index.js +0 -1
- package/dist/cli/commands/compile.d.ts +0 -1
- package/dist/cli/commands/compile.js +0 -1
- package/dist/cli/commands/epigenetic.d.ts +0 -1
- package/dist/cli/commands/epigenetic.js +0 -1
- package/dist/cli/commands/evolve.d.ts +0 -1
- package/dist/cli/commands/evolve.js +0 -1
- package/dist/cli/commands/guard.d.ts +0 -1
- package/dist/cli/commands/guard.js +0 -3
- package/dist/cli/commands/import.d.ts +0 -1
- package/dist/cli/commands/import.js +0 -1
- package/dist/cli/commands/init.d.ts +0 -1
- package/dist/cli/commands/init.js +0 -1
- package/dist/cli/commands/run.d.ts +0 -1
- package/dist/cli/commands/run.js +4 -27
- package/dist/cli/commands/setup.d.ts +9 -0
- package/dist/cli/commands/setup.js +42 -0
- package/dist/cli/commands/show.d.ts +0 -1
- package/dist/cli/commands/show.js +0 -1
- package/dist/cli/commands/sync.d.ts +13 -1
- package/dist/cli/commands/sync.js +158 -33
- package/dist/cli/commands/validate.d.ts +0 -1
- package/dist/cli/commands/validate.js +0 -1
- package/dist/cli/commands/verify.d.ts +0 -1
- package/dist/cli/commands/verify.js +0 -1
- package/dist/cli/index.d.ts +0 -1
- package/dist/cli/index.js +9 -1
- package/dist/cli/util/format.d.ts +0 -1
- package/dist/cli/util/format.js +0 -1
- package/dist/cli/util/prompt.d.ts +0 -1
- package/dist/cli/util/prompt.js +0 -1
- package/dist/compiler/activate.d.ts +0 -1
- package/dist/compiler/activate.js +0 -1
- package/dist/compiler/cascade.d.ts +1 -3
- package/dist/compiler/cascade.js +1 -10
- package/dist/compiler/compile.d.ts +0 -1
- package/dist/compiler/compile.js +33 -17
- package/dist/compiler/index.d.ts +0 -1
- package/dist/compiler/index.js +0 -1
- package/dist/compiler/workflow.d.ts +0 -1
- package/dist/compiler/workflow.js +0 -2
- package/dist/evolution/collector.d.ts +0 -1
- package/dist/evolution/collector.js +0 -1
- package/dist/evolution/fitness.d.ts +0 -1
- package/dist/evolution/fitness.js +0 -1
- package/dist/evolution/index.d.ts +0 -1
- package/dist/evolution/index.js +0 -1
- package/dist/evolution/marker-gen.d.ts +0 -1
- package/dist/evolution/marker-gen.js +0 -1
- package/dist/evolution/store.d.ts +0 -1
- package/dist/evolution/store.js +0 -1
- package/dist/evolution/types.d.ts +0 -1
- package/dist/evolution/types.js +0 -1
- package/dist/hooks/cli.d.ts +17 -0
- package/dist/hooks/cli.js +156 -0
- package/dist/hooks/enforce.d.ts +106 -0
- package/dist/hooks/enforce.js +431 -0
- package/dist/hooks/index.d.ts +9 -0
- package/dist/hooks/index.js +12 -0
- package/dist/hooks/protocol.d.ts +73 -0
- package/dist/hooks/protocol.js +91 -0
- package/dist/hooks/state.d.ts +53 -0
- package/dist/hooks/state.js +93 -0
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/log/logger.d.ts +0 -1
- package/dist/log/logger.js +0 -1
- package/dist/runtime/agent-md.d.ts +0 -1
- package/dist/runtime/agent-md.js +95 -105
- package/dist/runtime/claude-sdk.d.ts +0 -1
- package/dist/runtime/claude-sdk.js +0 -1
- package/dist/runtime/index.d.ts +3 -3
- package/dist/runtime/index.js +2 -2
- package/dist/runtime/markdown.d.ts +0 -1
- package/dist/runtime/markdown.js +0 -1
- package/dist/runtime/plugin-adapter.d.ts +42 -0
- package/dist/runtime/plugin-adapter.js +77 -0
- package/dist/runtime/settings-adapter.d.ts +8 -9
- package/dist/runtime/settings-adapter.js +57 -46
- package/dist/runtime/skill-adapter.d.ts +0 -1
- package/dist/runtime/skill-adapter.js +94 -71
- package/dist/runtime/workflow-runner.d.ts +0 -1
- package/dist/runtime/workflow-runner.js +0 -14
- package/dist/schema/index.d.ts +0 -1
- package/dist/schema/index.js +0 -1
- package/dist/schema/types.d.ts +33 -20
- package/dist/schema/types.js +0 -1
- package/dist/schema/validate.d.ts +0 -1
- package/dist/schema/validate.js +32 -19
- package/dist/schema/yaml-parser.d.ts +0 -1
- package/dist/schema/yaml-parser.js +0 -1
- package/dist/templates/code-review-pipeline.dna.yaml +0 -11
- package/dist/templates/flutter-behavior-lock.dna.yaml +0 -16
- package/dist/templates/flutter-refactoring-rescue.dna.yaml +0 -12
- package/dist/templates/flutter-rewrite.dna.yaml +0 -27
- package/dist/templates/full-pipeline.dna.yaml +0 -25
- package/dist/templates/multi-perspective-review.dna.yaml +0 -12
- package/dist/templates/subagent-parallel.dna.yaml +0 -16
- package/package.json +4 -2
- package/dist/audit/index.d.ts.map +0 -1
- package/dist/audit/index.js.map +0 -1
- package/dist/cli/commands/compile.d.ts.map +0 -1
- package/dist/cli/commands/compile.js.map +0 -1
- package/dist/cli/commands/epigenetic.d.ts.map +0 -1
- package/dist/cli/commands/epigenetic.js.map +0 -1
- package/dist/cli/commands/evolve.d.ts.map +0 -1
- package/dist/cli/commands/evolve.js.map +0 -1
- package/dist/cli/commands/guard.d.ts.map +0 -1
- package/dist/cli/commands/guard.js.map +0 -1
- package/dist/cli/commands/import.d.ts.map +0 -1
- package/dist/cli/commands/import.js.map +0 -1
- package/dist/cli/commands/init.d.ts.map +0 -1
- package/dist/cli/commands/init.js.map +0 -1
- package/dist/cli/commands/run.d.ts.map +0 -1
- package/dist/cli/commands/run.js.map +0 -1
- package/dist/cli/commands/show.d.ts.map +0 -1
- package/dist/cli/commands/show.js.map +0 -1
- package/dist/cli/commands/sync.d.ts.map +0 -1
- package/dist/cli/commands/sync.js.map +0 -1
- package/dist/cli/commands/validate.d.ts.map +0 -1
- package/dist/cli/commands/validate.js.map +0 -1
- package/dist/cli/commands/verify.d.ts.map +0 -1
- package/dist/cli/commands/verify.js.map +0 -1
- package/dist/cli/index.d.ts.map +0 -1
- package/dist/cli/index.js.map +0 -1
- package/dist/cli/util/format.d.ts.map +0 -1
- package/dist/cli/util/format.js.map +0 -1
- package/dist/cli/util/prompt.d.ts.map +0 -1
- package/dist/cli/util/prompt.js.map +0 -1
- package/dist/compiler/activate.d.ts.map +0 -1
- package/dist/compiler/activate.js.map +0 -1
- package/dist/compiler/cascade.d.ts.map +0 -1
- package/dist/compiler/cascade.js.map +0 -1
- package/dist/compiler/compile.d.ts.map +0 -1
- package/dist/compiler/compile.js.map +0 -1
- package/dist/compiler/index.d.ts.map +0 -1
- package/dist/compiler/index.js.map +0 -1
- package/dist/compiler/workflow.d.ts.map +0 -1
- package/dist/compiler/workflow.js.map +0 -1
- package/dist/evolution/collector.d.ts.map +0 -1
- package/dist/evolution/collector.js.map +0 -1
- package/dist/evolution/fitness.d.ts.map +0 -1
- package/dist/evolution/fitness.js.map +0 -1
- package/dist/evolution/index.d.ts.map +0 -1
- package/dist/evolution/index.js.map +0 -1
- package/dist/evolution/marker-gen.d.ts.map +0 -1
- package/dist/evolution/marker-gen.js.map +0 -1
- package/dist/evolution/store.d.ts.map +0 -1
- package/dist/evolution/store.js.map +0 -1
- package/dist/evolution/types.d.ts.map +0 -1
- package/dist/evolution/types.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/log/logger.d.ts.map +0 -1
- package/dist/log/logger.js.map +0 -1
- package/dist/runtime/agent-md.d.ts.map +0 -1
- package/dist/runtime/agent-md.js.map +0 -1
- package/dist/runtime/claude-sdk.d.ts.map +0 -1
- package/dist/runtime/claude-sdk.js.map +0 -1
- package/dist/runtime/hooks.d.ts +0 -67
- package/dist/runtime/hooks.d.ts.map +0 -1
- package/dist/runtime/hooks.js +0 -785
- package/dist/runtime/hooks.js.map +0 -1
- package/dist/runtime/index.d.ts.map +0 -1
- package/dist/runtime/index.js.map +0 -1
- package/dist/runtime/markdown.d.ts.map +0 -1
- package/dist/runtime/markdown.js.map +0 -1
- package/dist/runtime/settings-adapter.d.ts.map +0 -1
- package/dist/runtime/settings-adapter.js.map +0 -1
- package/dist/runtime/skill-adapter.d.ts.map +0 -1
- package/dist/runtime/skill-adapter.js.map +0 -1
- package/dist/runtime/workflow-runner.d.ts.map +0 -1
- package/dist/runtime/workflow-runner.js.map +0 -1
- package/dist/schema/index.d.ts.map +0 -1
- package/dist/schema/index.js.map +0 -1
- package/dist/schema/types.d.ts.map +0 -1
- package/dist/schema/types.js.map +0 -1
- package/dist/schema/validate.d.ts.map +0 -1
- package/dist/schema/validate.js.map +0 -1
- package/dist/schema/yaml-parser.d.ts.map +0 -1
- package/dist/schema/yaml-parser.js.map +0 -1
|
@@ -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
package/dist/index.js
CHANGED
package/dist/log/logger.d.ts
CHANGED
package/dist/log/logger.js
CHANGED
package/dist/runtime/agent-md.js
CHANGED
|
@@ -50,99 +50,17 @@ function escapeYamlString(s) {
|
|
|
50
50
|
return s.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
|
51
51
|
}
|
|
52
52
|
/**
|
|
53
|
-
* Render
|
|
53
|
+
* Render constraints from ConstraintIR prompt_directives as bullet points.
|
|
54
54
|
*/
|
|
55
|
-
function
|
|
55
|
+
function renderConstraints(ir) {
|
|
56
56
|
const lines = [];
|
|
57
|
-
|
|
58
|
-
|
|
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
|
|
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
|
-
//
|
|
158
|
-
sections.push(
|
|
159
|
-
|
|
75
|
+
// Open Agent_Prompt
|
|
76
|
+
sections.push("<Agent_Prompt>");
|
|
77
|
+
// Role section
|
|
78
|
+
sections.push("<Role>");
|
|
160
79
|
sections.push(role.description);
|
|
161
|
-
|
|
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
|
-
|
|
164
|
-
|
|
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
|
-
|
|
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(
|
|
143
|
+
sections.push("<Output_Format>");
|
|
144
|
+
sections.push(lines.join("\n"));
|
|
145
|
+
sections.push("</Output_Format>");
|
|
170
146
|
}
|
|
171
|
-
//
|
|
172
|
-
if (
|
|
147
|
+
// Final_Checklist — post_checks
|
|
148
|
+
if (role.post_checks && role.post_checks.length > 0) {
|
|
173
149
|
sections.push("");
|
|
174
|
-
sections.push(
|
|
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
|
-
//
|
|
177
|
-
if (role.
|
|
156
|
+
// Success_Criteria — optional field
|
|
157
|
+
if (role.success_criteria && role.success_criteria.length > 0) {
|
|
178
158
|
sections.push("");
|
|
179
|
-
sections.push(
|
|
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
|
-
//
|
|
182
|
-
if (role.
|
|
165
|
+
// Failure_Modes — optional field
|
|
166
|
+
if (role.failure_modes && role.failure_modes.length > 0) {
|
|
183
167
|
sections.push("");
|
|
184
|
-
sections.push(
|
|
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
|
package/dist/runtime/index.d.ts
CHANGED
|
@@ -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
|
-
|
|
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";
|
package/dist/runtime/index.js
CHANGED
|
@@ -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
|
-
|
|
4
|
+
export { createCompiledIR, writeCompiledIR, loadCompiledIR, removeCompiledIR, } from "./plugin-adapter.js";
|
|
5
|
+
export { compilePluginSettings, detectEnabledEvents, } from "./settings-adapter.js";
|
package/dist/runtime/markdown.js
CHANGED
|
@@ -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>;
|
|
@@ -0,0 +1,77 @@
|
|
|
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 { readFile, writeFile, mkdir } from "node:fs/promises";
|
|
10
|
+
import { join } from "node:path";
|
|
11
|
+
// ── Serialize ──────────────────────────────────────────────
|
|
12
|
+
/**
|
|
13
|
+
* Create a CompiledIRFile wrapper around a ConstraintIR.
|
|
14
|
+
*/
|
|
15
|
+
export function createCompiledIR(ir, roles) {
|
|
16
|
+
return {
|
|
17
|
+
ir_version: 1,
|
|
18
|
+
compiled_at: ir.compiled_at,
|
|
19
|
+
source_dna_ids: ir.source_dna_ids,
|
|
20
|
+
ir,
|
|
21
|
+
roles: roles && Object.keys(roles).length > 0 ? roles : undefined,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Write compiled IR to .dna/compiled/ir.json.
|
|
26
|
+
* Creates the directory if needed.
|
|
27
|
+
* Returns the absolute path written.
|
|
28
|
+
*/
|
|
29
|
+
export async function writeCompiledIR(projectDir, compiled) {
|
|
30
|
+
const outputDir = join(projectDir, ".dna", "compiled");
|
|
31
|
+
await mkdir(outputDir, { recursive: true });
|
|
32
|
+
const outputPath = join(outputDir, "ir.json");
|
|
33
|
+
await writeFile(outputPath, JSON.stringify(compiled, null, 2) + "\n", "utf-8");
|
|
34
|
+
return outputPath;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Load a CompiledIRFile from disk.
|
|
38
|
+
* Returns null if not found or invalid.
|
|
39
|
+
*/
|
|
40
|
+
export async function loadCompiledIR(irPath) {
|
|
41
|
+
try {
|
|
42
|
+
const raw = await readFile(irPath, "utf-8");
|
|
43
|
+
const data = JSON.parse(raw);
|
|
44
|
+
// Validate wrapper format
|
|
45
|
+
if (data.ir_version === 1 && data.ir && data.compiled_at) {
|
|
46
|
+
return data;
|
|
47
|
+
}
|
|
48
|
+
// Maybe it's a raw ConstraintIR (backward compat)
|
|
49
|
+
if (data.compiled_at && data.source_dna_ids) {
|
|
50
|
+
return {
|
|
51
|
+
ir_version: 1,
|
|
52
|
+
compiled_at: data.compiled_at,
|
|
53
|
+
source_dna_ids: data.source_dna_ids,
|
|
54
|
+
ir: data,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Remove compiled IR file.
|
|
65
|
+
* Returns true if removed, false if not found.
|
|
66
|
+
*/
|
|
67
|
+
export async function removeCompiledIR(projectDir) {
|
|
68
|
+
const irPath = join(projectDir, ".dna", "compiled", "ir.json");
|
|
69
|
+
try {
|
|
70
|
+
const { unlink } = await import("node:fs/promises");
|
|
71
|
+
await unlink(irPath);
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Intent DNA — Settings Adapter
|
|
3
3
|
*
|
|
4
|
-
* Compiles DNA hook
|
|
5
|
-
* hook configurations for
|
|
4
|
+
* Compiles DNA hook events into Claude Code settings.json
|
|
5
|
+
* hook configurations for the dna-hook binary.
|
|
6
6
|
*
|
|
7
7
|
* See docs/references/cc-source-analysis.md §2 for the full hook event catalog.
|
|
8
8
|
*/
|
|
9
|
-
|
|
9
|
+
export type HookEventKey = "preToolUse" | "postToolUse" | "userPromptSubmit" | "subagentStop" | "preCompact" | "notification";
|
|
10
10
|
export interface SettingsHookEntry {
|
|
11
11
|
matcher: string;
|
|
12
12
|
hooks: Array<{
|
|
@@ -18,18 +18,17 @@ export interface DNASettings {
|
|
|
18
18
|
hooks: Record<string, SettingsHookEntry[]>;
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
|
-
* Compile
|
|
22
|
-
*
|
|
21
|
+
* Compile settings.json hook configuration for dna-hook binary.
|
|
22
|
+
* Uses `dna-hook <event>` commands.
|
|
23
23
|
*/
|
|
24
|
-
export declare function
|
|
24
|
+
export declare function compilePluginSettings(enabledEvents: HookEventKey[], timeout?: number): DNASettings;
|
|
25
25
|
/**
|
|
26
|
-
*
|
|
26
|
+
* Determine which hook events are needed based on IR content.
|
|
27
27
|
*/
|
|
28
|
-
export declare function
|
|
28
|
+
export declare function detectEnabledEvents(ir: import("../schema/types.js").ConstraintIR): HookEventKey[];
|
|
29
29
|
/**
|
|
30
30
|
* Merge DNA settings into existing settings.json.
|
|
31
31
|
* Only touches the hooks section — preserves other settings.
|
|
32
32
|
* Replaces DNA hooks (identified by "dna-" prefix), keeps user hooks.
|
|
33
33
|
*/
|
|
34
34
|
export declare function mergeSettingsFile(dnaSettings: DNASettings, settingsPath: string): Promise<void>;
|
|
35
|
-
//# sourceMappingURL=settings-adapter.d.ts.map
|