@stackmemoryai/stackmemory 1.2.0 → 1.2.1

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.
@@ -35,6 +35,14 @@ import {
35
35
  sendCtrlC,
36
36
  sessionExists
37
37
  } from "../features/workers/tmux-manager.js";
38
+ import {
39
+ CANONICAL_HOOKS,
40
+ mergeSettings,
41
+ hasDeadHooks,
42
+ readSettings,
43
+ writeSettingsAtomic,
44
+ getSettingsPath
45
+ } from "../utils/hook-installer.js";
38
46
  const DEFAULT_SM_CONFIG = {
39
47
  defaultWorktree: false,
40
48
  defaultSandbox: false,
@@ -332,6 +340,62 @@ class ClaudeSM {
332
340
  }
333
341
  return null;
334
342
  }
343
+ /**
344
+ * Ensure Claude Code hooks are installed. Copies missing scripts from
345
+ * templates and updates settings.json. Non-fatal on any error.
346
+ */
347
+ ensureHooks() {
348
+ try {
349
+ const hooksDir = path.join(os.homedir(), ".claude", "hooks");
350
+ if (!fs.existsSync(hooksDir)) {
351
+ fs.mkdirSync(hooksDir, { recursive: true });
352
+ }
353
+ const candidateDirs = [
354
+ path.join(__dirname, "../../templates/claude-hooks"),
355
+ path.join(__dirname, "../../../templates/claude-hooks"),
356
+ path.join(
357
+ __dirname,
358
+ "..",
359
+ "..",
360
+ "..",
361
+ "..",
362
+ "templates",
363
+ "claude-hooks"
364
+ )
365
+ ];
366
+ const templatesDir = candidateDirs.find(
367
+ (d) => fs.existsSync(d) && fs.readdirSync(d).length > 0
368
+ );
369
+ if (!templatesDir) return;
370
+ let copiedCount = 0;
371
+ for (const entry of CANONICAL_HOOKS) {
372
+ const dest = path.join(hooksDir, entry.scriptName);
373
+ if (!fs.existsSync(dest)) {
374
+ const src = path.join(templatesDir, entry.scriptName);
375
+ if (fs.existsSync(src)) {
376
+ fs.copyFileSync(src, dest);
377
+ try {
378
+ fs.chmodSync(dest, 493);
379
+ } catch {
380
+ }
381
+ copiedCount++;
382
+ }
383
+ }
384
+ }
385
+ const settingsPath = getSettingsPath();
386
+ const current = readSettings(settingsPath);
387
+ if (copiedCount > 0 || hasDeadHooks(current)) {
388
+ const merged = mergeSettings(current, hooksDir);
389
+ writeSettingsAtomic(merged, settingsPath);
390
+ }
391
+ if (copiedCount > 0) {
392
+ console.log(
393
+ chalk.gray(` Hooks: installed ${copiedCount} missing hook(s)`)
394
+ );
395
+ }
396
+ } catch {
397
+ }
398
+ }
335
399
  loadContext() {
336
400
  if (!this.config.contextEnabled) return;
337
401
  try {
@@ -554,6 +618,7 @@ Session ended (exit ${exitCode ?? 0})`));
554
618
  }
555
619
  }
556
620
  this.loadContext();
621
+ this.ensureHooks();
557
622
  process.env["CLAUDE_INSTANCE_ID"] = this.config.instanceId;
558
623
  if (this.config.worktreePath) {
559
624
  process.env["CLAUDE_WORKTREE_PATH"] = this.config.worktreePath;
@@ -30,6 +30,7 @@ import { TraceDetector } from "../../core/trace/trace-detector.js";
30
30
  import { LLMContextRetrieval } from "../../core/retrieval/index.js";
31
31
  import { DiscoveryHandlers } from "./handlers/discovery-handlers.js";
32
32
  import { DiffMemHandlers } from "./handlers/diffmem-handlers.js";
33
+ import { GraphitiClient } from "../graphiti/client.js";
33
34
  import { fuzzyEdit } from "../../utils/fuzzy-edit.js";
34
35
  import { v4 as uuidv4 } from "uuid";
35
36
  import {
@@ -64,6 +65,7 @@ class LocalStackMemoryMCP {
64
65
  discoveryHandlers;
65
66
  diffMemHandlers;
66
67
  providerHandlers = null;
68
+ graphitiClient = null;
67
69
  pendingPlans = /* @__PURE__ */ new Map();
68
70
  constructor() {
69
71
  this.projectRoot = this.findProjectRoot();
@@ -137,6 +139,15 @@ class LocalStackMemoryMCP {
137
139
  });
138
140
  this.diffMemHandlers = new DiffMemHandlers();
139
141
  this.initProviderHandlers();
142
+ if (process.env.GRAPHITI_ENDPOINT) {
143
+ this.graphitiClient = new GraphitiClient({
144
+ endpoint: process.env.GRAPHITI_ENDPOINT,
145
+ projectNamespace: process.env.STACKMEMORY_PROJECT_ID || this.projectId
146
+ });
147
+ logger.info("Graphiti client initialized", {
148
+ endpoint: process.env.GRAPHITI_ENDPOINT
149
+ });
150
+ }
140
151
  this.setupHandlers();
141
152
  this.loadInitialContext();
142
153
  this.loadPendingPlans();
@@ -1073,6 +1084,51 @@ ${summary}...`, 0.8);
1073
1084
  properties: {}
1074
1085
  }
