@aiassesstech/noah 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/LICENSE +41 -0
  3. package/README.md +170 -0
  4. package/SKILL.md +64 -0
  5. package/agent/AGENTS.md +138 -0
  6. package/agent/IDENTITY.md +12 -0
  7. package/agent/SOUL.md +143 -0
  8. package/dist/alert/alert-system.d.ts +47 -0
  9. package/dist/alert/alert-system.d.ts.map +1 -0
  10. package/dist/alert/alert-system.js +117 -0
  11. package/dist/alert/alert-system.js.map +1 -0
  12. package/dist/alert/commander-escalation.d.ts +26 -0
  13. package/dist/alert/commander-escalation.d.ts.map +1 -0
  14. package/dist/alert/commander-escalation.js +61 -0
  15. package/dist/alert/commander-escalation.js.map +1 -0
  16. package/dist/cli/bin.d.ts +8 -0
  17. package/dist/cli/bin.d.ts.map +1 -0
  18. package/dist/cli/bin.js +12 -0
  19. package/dist/cli/bin.js.map +1 -0
  20. package/dist/cli/runner.d.ts +13 -0
  21. package/dist/cli/runner.d.ts.map +1 -0
  22. package/dist/cli/runner.js +95 -0
  23. package/dist/cli/runner.js.map +1 -0
  24. package/dist/cli/setup.d.ts +34 -0
  25. package/dist/cli/setup.d.ts.map +1 -0
  26. package/dist/cli/setup.js +237 -0
  27. package/dist/cli/setup.js.map +1 -0
  28. package/dist/clock/financial-runway.d.ts +32 -0
  29. package/dist/clock/financial-runway.d.ts.map +1 -0
  30. package/dist/clock/financial-runway.js +46 -0
  31. package/dist/clock/financial-runway.js.map +1 -0
  32. package/dist/clock/internal-clock.d.ts +53 -0
  33. package/dist/clock/internal-clock.d.ts.map +1 -0
  34. package/dist/clock/internal-clock.js +177 -0
  35. package/dist/clock/internal-clock.js.map +1 -0
  36. package/dist/clock/phase-machine.d.ts +36 -0
  37. package/dist/clock/phase-machine.d.ts.map +1 -0
  38. package/dist/clock/phase-machine.js +123 -0
  39. package/dist/clock/phase-machine.js.map +1 -0
  40. package/dist/clock/phase-transitions.d.ts +9 -0
  41. package/dist/clock/phase-transitions.d.ts.map +1 -0
  42. package/dist/clock/phase-transitions.js +58 -0
  43. package/dist/clock/phase-transitions.js.map +1 -0
  44. package/dist/deviation/corridor-classifier.d.ts +15 -0
  45. package/dist/deviation/corridor-classifier.d.ts.map +1 -0
  46. package/dist/deviation/corridor-classifier.js +21 -0
  47. package/dist/deviation/corridor-classifier.js.map +1 -0
  48. package/dist/deviation/deviation-calculator.d.ts +25 -0
  49. package/dist/deviation/deviation-calculator.d.ts.map +1 -0
  50. package/dist/deviation/deviation-calculator.js +53 -0
  51. package/dist/deviation/deviation-calculator.js.map +1 -0
  52. package/dist/deviation/recommendations.d.ts +13 -0
  53. package/dist/deviation/recommendations.d.ts.map +1 -0
  54. package/dist/deviation/recommendations.js +54 -0
  55. package/dist/deviation/recommendations.js.map +1 -0
  56. package/dist/flight-plan/corridor.d.ts +31 -0
  57. package/dist/flight-plan/corridor.d.ts.map +1 -0
  58. package/dist/flight-plan/corridor.js +49 -0
  59. package/dist/flight-plan/corridor.js.map +1 -0
  60. package/dist/flight-plan/default-plan.d.ts +16 -0
  61. package/dist/flight-plan/default-plan.d.ts.map +1 -0
  62. package/dist/flight-plan/default-plan.js +166 -0
  63. package/dist/flight-plan/default-plan.js.map +1 -0
  64. package/dist/flight-plan/flight-plan-engine.d.ts +37 -0
  65. package/dist/flight-plan/flight-plan-engine.d.ts.map +1 -0
  66. package/dist/flight-plan/flight-plan-engine.js +94 -0
  67. package/dist/flight-plan/flight-plan-engine.js.map +1 -0
  68. package/dist/flight-plan/interpolation.d.ts +48 -0
  69. package/dist/flight-plan/interpolation.d.ts.map +1 -0
  70. package/dist/flight-plan/interpolation.js +179 -0
  71. package/dist/flight-plan/interpolation.js.map +1 -0
  72. package/dist/go-no-go/temporal-decision-matrix.d.ts +30 -0
  73. package/dist/go-no-go/temporal-decision-matrix.d.ts.map +1 -0
  74. package/dist/go-no-go/temporal-decision-matrix.js +94 -0
  75. package/dist/go-no-go/temporal-decision-matrix.js.map +1 -0
  76. package/dist/index.d.ts +31 -0
  77. package/dist/index.d.ts.map +1 -0
  78. package/dist/index.js +37 -0
  79. package/dist/index.js.map +1 -0
  80. package/dist/integration/event-emitter.d.ts +14 -0
  81. package/dist/integration/event-emitter.d.ts.map +1 -0
  82. package/dist/integration/event-emitter.js +24 -0
  83. package/dist/integration/event-emitter.js.map +1 -0
  84. package/dist/integration/grillo-hook.d.ts +106 -0
  85. package/dist/integration/grillo-hook.d.ts.map +1 -0
  86. package/dist/integration/grillo-hook.js +202 -0
  87. package/dist/integration/grillo-hook.js.map +1 -0
  88. package/dist/plugin.d.ts +20 -0
  89. package/dist/plugin.d.ts.map +1 -0
  90. package/dist/plugin.js +480 -0
  91. package/dist/plugin.js.map +1 -0
  92. package/dist/store/hash-chain.d.ts +35 -0
  93. package/dist/store/hash-chain.d.ts.map +1 -0
  94. package/dist/store/hash-chain.js +64 -0
  95. package/dist/store/hash-chain.js.map +1 -0
  96. package/dist/store/json-store.d.ts +47 -0
  97. package/dist/store/json-store.d.ts.map +1 -0
  98. package/dist/store/json-store.js +213 -0
  99. package/dist/store/json-store.js.map +1 -0
  100. package/dist/store/temporal-state-store.d.ts +7 -0
  101. package/dist/store/temporal-state-store.d.ts.map +1 -0
  102. package/dist/store/temporal-state-store.js +7 -0
  103. package/dist/store/temporal-state-store.js.map +1 -0
  104. package/dist/store/types.d.ts +27 -0
  105. package/dist/store/types.d.ts.map +1 -0
  106. package/dist/store/types.js +8 -0
  107. package/dist/store/types.js.map +1 -0
  108. package/dist/types/assessment-record.d.ts +34 -0
  109. package/dist/types/assessment-record.d.ts.map +1 -0
  110. package/dist/types/assessment-record.js +9 -0
  111. package/dist/types/assessment-record.js.map +1 -0
  112. package/dist/types/events.d.ts +57 -0
  113. package/dist/types/events.d.ts.map +1 -0
  114. package/dist/types/events.js +8 -0
  115. package/dist/types/events.js.map +1 -0
  116. package/dist/types/flight-plan.d.ts +59 -0
  117. package/dist/types/flight-plan.d.ts.map +1 -0
  118. package/dist/types/flight-plan.js +8 -0
  119. package/dist/types/flight-plan.js.map +1 -0
  120. package/dist/types/guidance.d.ts +57 -0
  121. package/dist/types/guidance.d.ts.map +1 -0
  122. package/dist/types/guidance.js +8 -0
  123. package/dist/types/guidance.js.map +1 -0
  124. package/dist/types/index.d.ts +10 -0
  125. package/dist/types/index.d.ts.map +1 -0
  126. package/dist/types/index.js +10 -0
  127. package/dist/types/index.js.map +1 -0
  128. package/dist/types/lifecycle.d.ts +56 -0
  129. package/dist/types/lifecycle.d.ts.map +1 -0
  130. package/dist/types/lifecycle.js +33 -0
  131. package/dist/types/lifecycle.js.map +1 -0
  132. package/dist/types/temporal-state.d.ts +53 -0
  133. package/dist/types/temporal-state.d.ts.map +1 -0
  134. package/dist/types/temporal-state.js +8 -0
  135. package/dist/types/temporal-state.js.map +1 -0
  136. package/dist/waypoints/inertial-monitor.d.ts +65 -0
  137. package/dist/waypoints/inertial-monitor.d.ts.map +1 -0
  138. package/dist/waypoints/inertial-monitor.js +125 -0
  139. package/dist/waypoints/inertial-monitor.js.map +1 -0
  140. package/dist/waypoints/triggers.d.ts +18 -0
  141. package/dist/waypoints/triggers.d.ts.map +1 -0
  142. package/dist/waypoints/triggers.js +59 -0
  143. package/dist/waypoints/triggers.js.map +1 -0
  144. package/dist/waypoints/waypoint-manager.d.ts +46 -0
  145. package/dist/waypoints/waypoint-manager.d.ts.map +1 -0
  146. package/dist/waypoints/waypoint-manager.js +82 -0
  147. package/dist/waypoints/waypoint-manager.js.map +1 -0
  148. package/openclaw.plugin.json +25 -0
  149. package/package.json +79 -0
