hafez 1.3.0 → 1.4.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/README.md CHANGED
@@ -18,10 +18,12 @@ Claude Code (or any agent with shell access):
18
18
  ```text
19
19
  Set up Hafez, an agent-native knowledge vault (github.com/shrvn-r/hafez):
20
20
 
21
- 1. Install the CLI (needs Node.js 22+ and git): npm install -g hafez
22
- On npm 11+, append --allow-scripts=better-sqlite3 (npm 11 blocks install
23
- scripts by default; the SQLite bindings need theirs, and the install
24
- reports success even when they were skipped).
21
+ 1. Install the CLI (needs Node.js 22+ and git):
22
+ npm install -g hafez --allow-scripts=better-sqlite3
23
+ Always include that flag: npm 11+ blocks install scripts by default, the
24
+ SQLite bindings need theirs, and the install reports success even when
25
+ they were skipped. npm majors predating the flag print
26
+ "npm warn Unknown cli config" and proceed.
25
27
  2. Check git identity is configured (git config user.name and user.email);
26
28
  if not, ask me for a name and email and set them with git config --global.
27
29
  3. Create my vault — a git repo with entities/ and knowledge/ directories and an
@@ -50,9 +52,10 @@ triggers compete for the same invocations.
50
52
  The same thing by hand:
51
53
 
52
54
  ```bash
53
- # Install (Node.js 22+ and git required).
54
- # On npm 11+, append: --allow-scripts=better-sqlite3
55
- npm install -g hafez
55
+ # Install (Node.js 22+ and git required). Always include the flag: npm 11+
56
+ # blocks install scripts by default and the SQLite bindings need theirs;
57
+ # older npm majors print "npm warn Unknown cli config" and proceed.
58
+ npm install -g hafez --allow-scripts=better-sqlite3
56
59
 
57
60
  # One-time, if you've never used git on this machine:
58
61
  # git config --global user.name "Your Name"
@@ -74,8 +77,63 @@ cp "$(npm root -g)/hafez/skill/SKILL.md" ~/.claude/skills/hafez/SKILL.md
74
77
  ```
75
78
 
76
79
  Prefer installing without the npm registry? The GitHub release tarball is the
77
- same artifact: `npm install -g https://github.com/shrvn-r/hafez/releases/latest/download/hafez.tgz`
78
- (npm 12+ additionally needs `--allow-remote=root`).
80
+ same artifact, running the same install scripts, so it takes the same flag —
81
+ plus `--allow-remote=root`, which npm 12+ requires for a remote URL:
82
+
83
+ ```bash
84
+ npm install -g https://github.com/shrvn-r/hafez/releases/latest/download/hafez.tgz --allow-scripts=better-sqlite3 --allow-remote=root
85
+ ```
86
+
87
+ ## Updating
88
+
89
+ Tell your agent: **update hafez**. Or paste: "Run `hafez upgrade` and follow
90
+ what it prints."
91
+
92
+ `hafez upgrade` checks and prints — it never installs. The steps it prints
93
+ install code and overwrite your agent instructions file, so **you** approve
94
+ them; don't let an agent run them unattended. Re-run `hafez upgrade`
95
+ afterwards to verify.
96
+
97
+ If `hafez upgrade` fails with `Unknown command:`, your installed hafez
98
+ predates the command — run the manual steps below once, then use it.
99
+
100
+ ### Updating by hand
101
+
102
+ ```bash
103
+ # 1. Install. Same flag rule as a fresh install; <version> is the version you
104
+ # are moving to (npm view hafez version).
105
+ npm install -g hafez@<version> --allow-scripts=better-sqlite3
106
+
107
+ # From the GitHub release tarball instead (npm 12+ needs --allow-remote):
108
+ npm install -g https://github.com/shrvn-r/hafez/releases/download/v<version>/hafez.tgz --allow-scripts=better-sqlite3 --allow-remote=root
109
+
110
+ # 2. Claude Code only: re-copy the bundled skill. It ships inside the package,
111
+ # so an upgraded package leaves the installed copy stale.
112
+ mkdir -p ~/.claude/skills/hafez
113
+ cp "$(npm root -g)/hafez/skill/SKILL.md" ~/.claude/skills/hafez/SKILL.md
114
+
115
+ # Under nvm, or for a symlinked dev install, `npm root -g` points at the
116
+ # wrong tree. Resolve it from the binary you actually run instead:
117
+ cp "$(dirname "$(dirname "$(readlink -f "$(which hafez)")")")/skill/SKILL.md" ~/.claude/skills/hafez/SKILL.md
118
+
119
+ # 3. Rebuild the read index. A schema bump invalidates it rather than
120
+ # rebuilding it, so the first query after an upgrade can answer empty.
121
+ hafez index rebuild
122
+ ```
123
+
124
+ The prose above always includes every install flag, because static text cannot
125
+ probe your npm — `hafez upgrade` does probe it and prints the exact form your
126
+ npm accepts. Same instruction, two renderings; the extra flags are harmless
127
+ (`npm warn Unknown cli config`, then it proceeds).
128
+
129
+ Also compare the Hafez block in your global agent instructions against the one
130
+ `hafez upgrade` prints, and reconcile any differences.
131
+
132
+ Your vault is untouched by an upgrade: the files, the git history, and the
133
+ registered vault path all survive. Only the read index is invalidated.
134
+
135
+ If any command reports unbuilt SQLite bindings, reinstall with
136
+ `--allow-scripts=better-sqlite3` — the CLI prints this itself when it happens.
79
137
 
80
138
  ## Quick start
81
139
 
@@ -0,0 +1,30 @@
1
+ import type { BatchOperation, BatchResult, CreateEntityFields, CreateKnowledgeFields, KnowledgeSubtype, UpdateFields } from './types.js';
2
+ export interface AppliedOp {
3
+ filesWritten: string[];
4
+ filesDeleted: string[];
5
+ result: BatchResult;
6
+ commitMessage: string;
7
+ indexRemovals: string[];
8
+ indexUpserts: Array<{
9
+ slug: string;
10
+ kind: 'entity' | 'knowledge';
11
+ }>;
12
+ matchedAction?: string;
13
+ }
14
+ /** Everything an apply arm needs from its caller: where the vault is, and how
15
+ * to hand the Spine a pre-write snapshot for rollback. Path resolution, the
16
+ * existence checks, and the local-day clock are ordinary imports — one adapter
17
+ * would only be a hypothetical seam. */
18
+ export interface ApplyContext {
19
+ vaultPath: string;
20
+ captureOriginal(path: string): void;
21
+ }
22
+ export declare function validateKindFields(kind: 'entity' | 'knowledge', fields: UpdateFields, subtype?: KnowledgeSubtype): void;
23
+ export declare function buildEntityFrontmatter(name: string, ef: CreateEntityFields, existsFn: (slug: string) => boolean): Record<string, any>;
24
+ export declare function buildKnowledgeFrontmatter(name: string, kf: CreateKnowledgeFields, existsFn: (slug: string) => boolean): Record<string, any>;
25
+ /** The single apply path for every mutation. Writes vault files but never
26
+ * touches git or SQLite: the Spine commits [...filesWritten, ...filesDeleted]
27
+ * under commitMessage (single ops) or one composed batch message, then runs
28
+ * the index updates. ctx.captureOriginal snapshots files for rollback before
29
+ * they change. */
30
+ export declare function applyOperation(op: BatchOperation, ctx: ApplyContext): AppliedOp;