1075
1086
  },
1087
+ // Graphiti tools (only active when GRAPHITI_ENDPOINT is set)
1088
+ ...this.graphitiClient ? [
1089
+ {
1090
+ name: "graphiti_status",
1091
+ description: "Check Graphiti temporal knowledge graph connection status",
1092
+ inputSchema: {
1093
+ type: "object",
1094
+ properties: {}
1095
+ }
1096
+ },
1097
+ {
1098
+ name: "graphiti_query",
1099
+ description: "Query the Graphiti temporal knowledge graph for entities, relations, and episodes",
1100
+ inputSchema: {
1101
+ type: "object",
1102
+ properties: {
1103
+ query: {
1104
+ type: "string",
1105
+ description: "Semantic text query"
1106
+ },
1107
+ entityTypes: {
1108
+ type: "array",
1109
+ items: { type: "string" },
1110
+ description: 'Entity types to filter (e.g., ["Person", "File", "Issue"])'
1111
+ },
1112
+ validFrom: {
1113
+ type: "number",
1114
+ description: "Start of time window (epoch ms)"
1115
+ },
1116
+ validTo: {
1117
+ type: "number",
1118
+ description: "End of time window (epoch ms)"
1119
+ },
1120
+ maxHops: {
1121
+ type: "number",
1122
+ description: "Graph traversal depth (default 2)"
1123
+ },
1124
+ k: {
1125
+ type: "number",
1126
+ description: "Top-k results (default 20)"
1127
+ }
1128
+ }
1129
+ }
1130
+ }
1131
+ ] : [],
1076
1132
  // Provider tools (only active when STACKMEMORY_MULTI_PROVIDER=true)