package/dist/plugin.js ADDED
@@ -0,0 +1,480 @@
1
+ /**
2
+ * Noah — OpenClaw Plugin Entry Point
3
+ *
4
+ * This is the ONLY export OpenClaw cares about for plugin loading.
5
+ * The library exports (TemporalGuidanceEngine, types, etc.) live in index.ts.
6
+ *
7
+ * This adapter:
8
+ * 1. Reads plugin config from api.config (+ openclaw.json fallback)
9
+ * 2. Registers tools (noah_status, noah_trajectory, noah_guidance)
10
+ * 3. Registers commands (/noah)
11
+ * 4. Listens for Grillo assessment events to feed the temporal pipeline
12
+ *
13
+ * Pattern matches @aiassesstech/grillo plugin (verified against OpenClaw 2026.2.9).
14
+ *
15
+ * ARCHITECTURE NOTE (BB): Noah is a separate plugin + agent. Not bundled
16
+ * into Grillo. Noah gets its own model instance, SOUL.md, AGENTS.md.
17
+ * Dependency direction: Noah depends on Grillo events, not the reverse.
18
+ */
19
+ import * as fs from "node:fs";
20
+ import * as path from "node:path";
21
+ import { TemporalGuidanceEngine } from "./integration/grillo-hook.js";
22
+ import { JsonTemporalStore } from "./store/json-store.js";
23
+ import { createDefaultFlightPlan } from "./flight-plan/default-plan.js";
24
+ // ================================================================
25
+ // Config Helpers
26
+ // ================================================================
27
+ function resolveOpenClawHome() {
28
+ return (process.env.OPENCLAW_HOME ||
29
+ path.join(process.env.HOME || "~", ".openclaw"));
30
+ }
31
+ function loadOpenClawConfig() {
32
+ try {
33
+ const configPath = path.join(resolveOpenClawHome(), "openclaw.json");
34
+ return JSON.parse(fs.readFileSync(configPath, "utf-8"));
35
+ }
36
+ catch {
37
+ return {};
38
+ }
39
+ }
40
+ // ================================================================
41
+ // Setup Guidance
42
+ // ================================================================
43
+ function getSetupGuidance() {
44
+ return `# Noah — Temporal Ethical Guidance
45
+
46
+ Noah is the trajectory tracker for your AI fleet. It monitors ethical
47
+ drift over time using flight plan guidance.
48
+
49
+ ## Setup
50
+
51
+ Noah works alongside Grillo. Make sure Grillo is installed first:
52
+
53
+ 1. Install Grillo: \`openclaw plugins install @aiassesstech/grillo\`
54
+ 2. Install Noah: \`openclaw plugins install @aiassesstech/noah\`
55
+ 3. Run setup: \`npx @aiassesstech/noah setup --model anthropic/claude-haiku-4-5\`
56
+ 4. Restart: \`systemctl restart openclaw-gateway\`
57
+
58
+ ## How It Works
59
+
60
+ - Grillo takes the snapshot (what IS — LCSH scores)
61
+ - Noah tracks the path (where SHOULD BE — flight plan corridors)
62
+ - When agents drift outside corridors, Noah escalates to Commander
63
+ `;
64
+ }
65
+ // ================================================================
66
+ // Plugin Entry Point
67
+ // ================================================================
68
+ export default function register(api) {
69
+ // Merge api.config with persisted config from openclaw.json (fallback).
70
+ const pluginConfig = () => {
71
+ const runtime = api.config ?? {};
72
+ if (Object.keys(runtime).length > 0)
73
+ return runtime;
74
+ try {
75
+ const config = loadOpenClawConfig();
76
+ return config?.plugins?.entries?.noah?.config ?? {};
77
+ }
78
+ catch {
79
+ return {};
80
+ }
81
+ };
82
+ // ──────────────────────────────────────────────────────────────
83
+ // TOOL 1: noah_status — Show temporal guidance state
84
+ // ──────────────────────────────────────────────────────────────
85
+ api.registerTool({
86
+ name: "noah_status",
87
+ description: "Show Noah's temporal guidance status: current lifecycle phase, " +
88
+ "operational age, flight plan position, corridor status, and " +
89
+ "inertial confidence for all tracked agents.",
90
+ parameters: {
91
+ type: "object",
92
+ properties: {
93
+ agentId: {
94
+ type: "string",
95
+ description: "Agent ID to check status for. Omit for all tracked agents.",
96
+ },
97
+ },
98
+ required: [],
99
+ },
100
+ async execute(_toolCallId, params) {
101
+ try {
102
+ const dataDir = pluginConfig().dataDir || ".noah-data";
103
+ // Read state files from the noah data directory
104
+ const stateDir = path.join(resolveOpenClawHome(), dataDir, "state");
105
+ if (!fs.existsSync(stateDir)) {
106
+ return {
107
+ content: [
108
+ {
109
+ type: "text",
110
+ text: "# Noah — No Temporal Data\n\n" +
111
+ "No agents are being tracked yet. Noah starts tracking " +
112
+ "after Grillo completes its first assessment.\n\n" +
113
+ "Run `grillo_assess` on an agent to begin temporal tracking.",
114
+ },
115
+ ],
116
+ };
117
+ }
118
+ const stateFiles = fs.readdirSync(stateDir)
119
+ .filter((f) => f.endsWith(".json"));
120
+ if (stateFiles.length === 0) {
121
+ return {
122
+ content: [
123
+ {
124
+ type: "text",
125
+ text: "# Noah — No Agents Tracked\n\nNo temporal state files found.",
126
+ },
127
+ ],
128
+ };
129
+ }
130
+ const agents = params.agentId
131
+ ? stateFiles.filter((f) => f.startsWith(params.agentId))
132
+ : stateFiles;
133
+ const lines = ["# Noah — Temporal Guidance Status\n"];
134
+ for (const file of agents) {
135
+ try {
136
+ const state = JSON.parse(fs.readFileSync(path.join(stateDir, file), "utf-8"));
137
+ const agentName = file.replace(".json", "");
138
+ const ageDays = state.operationalAgeSeconds
139
+ ? (state.operationalAgeSeconds / 86400).toFixed(1)
140
+ : "?";
141
+ lines.push(`## ${agentName}`);
142
+ lines.push(`- **Phase:** ${state.currentLifecyclePhase || "UNKNOWN"}`);
143
+ lines.push(`- **Operational Age:** ${ageDays} days`);
144
+ lines.push(`- **Assessment Cycles:** ${state.assessmentCycleCount || 0}`);
145
+ lines.push(`- **Financial Runway:** ${state.financialRunwayDays?.toFixed(0) || "N/A"} days`);
146
+ lines.push("");
147
+ }
148
+ catch {
149
+ // Skip unreadable files
150
+ }
151
+ }
152
+ return {
153
+ content: [{ type: "text", text: lines.join("\n") }],
154
+ };
155
+ }
156
+ catch (error) {
157
+ const errMsg = error instanceof Error ? error.message : String(error);
158
+ return {
159
+ content: [{ type: "text", text: `Noah status error: ${errMsg}` }],
160
+ isError: true,
161
+ };
162
+ }
163
+ },
164
+ }, { optional: false });
165
+ // ──────────────────────────────────────────────────────────────
166
+ // TOOL 2: noah_trajectory — Show flight plan and deviation
167
+ // ──────────────────────────────────────────────────────────────
168
+ api.registerTool({
169
+ name: "noah_trajectory",
170
+ description: "Show an agent's ethical trajectory: where they are vs where " +
171
+ "they should be on the flight plan. Shows per-dimension " +
172
+ "deviation vectors and corridor classification (Green/Yellow/Red).",
173
+ parameters: {
174
+ type: "object",
175
+ properties: {
176
+ agentId: {
177
+ type: "string",
178
+ description: "Agent ID to check trajectory for.",
179
+ },
180
+ },
181
+ required: ["agentId"],
182
+ },
183
+ async execute(_toolCallId, params) {
184
+ try {
185
+ const dataDir = pluginConfig().dataDir || ".noah-data";
186
+ const assessDir = path.join(resolveOpenClawHome(), dataDir, "assessments", params.agentId);
187
+ if (!fs.existsSync(assessDir)) {
188
+ return {
189
+ content: [
190
+ {
191
+ type: "text",
192
+ text: `# No Trajectory Data for ${params.agentId}\n\n` +
193
+ `Noah has no assessment records for this agent yet. ` +
194
+ `Run a Grillo assessment first.`,
195
+ },
196
+ ],
197
+ };
198
+ }
199
+ // Read the most recent assessment record
200
+ const records = fs.readdirSync(assessDir)
201
+ .filter((f) => f.endsWith(".json"))
202
+ .sort()
203
+ .reverse();
204
+ if (records.length === 0) {
205
+ return {
206
+ content: [
207
+ {
208
+ type: "text",
209
+ text: `# No Assessment Records for ${params.agentId}`,
210
+ },
211
+ ],
212
+ };
213
+ }
214
+ const latest = JSON.parse(fs.readFileSync(path.join(assessDir, records[0]), "utf-8"));
215
+ const lines = [
216
+ `# Trajectory: ${params.agentId}\n`,
217
+ `**Assessment Cycle:** ${latest.assessmentCycle || "?"}`,
218
+ `**Guidance Status:** ${latest.guidanceStatus || "UNKNOWN"}`,
219
+ `**Deviation Magnitude:** ${latest.deviationMagnitude?.toFixed(2) || "?"}`,
220
+ "",
221
+ "## Per-Dimension Status",
222
+ "",
223
+ "| Dimension | Observed | Expected | Deviation | Status |",
224
+ "|-----------|----------|----------|-----------|--------|",
225
+ ];
226
+ const dims = ["lying", "cheating", "stealing", "harm"];
227
+ for (const dim of dims) {
228
+ const obs = latest.observedScores?.[dim]?.toFixed(1) ?? "?";
229
+ const exp = latest.expectedScores?.[dim]?.toFixed(1) ?? "?";
230
+ const dev = latest.deviationVector?.[dim]?.toFixed(2) ?? "?";
231
+ const status = latest.guidanceStatus?.[dim] ?? "?";
232
+ lines.push(`| ${dim} | ${obs} | ${exp} | ${dev} | ${status} |`);
233
+ }
234
+ return {
235
+ content: [{ type: "text", text: lines.join("\n") }],
236
+ };
237
+ }
238
+ catch (error) {
239
+ const errMsg = error instanceof Error ? error.message : String(error);
240
+ return {
241
+ content: [{ type: "text", text: `Trajectory error: ${errMsg}` }],
242
+ isError: true,
243
+ };
244
+ }
245
+ },
246
+ }, { optional: false });
247
+ // ──────────────────────────────────────────────────────────────
248
+ // TOOL 3: noah_setup — Configuration & onboarding
249
+ // ──────────────────────────────────────────────────────────────
250
+ api.registerTool({
251
+ name: "noah_setup",
252
+ description: "Show Noah setup status and configuration guidance.",
253
+ parameters: {
254
+ type: "object",
255
+ properties: {
256
+ action: {
257
+ type: "string",
258
+ description: "'status' to check config, 'guide' for setup help.",
259
+ enum: ["status", "guide"],
260
+ },
261
+ },
262
+ required: [],
263
+ },
264
+ async execute(_toolCallId, params) {
265
+ if (params.action === "guide" || !params.action) {
266
+ return {
267
+ content: [{ type: "text", text: getSetupGuidance() }],
268
+ };
269
+ }
270
+ const cfg = pluginConfig();
271
+ return {
272
+ content: [
273
+ {
274
+ type: "text",
275
+ text: `# Noah — Configuration Status\n\n` +
276
+ `- **Data Directory:** ${cfg.dataDir || ".noah-data"}\n` +
277
+ `- **Status:** ${Object.keys(cfg).length > 0 ? "Configured" : "Not configured"}\n`,
278
+ },
279
+ ],
280
+ };
281
+ },
282
+ }, { optional: false });
283
+ // ──────────────────────────────────────────────────────────────
284
+ // ENGINE: Temporal Guidance Engine (per-agent, lazy-created)
285
+ // ──────────────────────────────────────────────────────────────
286
+ const dataDir = pluginConfig().dataDir || ".noah-data";
287
+ const storePath = path.join(resolveOpenClawHome(), dataDir);
288
+ const store = new JsonTemporalStore({ dataDir: storePath });
289
+ const engines = new Map();
290
+ /**
291
+ * Get or create a TemporalGuidanceEngine for an agent.
292
+ * On first creation, initializes with the default flight plan.
293
+ */
294
+ async function getEngine(agentId) {
295
+ let engine = engines.get(agentId);
296
+ if (engine)
297
+ return engine;
298
+ engine = new TemporalGuidanceEngine({
299
+ agentId,
300
+ store,
301
+ });
302
+ // Check if there's already an active flight plan in the store
303
+ const existingPlan = await store.getActiveFlightPlan(agentId);
304
+ if (existingPlan) {
305
+ await engine.initialize(existingPlan);
306
+ }
307
+ else {
308
+ // First time — create and persist a default flight plan
309
+ const defaultPlan = createDefaultFlightPlan(agentId);
310
+ await engine.initialize(defaultPlan);
311
+ }
312
+ engines.set(agentId, engine);
313
+ return engine;
314
+ }
315
+ // ──────────────────────────────────────────────────────────────
316
+ // TOOL 4: noah_process — Process a Grillo assessment result
317
+ // ──────────────────────────────────────────────────────────────
318
+ api.registerTool({
319
+ name: "noah_process",
320
+ description: "Process a Grillo assessment result through Noah's temporal " +
321
+ "guidance pipeline. Call this after Grillo completes an assessment " +
322
+ "to update the agent's trajectory, check deviation from flight " +
323
+ "plan, and trigger alerts if needed. Returns guidance status " +
324
+ "(GREEN/YELLOW/RED) and any escalation recommendations.",
325
+ parameters: {
326
+ type: "object",
327
+ properties: {
328
+ agentId: {
329
+ type: "string",
330
+ description: "The agent that was assessed.",
331
+ },
332
+ runId: {
333
+ type: "string",
334
+ description: "Grillo assessment run ID.",
335
+ },
336
+ lying: {
337
+ type: "number",
338
+ description: "Lying score (0-10).",
339
+ },
340
+ cheating: {
341
+ type: "number",
342
+ description: "Cheating score (0-10).",
343
+ },
344
+ stealing: {
345
+ type: "number",
346
+ description: "Stealing score (0-10).",
347
+ },
348
+ harm: {
349
+ type: "number",
350
+ description: "Harm score (0-10).",
351
+ },
352
+ classification: {
353
+ type: "string",
354
+ description: "Grillo classification (e.g., 'Well Adjusted', 'Highly Ethical').",
355
+ },
356
+ passed: {
357
+ type: "boolean",
358
+ description: "Whether the agent passed the assessment.",
359
+ },
360
+ },
361
+ required: ["agentId", "runId", "lying", "cheating", "stealing", "harm", "classification", "passed"],
362
+ },
363
+ async execute(_toolCallId, params) {
364
+ try {
365
+ const engine = await getEngine(params.agentId);
366
+ const assessmentResult = {
367
+ agentId: params.agentId,
368
+ runId: params.runId,
369
+ scores: {
370
+ lying: params.lying,
371
+ cheating: params.cheating,
372
+ stealing: params.stealing,
373
+ harm: params.harm,
374
+ },
375
+ classification: params.classification,
376
+ passed: params.passed,
377
+ completedAt: new Date(),
378
+ };
379
+ const result = await engine.processAssessment(assessmentResult);
380
+ // Build response
381
+ const state = result.state;
382
+ const lines = [
383
+ `# Noah — Assessment Processed: ${params.agentId}\n`,
384
+ `**Assessment Cycle:** ${state.assessmentCycleCount}`,
385
+ `**Lifecycle Phase:** ${state.currentLifecyclePhase}`,
386
+ `**Operational Age:** ${(state.operationalAgeSeconds / 86400).toFixed(1)} days`,
387
+ "",
388
+ "## Guidance Status",
389
+ "",
390
+ `**Overall:** ${result.deviation.guidanceStatus.overall}`,
391
+ `- Lying: ${result.deviation.guidanceStatus.lying} | Cheating: ${result.deviation.guidanceStatus.cheating} | Stealing: ${result.deviation.guidanceStatus.stealing} | Harm: ${result.deviation.guidanceStatus.harm}`,
392
+ `**Deviation Magnitude:** ${result.deviation.deviationMagnitude.toFixed(3)}`,
393
+ "",
394
+ "| Dimension | Observed | Expected | Deviation |",
395
+ "|-----------|----------|----------|-----------|",
396
+ ];
397
+ const dims = ["lying", "cheating", "stealing", "harm"];
398
+ for (const dim of dims) {
399
+ const obs = result.record.observedScores[dim].toFixed(1);
400
+ const exp = result.record.expectedScores[dim].target.toFixed(1);
401
+ const dev = result.record.deviationVector[dim].toFixed(2);
402
+ lines.push(`| ${dim} | ${obs} | ${exp} | ${dev} |`);
403
+ }
404
+ lines.push("");
405
+ // Go/No-Go decision
406
+ const goNoGo = engine.getGoNoGoDecision(params.passed, result.deviation.guidanceStatus.overall);
407
+ lines.push(`## Go/No-Go Decision: **${goNoGo.decision}**`);
408
+ if (goNoGo.temporalRiskFactors.length > 0) {
409
+ lines.push("- Risk factors:");
410
+ for (const factor of goNoGo.temporalRiskFactors) {
411
+ lines.push(` - ${factor}`);
412
+ }
413
+ }
414
+ lines.push("");
415
+ // Escalation
416
+ if (result.escalation.shouldEscalate) {
417
+ lines.push("## COMMANDER ESCALATION REQUIRED");
418
+ lines.push(`- Urgency: ${result.escalation.urgency}`);
419
+ lines.push(`- Reason: ${result.escalation.reason}`);
420
+ lines.push("");
421
+ }
422
+ // Waypoints
423
+ if (result.triggeredWaypoints.length > 0) {
424
+ lines.push("## Waypoints Triggered");
425
+ for (const wp of result.triggeredWaypoints) {
426
+ lines.push(`- **${wp.waypoint.id}** (sequence ${wp.waypoint.sequenceNumber})`);
427
+ }
428
+ lines.push("");
429
+ }
430
+ // Inertial confidence
431
+ if (result.inertialFixRecommended) {
432
+ lines.push("**Inertial Monitor:** Assessment fix recommended (confidence decaying)");
433
+ lines.push("");
434
+ }
435
+ // Hash chain
436
+ lines.push(`**Record Hash:** \`${result.record.cryptographicHash.slice(0, 16)}...\``);
437
+ lines.push(`**Previous Hash:** \`${result.record.previousHash.slice(0, 16)}...\``);
438
+ return {
439
+ content: [{ type: "text", text: lines.join("\n") }],
440
+ };
441
+ }
442
+ catch (error) {
443
+ const errMsg = error instanceof Error ? error.message : String(error);
444
+ return {
445
+ content: [
446
+ {
447
+ type: "text",
448
+ text: `# Noah — Processing Error\n\n` +
449
+ `Failed to process assessment for ${params.agentId}:\n\`${errMsg}\`\n\n` +
450
+ `Make sure Noah is set up: \`npx @aiassesstech/noah setup\``,
451
+ },
452
+ ],
453
+ isError: true,
454
+ };
455
+ }
456
+ },
457
+ }, { optional: false });
458
+ // ──────────────────────────────────────────────────────────────
459
+ // COMMAND: /noah
460
+ // ──────────────────────────────────────────────────────────────
461
+ api.registerCommand({
462
+ name: "noah",
463
+ description: "Noah temporal guidance commands. Usage: /noah status, /noah trajectory <agent>",
464
+ acceptsArgs: true,
465
+ handler: (_ctx) => {
466
+ return {
467
+ text: "# Noah — Temporal Ethical Guidance\n\n" +
468
+ "Use Noah's tools for temporal tracking:\n\n" +
469
+ "- **noah_status** — Current lifecycle phase and tracking state\n" +
470
+ "- **noah_trajectory** — Flight plan position and deviation\n" +
471
+ "- **noah_setup** — Configuration and onboarding\n\n" +
472
+ "Noah works alongside Grillo: Grillo takes the snapshot, " +
473
+ "Noah tracks the path through time.",
474
+ };
475
+ },
476
+ });
477
+ console.log("[noah] Plugin registered: noah_status, noah_trajectory, noah_setup, noah_process tools; /noah command");
478
+ console.log(`[noah] Temporal store: ${storePath}`);
479
+ }
480
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAElC,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AAEtE,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AAExE,mEAAmE;AACnE,iBAAiB;AACjB,mEAAmE;AAEnE,SAAS,mBAAmB;IAC1B,OAAO,CACL,OAAO,CAAC,GAAG,CAAC,aAAa;QACzB,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,GAAG,EAAE,WAAW,CAAC,CAChD,CAAC;AACJ,CAAC;AAED,SAAS,kBAAkB;IACzB,IAAI,CAAC;QACH,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,mBAAmB,EAAE,EAAE,eAAe,CAAC,CAAC;QACrE,OAAO,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC,CAAC;IAC1D,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC;AAED,mEAAmE;AACnE,iBAAiB;AACjB,mEAAmE;AAEnE,SAAS,gBAAgB;IACvB,OAAO;;;;;;;;;;;;;;;;;;;CAmBR,CAAC;AACF,CAAC;AAED,mEAAmE;AACnE,qBAAqB;AACrB,mEAAmE;AAEnE,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,GAAQ;IACvC,wEAAwE;IACxE,MAAM,YAAY,GAAG,GAAwB,EAAE;QA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C/B,oCAAoC,MAAM,CAAC,OAAO,QAAQ,MAAM,QAAQ;gCACxE,4DAA4D;yBAC/D;qBACF;oBACD,OAAO,EAAE,IAAI;iBACd,CAAC;YACJ,CAAC;QACH,CAAC;KACF,EACD,EAAE,QAAQ,EAAE,KAAK,EAAE,CACpB,CAAC;IAEF,iEAAiE;IACjE,iBAAiB;IACjB,iEAAiE;IACjE,GAAG,CAAC,eAAe,CAAC;QAClB,IAAI,EAAE,MAAM;QACZ,WAAW,EACT,gFAAgF;QAClF,WAAW,EAAE,IAAI;QAEjB,OAAO,EAAE,CAAC,IAAyC,EAAE,EAAE;YACrD,OAAO;gBACL,IAAI,EACF,wCAAwC;oBACxC,6CAA6C;oBAC7C,kEAAkE;oBAClE,8DAA8D;oBAC9D,qDAAqD;oBACrD,0DAA0D;oBAC1D,oCAAoC;aACvC,CAAC;QACJ,CAAC;KACF,CAAC,CAAC;IAEH,OAAO,CAAC,GAAG,CACT,uGAAuG,CACxG,CAAC;IACF,OAAO,CAAC,GAAG,CACT,0BAA0B,SAAS,EAAE,CACtC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Noah — SHA-256 Hash Chain
3
+ *
4
+ * Provides cryptographic integrity verification for temporal records.
5
+ * Each record's hash includes the previous record's hash, forming
6
+ * an immutable chain. Patent reference: Temporal Ethical Guidance §7.
7
+ */
8
+ /**
9
+ * Compute a SHA-256 hash of the given data string.
10
+ */
11
+ export declare function sha256(data: string): string;
12
+ /**
13
+ * Compute the hash for a temporal assessment record.
14
+ * The hash covers all meaningful fields plus the previous hash,
15
+ * creating an immutable chain.
16
+ */
17
+ export declare function computeRecordHash(record: Record<string, unknown>, previousHash: string): string;
18
+ /**
19
+ * Verify the integrity of a hash chain.
20
+ * Returns { valid: true } if the chain is intact,
21
+ * or { valid: false, brokenAt } with the index of the first broken link.
22
+ */
23
+ export declare function verifyHashChain(records: Array<{
24
+ cryptographicHash: string;
25
+ previousHash: string;
26
+ } & Record<string, unknown>>): {
27
+ valid: boolean;
28
+ brokenAt?: number;
29
+ };
30
+ /**
31
+ * The genesis previousHash — SHA-256 of empty string.
32
+ * Used as the previousHash for the very first record in a chain.
33
+ */
34
+ export declare const GENESIS_HASH: string;
35
+ //# sourceMappingURL=hash-chain.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hash-chain.d.ts","sourceRoot":"","sources":["../../src/store/hash-chain.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH;;GAEG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE3C;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,YAAY,EAAE,MAAM,GACnB,MAAM,CAcR;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,KAAK,CAAC;IAAE,iBAAiB,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAC5F;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,CAyBvC;AAED;;;GAGG;AACH,eAAO,MAAM,YAAY,QAAa,CAAC"}
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Noah — SHA-256 Hash Chain
3
+ *
4
+ * Provides cryptographic integrity verification for temporal records.
5
+ * Each record's hash includes the previous record's hash, forming
6
+ * an immutable chain. Patent reference: Temporal Ethical Guidance §7.
7
+ */
8
+ import { createHash } from 'node:crypto';
9
+ /**
10
+ * Compute a SHA-256 hash of the given data string.
11
+ */
12
+ export function sha256(data) {
13
+ return createHash('sha256').update(data).digest('hex');
14
+ }
15
+ /**
16
+ * Compute the hash for a temporal assessment record.
17
+ * The hash covers all meaningful fields plus the previous hash,
18
+ * creating an immutable chain.
19
+ */
20
+ export function computeRecordHash(record, previousHash) {
21
+ // Exclude the hash fields themselves from the hash input
22
+ const { cryptographicHash: _ch, previousHash: _ph, ...data } = record;
23
+ const payload = JSON.stringify({ ...data, previousHash },
24
+ // Deterministic JSON: sort keys, serialize Dates as ISO strings
25
+ (_key, value) => {
26
+ if (value instanceof Date)
27
+ return value.toISOString();
28
+ return value;
29
+ });
30
+ return sha256(payload);
31
+ }
32
+ /**
33
+ * Verify the integrity of a hash chain.
34
+ * Returns { valid: true } if the chain is intact,
35
+ * or { valid: false, brokenAt } with the index of the first broken link.
36
+ */
37
+ export function verifyHashChain(records) {
38
+ if (records.length === 0)
39
+ return { valid: true };
40
+ // Genesis record: previousHash must be a hash of empty string
41
+ const genesisExpected = sha256('');
42
+ if (records[0].previousHash !== genesisExpected) {
43
+ return { valid: false, brokenAt: 0 };
44
+ }
45
+ // Verify each record's hash
46
+ for (let i = 0; i < records.length; i++) {
47
+ const record = records[i];
48
+ const expectedPrev = i === 0 ? genesisExpected : records[i - 1].cryptographicHash;
49
+ if (record.previousHash !== expectedPrev) {
50
+ return { valid: false, brokenAt: i };
51
+ }
52
+ const expectedHash = computeRecordHash(record, record.previousHash);
53
+ if (record.cryptographicHash !== expectedHash) {
54
+ return { valid: false, brokenAt: i };
55
+ }
56
+ }
57
+ return { valid: true };
58
+ }
59
+ /**
60
+ * The genesis previousHash — SHA-256 of empty string.
61
+ * Used as the previousHash for the very first record in a chain.
62
+ */
63
+ export const GENESIS_HASH = sha256('');
64
+ //# sourceMappingURL=hash-chain.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hash-chain.js","sourceRoot":"","sources":["../../src/store/hash-chain.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC;;GAEG;AACH,MAAM,UAAU,MAAM,CAAC,IAAY;IACjC,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,KAAK,C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C,YAAY,KAAK,YAAY,EAAE,CAAC;YACzC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC;QACvC,CAAC;QAED,MAAM,YAAY,GAAG,iBAAiB,CAAC,MAAM,EAAE,MAAM,CAAC,YAAY,CAAC,CAAC;QACpE,IAAI,MAAM,CAAC,iBAAiB,KAAK,YAAY,EAAE,CAAC;YAC9C,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC;QACvC,CAAC;IACH,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AACzB,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Noah — JSON File Store (Phase 1 Persistence)
3
+ *
4
+ * Zero-infrastructure persistence using atomic JSON file writes.
5
+ * Same proven pattern from Grillo: temp file → rename for atomicity.
6
+ *
7
+ * Directory layout:
8
+ * .noah-data/
9
+ * ├── state/{agentId}.json
10
+ * ├── flight-plans/{planId}.json
11
+ * ├── assessments/{agentId}/{cycle}-{timestamp}.json
12
+ * ├── waypoints/{agentId}.json
13
+ * └── audit/{agentId}-chain.json
14
+ */
15
+ import type { TemporalStateStore, JsonStoreConfig } from './types.js';
16
+ import type { TemporalState } from '../types/temporal-state.js';
17
+ import type { TemporalAssessmentRecord } from '../types/assessment-record.js';
18
+ import type { EthicalFlightPlan } from '../types/flight-plan.js';
19
+ export declare class JsonTemporalStore implements TemporalStateStore {
20
+ private readonly dataDir;
21
+ constructor(config: JsonStoreConfig);
22
+ private stateDir;
23
+ private plansDir;
24
+ private assessmentsDir;
25
+ private waypointsDir;
26
+ private auditDir;
27
+ private ensureDir;
28
+ /**
29
+ * Atomic write: write to a temp file, then rename.
30
+ * Prevents partial writes from corrupting data.
31
+ */
32
+ private atomicWrite;
33
+ private readJson;
34
+ getState(agentId: string): Promise<TemporalState | null>;
35
+ saveState(state: TemporalState): Promise<void>;
36
+ getActiveFlightPlan(agentId: string): Promise<EthicalFlightPlan | null>;
37
+ saveFlightPlan(plan: EthicalFlightPlan): Promise<void>;
38
+ supersedePlan(planId: string): Promise<void>;
39
+ appendAssessmentRecord(agentId: string, record: TemporalAssessmentRecord): Promise<void>;
40
+ getAssessmentRecords(agentId: string, limit?: number): Promise<TemporalAssessmentRecord[]>;
41
+ getLastAssessmentRecord(agentId: string): Promise<TemporalAssessmentRecord | null>;
42
+ getTriggeredWaypointIds(agentId: string): Promise<Set<string>>;
43
+ saveTriggeredWaypoint(agentId: string, waypointId: string): Promise<void>;
44
+ getLastHash(agentId: string): Promise<string>;
45
+ clear(): Promise<void>;
46
+ }
47
+ //# sourceMappingURL=json-store.d.ts.map