brainclaw 0.19.6 → 0.19.7

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.
@@ -1,10 +1,11 @@
1
1
  import fs from 'node:fs';
2
2
  import path from 'node:path';
3
3
  import { ConstraintSchema, DecisionSchema, TrapSchema, HandoffSchema, PlanItemSchema } from './schema.js';
4
- import { ensureMemoryDir, resolveEntityDir } from './io.js';
4
+ import { ensureMemoryDir, memoryPath, resolveEntityDir, withStoreLock, writeFileAtomic } from './io.js';
5
5
  import { commitMemoryChange } from './memory-git.js';
6
6
  import { appendEvent } from './event-log.js';
7
7
  import { loadVersionedJsonFile, saveVersionedJsonFile } from './migration.js';
8
+ import { generateMarkdown } from './markdown.js';
8
9
  export function emptyState() {
9
10
  return {
10
11
  version: 1,
@@ -69,15 +70,31 @@ function syncDirectory(dirPath, items, documentType) {
69
70
  }
70
71
  }
71
72
  export function saveState(state, cwd) {
73
+ persistState(state, cwd, { writeProjectMarkdown: false });
74
+ }
75
+ function writeStateDirectories(state, cwd) {
72
76
  ensureMemoryDir(cwd);
73
77
  const effectiveCwd = cwd ?? process.cwd();
74
- // Write to entity-aligned directories
75
78
  syncDirectory(resolveEntityDir('constraints', effectiveCwd, 'write'), state.active_constraints, 'constraint');
76
79
  syncDirectory(resolveEntityDir('decisions', effectiveCwd, 'write'), state.recent_decisions, 'decision');
77
80
  syncDirectory(resolveEntityDir('traps', effectiveCwd, 'write'), state.known_traps, 'trap');
78
81
  syncDirectory(resolveEntityDir('handoffs', effectiveCwd, 'write'), state.open_handoffs, 'handoff');
79
82
  syncDirectory(resolveEntityDir('plans', effectiveCwd, 'write'), state.plan_items, 'plan');
80
- appendEvent({ action: 'update', item_type: 'state', agent: 'system' }, cwd);
81
- commitMemoryChange('state update', cwd);
83
+ }
84
+ export function persistState(state, cwd, options = {}) {
85
+ const effectiveCwd = cwd ?? process.cwd();
86
+ withStoreLock(effectiveCwd, () => {
87
+ writeStateDirectories(state, effectiveCwd);
88
+ if (options.writeProjectMarkdown ?? true) {
89
+ writeFileAtomic(memoryPath('project.md', effectiveCwd), generateMarkdown(state, effectiveCwd));
90
+ }
91
+ appendEvent({
92
+ action: options.eventAction ?? 'update',
93
+ item_type: 'state',
94
+ agent: 'system',
95
+ summary: options.eventSummary,
96
+ }, effectiveCwd);
97
+ commitMemoryChange(options.commitMessage ?? 'state update', effectiveCwd);
98
+ });
82
99
  }
83
100
  //# sourceMappingURL=state.js.map
package/package.json CHANGED
@@ -1,19 +1,18 @@
1
1
  {
2
2
  "name": "brainclaw",
3
- "version": "0.19.6",
3
+ "version": "0.19.7",
4
4
  "description": "Shared project memory for humans and coding agents.",
5
5
  "type": "module",
6
6
  "bin": {
7
7
  "brainclaw": "dist/cli.js",
8
8
  "bclaw": "dist/cli.js"
9
9
  },
10
- "files": [
11
- "dist/**/*.js",
12
- "docs/**/*.md",
13
- "!docs/plan.md",
14
- "README.md",
15
- "LICENSE"
16
- ],
10
+ "files": [
11
+ "dist/**/*.js",
12
+ "docs/**/*.md",
13
+ "README.md",
14
+ "LICENSE"
15
+ ],
17
16
  "scripts": {
18
17
  "build": "tsc",
19
18
  "dev": "tsc && node dist/cli.js",