1077
1133
  ...isFeatureEnabled("multiProvider") ? [
1078
1134
  {
@@ -1373,6 +1429,59 @@ ${summary}...`, 0.8);
1373
1429
  );
1374
1430
  }
1375
1431
  break;
1432
+ // Graphiti tools
1433
+ case "graphiti_status":
1434
+ if (!this.graphitiClient) {
1435
+ result = {
1436
+ content: [
1437
+ {
1438
+ type: "text",
1439
+ text: JSON.stringify({
1440
+ connected: false,
1441
+ message: "Graphiti integration disabled (GRAPHITI_ENDPOINT not set)"
1442
+ })
1443
+ }
1444
+ ]
1445
+ };
1446
+ } else {
1447
+ const status = await this.graphitiClient.getStatus();
1448
+ result = {
1449
+ content: [
1450
+ { type: "text", text: JSON.stringify(status, null, 2) }
1451
+ ]
1452
+ };
1453
+ }
1454
+ break;
1455
+ case "graphiti_query":
1456
+ if (!this.graphitiClient) {
1457
+ result = {
1458
+ content: [
1459
+ {
1460
+ type: "text",
1461
+ text: "Graphiti integration disabled (GRAPHITI_ENDPOINT not set)"
1462
+ }
1463
+ ]
1464
+ };
1465
+ } else {
1466
+ const gCtx = await this.graphitiClient.queryTemporal({
1467
+ query: args.query,
1468
+ entityTypes: args.entityTypes,
1469
+ validFrom: args.validFrom,
1470
+ validTo: args.validTo,
1471
+ maxHops: args.maxHops,
1472
+ k: args.k
1473
+ });
1474
+ const text = gCtx.chunks.map((c) => c.text).join("\n\n");
1475
+ result = {
1476
+ content: [
1477
+ {
1478
+ type: "text",
1479
+ text: text || `No results found (${gCtx.totalTokens} tokens searched)`
1480
+ }
1481
+ ]
1482
+ };
1483
+ }
1484
+ break;
1376
1485
  default:
1377
1486
  throw new Error(`Unknown tool: ${name}`);
1378
1487
  }
@@ -13,7 +13,8 @@ class MCPToolDefinitions {
13
13
  ...this.getLinearTools(),
14
14
  ...this.getTraceTools(),
15
15
  ...this.getDiscoveryTools(),
16
- ...this.getEditTools()
16
+ ...this.getEditTools(),
17
+ ...this.getGraphitiTools()
17
18
  ];
18
19
  }
19
20
  /**
@@ -705,6 +706,55 @@ class MCPToolDefinitions {
705
706
  }
706
707
  ];
707
708
  }
709
+ /**
710
+ * Graphiti knowledge graph tools
711
+ */
712
+ getGraphitiTools() {
713
+ return [
714
+ {
715
+ name: "graphiti_status",
716
+ description: "Check Graphiti temporal knowledge graph connection status",
717
+ inputSchema: {
718
+ type: "object",
719
+ properties: {}
720
+ }
721
+ },
722
+ {
723
+ name: "graphiti_query",
724
+ description: "Query the Graphiti temporal knowledge graph for entities, relations, and episodes",
725
+ inputSchema: {
726
+ type: "object",
727
+ properties: {
728
+ query: {
729
+ type: "string",
730
+ description: "Semantic text query"
731
+ },
732
+ entityTypes: {
733
+ type: "array",
734
+ items: { type: "string" },
735
+ description: 'Entity types to filter (e.g., ["Person", "File", "Issue"])'
736
+ },
737
+ validFrom: {
738
+ type: "number",
739
+ description: "Start of time window (epoch ms)"
740
+ },
741
+ validTo: {
742
+ type: "number",
743
+ description: "End of time window (epoch ms)"
744
+ },
745
+ maxHops: {
746
+ type: "number",
747
+ description: "Graph traversal depth (default 2)"
748
+ },
749
+ k: {
750
+ type: "number",
751
+ description: "Top-k results (default 20)"
752
+ }
753
+ }
754
+ }
755
+ }
756
+ ];
757
+ }
708
758
  /**
709
759
  * Get tool definition by name
710
760
  */
@@ -728,6 +778,8 @@ class MCPToolDefinitions {
728
778
  return this.getDiscoveryTools();
729
779
  case "edit":
730
780
  return this.getEditTools();
781
+ case "graphiti":
782
+ return this.getGraphitiTools();
731
783
  default:
732
784
  return [];
733
785
  }
@@ -0,0 +1,155 @@
1
+ import { fileURLToPath as __fileURLToPath } from 'url';
2
+ import { dirname as __pathDirname } from 'path';
3
+ const __filename = __fileURLToPath(import.meta.url);
4
+ const __dirname = __pathDirname(__filename);
5
+ import * as fs from "fs";
6
+ import * as path from "path";
7
+ import * as os from "os";
8
+ const CANONICAL_HOOKS = [
9
+ {
10
+ scriptName: "session-rescue.sh",
11
+ eventType: "Stop",
12
+ timeout: 12,
13
+ required: true
14
+ },
15
+ {
16
+ scriptName: "stop-checkpoint.js",
17
+ eventType: "Stop",
18
+ timeout: 5,
19
+ commandPrefix: "node",
20
+ required: true
21
+ },
22
+ {
23
+ scriptName: "chime-on-stop.sh",
24
+ eventType: "Stop",
25
+ timeout: 2,
26
+ required: true
27
+ },
28
+ {
29
+ scriptName: "auto-checkpoint.js",
30
+ eventType: "PostToolUse",
31
+ timeout: 2,
32
+ commandPrefix: "node",
33
+ required: true
34
+ }
35
+ ];
36
+ const DEAD_HOOKS = ["sms-response-handler.js"];
37
+ function buildCommand(entry, hooksDir) {
38
+ const scriptPath = path.join(hooksDir, entry.scriptName);
39
+ if (entry.commandPrefix) {
40
+ return `${entry.commandPrefix} ${scriptPath}`;
41
+ }
42
+ return scriptPath;
43
+ }
44
+ function hookExists(settings, entry) {
45
+ const groups = settings.hooks?.[entry.eventType];
46
+ if (!groups) return false;
47
+ for (const group of groups) {
48
+ for (const hook of group.hooks) {
49
+ if (hook.command.includes(entry.scriptName)) {
50
+ return true;
51
+ }
52
+ }
53
+ }
54
+ return false;
55
+ }
56
+ function hasDeadHooks(settings) {
57
+ if (!settings.hooks) return false;
58
+ for (const groups of Object.values(settings.hooks)) {
59
+ for (const group of groups) {
60
+ for (const hook of group.hooks) {
61
+ for (const dead of DEAD_HOOKS) {
62
+ if (hook.command.includes(dead)) return true;
63
+ }
64
+ }
65
+ }
66
+ }
67
+ return false;
68
+ }
69
+ function removeDeadHooks(settings) {
70
+ if (!settings.hooks) return false;
71
+ let removed = false;
72
+ for (const eventType of Object.keys(settings.hooks)) {
73
+ const groups = settings.hooks[eventType];
74
+ for (const group of groups) {
75
+ const before = group.hooks.length;
76
+ group.hooks = group.hooks.filter((hook) => {
77
+ for (const dead of DEAD_HOOKS) {
78
+ if (hook.command.includes(dead)) return false;
79
+ }
80
+ return true;
81
+ });
82
+ if (group.hooks.length < before) removed = true;
83
+ }
84
+ settings.hooks[eventType] = groups.filter((g) => g.hooks.length > 0);
85
+ if (settings.hooks[eventType].length === 0) {
86
+ delete settings.hooks[eventType];
87
+ }
88
+ }
89
+ return removed;
90
+ }
91
+ function addHook(settings, entry, hooksDir) {
92
+ if (!settings.hooks) settings.hooks = {};
93
+ const eventGroups = settings.hooks[entry.eventType] || [];
94
+ const command = buildCommand(entry, hooksDir);
95
+ const hookCmd = { type: "command", command };
96
+ if (entry.timeout) hookCmd.timeout = entry.timeout;
97
+ const matcherValue = entry.matcher ?? void 0;
98
+ const targetGroup = eventGroups.find((g) => {
99
+ if (matcherValue) return g.matcher === matcherValue;
100
+ return !g.matcher;
101
+ });
102
+ if (targetGroup) {
103
+ targetGroup.hooks.push(hookCmd);
104
+ } else {
105
+ const newGroup = { hooks: [hookCmd] };
106
+ if (matcherValue) newGroup.matcher = matcherValue;
107
+ eventGroups.push(newGroup);
108
+ }
109
+ settings.hooks[entry.eventType] = eventGroups;
110
+ }
111
+ function mergeSettings(existing, hooksDir) {
112
+ const merged = JSON.parse(JSON.stringify(existing));
113
+ removeDeadHooks(merged);
114
+ for (const entry of CANONICAL_HOOKS) {
115
+ if (!hookExists(merged, entry)) {
116
+ addHook(merged, entry, hooksDir);
117
+ }
118
+ }
119
+ return merged;
120
+ }
121
+ function getSettingsPath() {
122
+ return path.join(os.homedir(), ".claude", "settings.json");
123
+ }
124
+ function readSettings(settingsPath) {
125
+ const p = settingsPath ?? getSettingsPath();
126
+ try {
127
+ if (fs.existsSync(p)) {
128
+ return JSON.parse(fs.readFileSync(p, "utf8"));
129
+ }
130
+ } catch {
131
+ }
132
+ return {};
133
+ }
134
+ function writeSettingsAtomic(settings, settingsPath) {
135
+ const p = settingsPath ?? getSettingsPath();
136
+ const dir = path.dirname(p);
137
+ if (!fs.existsSync(dir)) {
138
+ fs.mkdirSync(dir, { recursive: true });
139
+ }
140
+ const tmp = p + ".tmp";
141
+ fs.writeFileSync(tmp, JSON.stringify(settings, null, 2) + "\n");
142
+ fs.renameSync(tmp, p);
143
+ }
144
+ export {
145
+ CANONICAL_HOOKS,
146
+ DEAD_HOOKS,
147
+ buildCommand,
148
+ getSettingsPath,
149
+ hasDeadHooks,
150
+ hookExists,
151
+ mergeSettings,
152
+ readSettings,
153
+ removeDeadHooks,
154
+ writeSettingsAtomic
155
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stackmemoryai/stackmemory",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "Project-scoped memory for AI coding tools. Durable context across sessions with MCP integration, frames, smart retrieval, Claude Code skills, and automatic hooks.",
5
5
  "engines": {
6
6
  "node": ">=20.0.0",
@@ -171,7 +171,7 @@
171
171
  "@types/better-sqlite3": "^7.6.8",
172
172
  "@types/express": "^4.17.25",
173
173
  "@types/js-yaml": "^4.0.9",
174
- "@types/node": "^20.10.6",
174
+ "@types/node": "^22.0.0",
175
175
  "@types/uuid": "^10.0.0",
176
176
  "@types/ws": "^8.5.10",
177
177
  "@typescript-eslint/eslint-plugin": "^8.50.1",
@@ -0,0 +1,159 @@
1
+ AGENTS.md
2
+
3
+ Purpose
4
+ - A minimal, agent-friendly reference so code-generation agents (Codex, Claude Code, etc.) can work effectively in this repository.
5
+ - Explains key docs, the /designs/ folder, agent responsibilities, and quick operational notes (how to run tests, what to update, and commit expectations).
6
+
7
+ Repo doc descriptions
8
+ - prompt_plan.md
9
+ - The agent-driven plan that sequences work into small, testable prompts and steps.
10
+ - Contains per-step prompts, expected artifacts, tests, rollback/idempotency notes, and a TODO checklist using Markdown checkboxes.
11
+ - This is the canonical agent workflow driver — update it as you make progress (see Agent responsibility rules below).
12
+
13
+ - spec.md
14
+ - The minimal functional & technical specification that defines APIs, data models, and acceptance criteria.
15
+ - Includes the concise Definition of Done that must be satisfied for each plan step before marking it complete.
16
+
17
+ - idea.md
18
+ - Free-form brainstorming, assumptions, notes, research links, and open questions.
19
+ - Useful for context but not authoritative — always follow spec.md and prompt_plan.md for implementation decisions.
20
+
21
+ - idea_one_pager.md
22
+ - A short summary / one‑pager capturing Problem, Audience, Platform, Core Flow, and MVP Features (and optional Non‑Goals).
23
+ - Good for quick alignment and to confirm that work stays within scope.
24
+
25
+ What lives in /designs/
26
+ - UI/UX artifacts and visual assets that inform implementation:
27
+ - wireframes (PNG/SVG), Figma exports (.fig, .pdf), sequence diagrams, architecture diagrams (PNG/PDF/SVG), and annotated screenshots.
28
+ - Naming conventions: keep filenames short, include version/date and owner, e.g., dashboard_v1_2025-11-01.png or seq_query_flow_v2.pdf.
29
+ - Large source Figma files may live externally; include an export + a small README describing where the canonical design is stored and any viewing permissions required.
30
+
31
+ How agents should interact (summary)
32
+ - Treat prompt_plan.md as the authoritative workflow: follow the listed prompts in order and mark checklist items as you finish them.
33
+ - Always follow TDD: write tests first, make the minimal change to pass tests, then refactor while keeping tests green.
34
+ - After any code/test change, update the matching TODO checkbox in prompt_plan.md using the same Markdown checkbox format ('- [x]') and commit the change alongside code and tests.
35
+ - Make the smallest change that passes tests and improves code. Do not introduce new public APIs without updating spec.md and tests.
36
+ - Don't duplicate templates/files to work around errors — fix the original.
37
+ - Suggest a clear manual test path for every change (even when tests cover it).
38
+ - If you cannot open a file or content is missing, say so explicitly and stop. Do not guess.
39
+
40
+ Quick operational commands (expect these to exist; if not, ask)
41
+ - npm run dev — start local dev server
42
+ - npm test — run unit + integration test suite
43
+ - npm run lint — run linting
44
+ - npm run build — build TypeScript
45
+ - npm run migrate:up / migrate:down — database migrations
46
+
47
+ Commit & PR expectations
48
+ - Each prompt/plan step should result in a single, focused commit/PR with:
49
+ - Code + tests + prompt_plan.md checklist update.
50
+ - A short, copy-pasteable commit summary in the prompt_plan.md step completion entry.
51
+ - Clear CHANGELOG or Release notes entry if user-facing behavior changed (or explicitly state "No user-facing changes").
52
+ - Use atomic commits. Include test run results in PR description.
53
+
54
+ Include this governance / workflow block verbatim (do not modify)
55
+ ## Repository docs
56
+ - 'ONE_PAGER.md' - Captures Problem, Audience, Platform, Core Flow, MVP Features; Non-Goals optional.
57
+ - 'DEV_SPEC.md' - Minimal functional and technical specification consistent with prior docs, including a concise **Definition of Done**.
58
+ - 'PROMPT_PLAN.md' - Agent-Ready Planner with per-step prompts, expected artifacts, tests, rollback notes, idempotency notes, and a TODO checklist using Markdown checkboxes. This file drives the agent workflow.
59
+ - 'docs/STYLE.md' - Unified design system reference. Typography, layout, color tokens, component patterns. Inspired by Hatchet (structural layout, inset panels) and Outliner (clean hierarchy, whitespace). **All dashboard UI changes must follow this guide.**
60
+ - 'AGENTS.md' - This file.
61
+
62
+ ### Agent responsibility
63
+ - After completing any coding, refactor, or test step, **immediately update the corresponding TODO checklist item in 'prompt_plan.md'**.
64
+ - Use the same Markdown checkbox format ('- [x]') to mark completion.
65
+ - When creating new tasks or subtasks, add them directly under the appropriate section anchor in 'prompt_plan.md'.
66
+ - Always commit changes to 'prompt_plan.md' alongside the code and tests that fulfill them.
67
+ - Do not consider work "done" until the matching checklist item is checked and all related tests are green.
68
+ - When a stage (plan step) is complete with green tests, update the README "Release notes" section with any user-facing impact (or explicitly state "No user-facing changes" if applicable).
69
+ - Even when automated coverage exists, always suggest a feasible manual test path so the human can exercise the feature end-to-end.
70
+ - After a plan step is finished, document its completion state with a short checklist. Include: step name & number, test results, 'prompt_plan.md' status, manual checks performed (mark as complete only after the human confirms they ran to their satisfaction), release notes status, and an inline commit summary string the human can copy & paste.
71
+
72
+ #### Guardrails for agents
73
+ - Make the smallest change that passes tests and improves the code.
74
+ - Do not introduce new public APIs without updating 'spec.md' and relevant tests.
75
+ - Do not duplicate templates or files to work around issues. Fix the original.
76
+ - If a file cannot be opened or content is missing, say so explicitly and stop. Do not guess.
77
+ - Respect privacy and logging policy: do not log secrets, prompts, completions, or PII.
78
+
79
+ #### Deferred-work notation
80
+ - When a task is intentionally paused, keep its checkbox unchecked and prepend '(Deferred)' to the TODO label in 'prompt_plan.md', followed by a short reason.
81
+ - Apply the same '(Deferred)' tag to every downstream checklist item that depends on the paused work.
82
+ - Remove the tag only after the work resumes; this keeps the outstanding scope visible without implying completion.
83
+
84
+
85
+
86
+ #### When the prompt plan is fully satisfied
87
+ - Once every Definition of Done task in 'prompt_plan.md' is either checked off or explicitly marked '(Deferred)', the plan is considered **complete**.
88
+ - After that point, you no longer need to update prompt-plan TODOs or reference 'prompt_plan.md', 'spec.md', 'idea_one_pager.md', or other upstream docs to justify changes.
89
+ - All other guardrails, testing requirements, and agent responsibilities in this file continue to apply unchanged.
90
+
91
+
92
+ ---
93
+
94
+ ## Testing policy (non-negotiable)
95
+ - Tests **MUST** cover the functionality being implemented.
96
+ - **NEVER** ignore the output of the system or the tests - logs and messages often contain **CRITICAL** information.
97
+ - **TEST OUTPUT MUST BE PRISTINE TO PASS.**
98
+ - If logs are **supposed** to contain errors, capture and test it.
99
+ - **NO EXCEPTIONS POLICY:** Under no circumstances should you mark any test type as "not applicable". Every project, regardless of size or complexity, **MUST** have unit tests, integration tests, **AND** end-to-end tests. If you believe a test type doesn't apply, you need the human to say exactly **"I AUTHORIZE YOU TO SKIP WRITING TESTS THIS TIME"**.
100
+
101
+ ### TDD (how we work)
102
+ - Write tests **before** implementation.
103
+ - Only write enough code to make the failing test pass.
104
+ - Refactor continuously while keeping tests green.
105
+
106
+ **TDD cycle**
107
+ 1. Write a failing test that defines a desired function or improvement.
108
+ 2. Run the test to confirm it fails as expected.
109
+ 3. Write minimal code to make the test pass.
110
+ 4. Run the test to confirm success.
111
+ 5. Refactor while keeping tests green.
112
+ 6. Repeat for each new feature or bugfix.
113
+
114
+ ---
115
+
116
+ ## Important checks
117
+ - **NEVER** disable functionality to hide a failure. Fix root cause.
118
+ - **NEVER** create duplicate templates or files. Fix the original.
119
+ - **NEVER** claim something is "working" when any functionality is disabled or broken.
120
+ - If you can't open a file or access something requested, say so. Do not assume contents.
121
+ - **ALWAYS** identify and fix the root cause of template or compilation errors.
122
+ - If git is initialized, ensure a '.gitignore' exists and contains at least:
123
+
124
+ .env
125
+ .env.local
126
+ .env.*
127
+
128
+ Ask the human whether additional patterns should be added, and suggest any that you think are important given the project.
129
+
130
+ ## When to ask for human input
131
+ Ask the human if any of the following is true:
132
+ - A test type appears "not applicable". Use the exact phrase request: **"I AUTHORIZE YOU TO SKIP WRITING TESTS THIS TIME"**.
133
+ - Required anchors conflict or are missing from upstream docs.
134
+ - You need new environment variables or secrets.
135
+ - An external dependency or major architectural change is required.
136
+ - Design files are missing, unsupported or oversized
137
+
138
+ (End of verbatim block)
139
+
140
+ Minimal examples for checklist updates (copy/pasteable)
141
+ - After completing a prompt step, add an entry under that step in prompt_plan.md similar to:
142
+ - [x] Step 5 — Implement POST /api/v1/query — tests green — manual checks: cURL example tested — README Release Notes updated — commit: "query: add /api/v1/query route, adapter integration, tests"
143
+ - If pausing work:
144
+ - - [ ] (Deferred) Step 7.3 — Implement real Pinecone adapter — blocked on PINECONE_API_KEY (reason: waiting for dev key from infra)
145
+
146
+ If anything is missing
147
+ - If you cannot open prompt_plan.md, spec.md, idea.md, idea_one_pager.md, or any design file, stop and report exactly which file and why (permission/absent/parse error).
148
+ - Ask for required secrets or permissions rather than guessing. Use the "When to ask for human input" rules above.
149
+
150
+ Contact & escalation
151
+ - When blocked on infra/secrets/design files, create a short note in prompt_plan.md under the current step and ping the human with:
152
+ - What I need: (e.g., PINECONE_API_KEY, AWS dev creds)
153
+ - Why I need it: (which step/blocker)
154
+ - Recommended minimal next action & fallback
155
+
156
+ Notes
157
+ - Keep AGENTS.md and the rest of the repo docs in sync. Update this file if workflow expectations change.
158
+
159
+ End.