hafez 1.2.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 +67 -9
- package/dist/apply.d.ts +30 -0
- package/dist/apply.js +582 -0
- package/dist/batch-ops.d.ts +470 -0
- package/dist/batch-ops.js +446 -0
- package/dist/cli/args.d.ts +19 -0
- package/dist/cli/args.js +53 -0
- package/dist/cli/batch-errors.js +6 -3
- package/dist/cli/commands.d.ts +24 -108
- package/dist/cli/commands.js +297 -313
- package/dist/cli/help-agent.d.ts +0 -5
- package/dist/cli/help-agent.js +44 -5
- package/dist/cli/index.d.ts +41 -0
- package/dist/cli/index.js +172 -172
- package/dist/cli/resolve-vault.js +2 -1
- package/dist/cli/schema-introspect.d.ts +1 -1
- package/dist/cli/schema-introspect.js +6 -22
- package/dist/cli/upgrade.d.ts +42 -0
- package/dist/cli/upgrade.js +305 -0
- package/dist/cli.js +0 -0
- package/dist/contracts.d.ts +55 -6
- package/dist/contracts.js +110 -23
- package/dist/dates.d.ts +10 -0
- package/dist/dates.js +27 -0
- package/dist/db.d.ts +27 -2
- package/dist/db.js +318 -56
- package/dist/digest.js +2 -0
- package/dist/document.d.ts +117 -0
- package/dist/document.js +578 -0
- package/dist/export-okf.js +48 -34
- package/dist/git.d.ts +7 -8
- package/dist/git.js +198 -63
- package/dist/index.d.ts +3 -4
- package/dist/index.js +302 -915
- package/dist/knowledge-index.d.ts +23 -1
- package/dist/knowledge-index.js +71 -13
- package/dist/merge.d.ts +1 -1
- package/dist/merge.js +106 -86
- package/dist/schema.js +4 -4
- package/dist/templates.d.ts +6 -0
- package/dist/templates.js +27 -27
- package/dist/types.d.ts +86 -12
- package/dist/vault.d.ts +51 -6
- package/dist/vault.js +114 -11
- package/package.json +2 -2
- package/skill/SKILL.md +51 -110
- package/dist/parser.d.ts +0 -18
- package/dist/parser.js +0 -68
- package/dist/query.d.ts +0 -24
- package/dist/query.js +0 -167
- package/dist/sections.d.ts +0 -54
- package/dist/sections.js +0 -297
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):
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
reports success even when
|
|
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
|
-
#
|
|
55
|
-
npm
|
|
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
|
|
78
|
-
|
|
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
|
|
package/dist/apply.d.ts
ADDED
|
@@ -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;
|