hafez 1.3.0 → 2.0.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 (75) hide show
  1. package/README.md +83 -32
  2. package/dist/apply.d.ts +33 -0
  3. package/dist/apply.js +693 -0
  4. package/dist/batch-ops.d.ts +372 -26
  5. package/dist/batch-ops.js +355 -73
  6. package/dist/cli/args.d.ts +48 -6
  7. package/dist/cli/args.js +74 -9
  8. package/dist/cli/batch-errors.js +19 -11
  9. package/dist/cli/block-hook.d.ts +9 -0
  10. package/dist/cli/block-hook.js +90 -0
  11. package/dist/cli/commands-schema.js +2 -0
  12. package/dist/cli/commands.d.ts +28 -3
  13. package/dist/cli/commands.js +440 -157
  14. package/dist/cli/format.d.ts +7 -3
  15. package/dist/cli/format.js +27 -10
  16. package/dist/cli/index.d.ts +55 -0
  17. package/dist/cli/index.js +215 -153
  18. package/dist/cli/install.d.ts +53 -0
  19. package/dist/cli/install.js +297 -0
  20. package/dist/cli/onboard.d.ts +15 -2
  21. package/dist/cli/onboard.js +265 -90
  22. package/dist/cli/resolve-vault.d.ts +11 -4
  23. package/dist/cli/resolve-vault.js +13 -11
  24. package/dist/cli/schema-introspect.js +4 -3
  25. package/dist/cli/upgrade.d.ts +51 -0
  26. package/dist/cli/upgrade.js +351 -0
  27. package/dist/closest.d.ts +8 -0
  28. package/dist/closest.js +65 -0
  29. package/dist/contracts.d.ts +65 -6
  30. package/dist/contracts.js +148 -23
  31. package/dist/dates.d.ts +10 -0
  32. package/dist/dates.js +27 -0
  33. package/dist/db.d.ts +40 -2
  34. package/dist/db.js +363 -66
  35. package/dist/digest.d.ts +6 -4
  36. package/dist/digest.js +28 -17
  37. package/dist/document.d.ts +135 -88
  38. package/dist/document.js +665 -379
  39. package/dist/export-okf.d.ts +13 -0
  40. package/dist/export-okf.js +50 -20
  41. package/dist/git.js +165 -48
  42. package/dist/harness.d.ts +58 -0
  43. package/dist/harness.js +50 -0
  44. package/dist/index.d.ts +2 -2
  45. package/dist/index.js +301 -826
  46. package/dist/knowledge-index.d.ts +23 -1
  47. package/dist/knowledge-index.js +62 -6
  48. package/dist/merge.d.ts +1 -1
  49. package/dist/merge.js +98 -64
  50. package/dist/near-match.d.ts +9 -0
  51. package/dist/near-match.js +34 -0
  52. package/dist/schema.js +4 -4
  53. package/dist/stale.d.ts +41 -0
  54. package/dist/stale.js +43 -0
  55. package/dist/stopwords.d.ts +6 -0
  56. package/dist/stopwords.js +25 -0
  57. package/dist/surfaces/items.d.ts +366 -0
  58. package/dist/surfaces/items.js +523 -0
  59. package/dist/surfaces/surfaces.d.ts +32 -0
  60. package/dist/surfaces/surfaces.js +230 -0
  61. package/dist/templates.d.ts +6 -0
  62. package/dist/templates.js +27 -27
  63. package/dist/types.d.ts +78 -22
  64. package/dist/validate.d.ts +7 -0
  65. package/dist/validate.js +109 -0
  66. package/dist/vault.d.ts +18 -0
  67. package/dist/vault.js +51 -5
  68. package/package.json +4 -3
  69. package/skill/hafez/SKILL.md +68 -0
  70. package/skill/hafez-save/SKILL.md +29 -0
  71. package/dist/cli/help-agent.d.ts +0 -1
  72. package/dist/cli/help-agent.js +0 -186
  73. package/dist/query.d.ts +0 -24
  74. package/dist/query.js +0 -169
  75. package/skill/SKILL.md +0 -196
@@ -0,0 +1,366 @@
1
+ import { type DocTarget, type WriteLineField } from '../contracts.js';
2
+ import { renderActionHandles } from '../document.js';
3
+ import type { ActionAge } from '../stale.js';
4
+ import type { KnowledgeSubtype, UpdateFields, UpdateResult } from '../types.js';
5
+ import { type OnboardHarness } from '../harness.js';
6
+ import type { Mode } from '../cli/install.js';
7
+ /** Every Surface the contract names. The static ones are composed in
8
+ * surfaces.ts; the binary ones are command output, rendered at run time. */
9
+ export type SurfaceId = 'block' | 'hafezSkillDescription' | 'hafezSkillBody' | 'hafezSaveDescription' | 'hafezSaveBody' | 'read' | 'readHeader' | 'readFooter' | 'readMiss' | 'updateSuccess' | 'updateMisuse' | 'createKnowledge' | 'digestError' | 'batchMisuse' | 'mechanised' | 'schema' | 'onboard';
10
+ /** Places another Item inside this one's text, counted against the same Surface. */
11
+ export type Place = (id: string) => string;
12
+ export interface Item {
13
+ /** The Item's row text in the owner table. */
14
+ label: string;
15
+ owner: SurfaceId;
16
+ /** A declared second placement, for agents whose Owner is absent. */
17
+ fallback?: SurfaceId;
18
+ /** The owner table's Invoke-only column. */
19
+ invokeOnly: string;
20
+ /** The audit row, field count or ticket that earns the Item its place. */
21
+ evidence: string;
22
+ /** Static text. A function form may place nested Items, and may give the
23
+ * fallback a shorter form than the Owner. */
24
+ text?: string | ((place: Place, at: 'owner' | 'fallback') => string);
25
+ /** What the binary computes: for Items owned by command output, and for a
26
+ * static Item a binary Surface places filled in (the create line in the
27
+ * `read` miss). */
28
+ render?: (input: never) => string;
29
+ }
30
+ /** An existing note a Near-match names. */
31
+ export interface NearMatchNote {
32
+ slug: string;
33
+ name: string;
34
+ description?: string | null;
35
+ subtype: KnowledgeSubtype;
36
+ }
37
+ /** An entity matching the working folder, as `onboard --block` names it. */
38
+ export interface FolderMatch {
39
+ slug: string;
40
+ description: string | null;
41
+ }
42
+ /** The three outputs of the Near-match Item: the `create knowledge` refusal
43
+ * (the message the error line carries), the relate line printed after a
44
+ * written note's slug, and `batch`'s warning line. */
45
+ export type NearMatchRender = {
46
+ form: 'refusal';
47
+ name: string;
48
+ /** The flags the create was given, in order: `[flag]` for a switch. */
49
+ flags: [flag: string, value?: string][];
50
+ /** The text passed as `--synthesis`, offered as evidence. */
51
+ evidence?: string;
52
+ matches: NearMatchNote[];
53
+ } | {
54
+ form: 'relate';
55
+ slug: string;
56
+ related: string[];
57
+ resembles: string[];
58
+ } | {
59
+ form: 'batchWarning';
60
+ index: number;
61
+ name: string;
62
+ matches: string[];
63
+ };
64
+ declare function renderNearMatch(input: NearMatchRender): string;
65
+ /** What a `read` Footer is rendered from: the file it ends. */
66
+ export interface FooterInput {
67
+ slug: string;
68
+ target: DocTarget;
69
+ /** The first open action's Handle; absent when no action is open. */
70
+ handle?: string;
71
+ /** Who the session log entry names: detected from the Harness. */
72
+ agent: string;
73
+ }
74
+ /** The Footer's op as the batch object carries it: what `read --json` puts
75
+ * under `writes`, and what the Write Line renders. */
76
+ export type FooterOp = {
77
+ op: 'update';
78
+ slug: string;
79
+ fields: Partial<Record<WriteLineField, unknown>>;
80
+ } | {
81
+ op: 'promote';
82
+ slug: string;
83
+ target: string;
84
+ };
85
+ export declare function footerOp(input: FooterInput): FooterOp;
86
+ /** The Footer: a blank line, a rule line, plain prose and one fenced block. */
87
+ declare function renderFooter(input: FooterInput): string;
88
+ /** `Updated <slug>: <what changed>.` — one phrase per change, nothing else. */
89
+ declare function renderUpdateSummary({ slug, fields, result }: {
90
+ slug: string;
91
+ fields: UpdateFields;
92
+ result: UpdateResult;
93
+ }): string;
94
+ /** The suffix a Stale open line carries on `read`: its age, or that it is
95
+ * undated. A fresh line carries none. */
96
+ declare function renderStaleMarker({ stale, age_days }: ActionAge): string;
97
+ /** The line after an update's success while Stale lines remain on the entity. */
98
+ declare function renderStaleReminder({ handles }: {
99
+ handles: string[];
100
+ }): string;
101
+ /** What a misuse retries from: the file's Footer, or the `read` miss when the
102
+ * slug names no file. */
103
+ export type MisuseRetry = {
104
+ footer: FooterInput;
105
+ } | {
106
+ miss: {
107
+ slug: string;
108
+ closest: string[];
109
+ };
110
+ };
111
+ /** The error line stating nothing was written, any detail lines, then the
112
+ * Footer (which brings its own blank line) or, after a blank line, the miss. */
113
+ declare function renderUpdateMisuse(input: {
114
+ error: string;
115
+ details?: string[];
116
+ } & MisuseRetry): string;
117
+ /** Step 3 of the onboard script: the exact entries that let `hafez` run and
118
+ * write the vault without a prompt. Claude Code runs it from an allow entry;
119
+ * Codex from a command rule, with the vault a writable root of the sandbox. */
120
+ declare function renderHarnessPermissions({ harness, vault }: {
121
+ harness: OnboardHarness;
122
+ vault: string;
123
+ }): string;
124
+ /** The four lines said to the user at hand-over, or line 2 alone. Line 1
125
+ * carries the save keystroke of the Harness `onboard` ran in; line 2 is the
126
+ * Mode. */
127
+ declare function renderTeachingLines({ harness, mode, line2Only }: {
128
+ harness: OnboardHarness;
129
+ mode: Mode;
130
+ line2Only?: boolean;
131
+ }): string;
132
+ export declare const ITEMS: {
133
+ loadTriggers: {
134
+ label: string;
135
+ owner: "block";
136
+ invokeOnly: string;
137
+ evidence: string;
138
+ text: string;
139
+ };
140
+ slugMissRecovery: {
141
+ label: string;
142
+ owner: "readMiss";
143
+ invokeOnly: string;
144
+ evidence: string;
145
+ render: ({ slug, closest }: {
146
+ slug: string;
147
+ closest: string[];
148
+ }) => string;
149
+ };
150
+ parentDescription: {
151
+ label: string;
152
+ owner: "readHeader";
153
+ invokeOnly: string;
154
+ evidence: string;
155
+ /** The `parent:` line's value: the slug, with the parent's description
156
+ * in brackets when it has one. */
157
+ render: ({ slug, description }: {
158
+ slug: string;
159
+ description: string | null;
160
+ }) => string;
161
+ };
162
+ writeTriggers: {
163
+ label: string;
164
+ owner: "block";
165
+ invokeOnly: string;
166
+ evidence: string;
167
+ text: (place: Place) => string;
168
+ };
169
+ knowledgeBoundary: {
170
+ label: string;
171
+ owner: "block";
172
+ invokeOnly: string;
173
+ evidence: string;
174
+ text: string;
175
+ };
176
+ neverAsk: {
177
+ label: string;
178
+ owner: "block";
179
+ fallback: "hafezSkillBody";
180
+ invokeOnly: string;
181
+ evidence: string;
182
+ text: (_place: Place, at: "owner" | "fallback") => string;
183
+ };
184
+ readBeforeWrite: {
185
+ label: string;
186
+ owner: "block";
187
+ fallback: "hafezSkillBody";
188
+ invokeOnly: string;
189
+ evidence: string;
190
+ text: string;
191
+ };
192
+ oneCommand: {
193
+ label: string;
194
+ owner: "block";
195
+ invokeOnly: string;
196
+ evidence: string;
197
+ text: string;
198
+ };
199
+ openActions: {
200
+ label: string;
201
+ owner: "block";
202
+ fallback: "hafezSkillBody";
203
+ invokeOnly: string;
204
+ evidence: string;
205
+ text: string;
206
+ };
207
+ neverEditByHand: {
208
+ label: string;
209
+ owner: "block";
210
+ invokeOnly: string;
211
+ evidence: string;
212
+ text: string;
213
+ };
214
+ neverSaveUnprompted: {
215
+ label: string;
216
+ owner: "block";
217
+ invokeOnly: string;
218
+ evidence: string;
219
+ text: string;
220
+ };
221
+ createLines: {
222
+ label: string;
223
+ owner: "block";
224
+ fallback: "hafezSkillBody";
225
+ invokeOnly: string;
226
+ evidence: string;
227
+ text: string;
228
+ /** The entity create line for one name: what the `read` miss places. */
229
+ render: (name: string) => string;
230
+ };
231
+ writeLine: {
232
+ label: string;
233
+ owner: "readFooter";
234
+ fallback: "updateMisuse";
235
+ invokeOnly: string;
236
+ evidence: string;
237
+ render: typeof renderFooter;
238
+ };
239
+ handles: {
240
+ label: string;
241
+ owner: "read";
242
+ invokeOnly: string;
243
+ evidence: string;
244
+ render: typeof renderActionHandles;
245
+ };
246
+ staleMarker: {
247
+ label: string;
248
+ owner: "read";
249
+ invokeOnly: string;
250
+ evidence: string;
251
+ render: typeof renderStaleMarker;
252
+ };
253
+ staleReminder: {
254
+ label: string;
255
+ owner: "updateSuccess";
256
+ invokeOnly: string;
257
+ evidence: string;
258
+ render: typeof renderStaleReminder;
259
+ };
260
+ updateSummary: {
261
+ label: string;
262
+ owner: "updateSuccess";
263
+ invokeOnly: string;
264
+ evidence: string;
265
+ render: typeof renderUpdateSummary;
266
+ };
267
+ updateMisuse: {
268
+ label: string;
269
+ owner: "updateMisuse";
270
+ invokeOnly: string;
271
+ evidence: string;
272
+ render: typeof renderUpdateMisuse;
273
+ };
274
+ sessionLogOnUpdate: {
275
+ label: string;
276
+ owner: "mechanised";
277
+ invokeOnly: string;
278
+ evidence: string;
279
+ };
280
+ nearMatch: {
281
+ label: string;
282
+ owner: "createKnowledge";
283
+ invokeOnly: string;
284
+ evidence: string;
285
+ render: typeof renderNearMatch;
286
+ };
287
+ saveTrigger: {
288
+ label: string;
289
+ owner: "hafezSaveDescription";
290
+ invokeOnly: string;
291
+ evidence: string;
292
+ text: string;
293
+ };
294
+ saveMechanics: {
295
+ label: string;
296
+ owner: "hafezSaveBody";
297
+ invokeOnly: string;
298
+ evidence: string;
299
+ text: string;
300
+ };
301
+ unknownSlugAtSave: {
302
+ label: string;
303
+ owner: "digestError";
304
+ invokeOnly: string;
305
+ evidence: string;
306
+ render: (slugs: readonly string[]) => string;
307
+ };
308
+ find: {
309
+ label: string;
310
+ owner: "hafezSkillBody";
311
+ invokeOnly: string;
312
+ evidence: string;
313
+ text: string;
314
+ };
315
+ rareOps: {
316
+ label: string;
317
+ owner: "hafezSkillBody";
318
+ invokeOnly: string;
319
+ evidence: string;
320
+ text: string;
321
+ };
322
+ batchShape: {
323
+ label: string;
324
+ owner: "hafezSkillBody";
325
+ fallback: "batchMisuse";
326
+ invokeOnly: string;
327
+ evidence: string;
328
+ text: (_place: Place, at: "owner" | "fallback") => string;
329
+ };
330
+ upgradeReconfigure: {
331
+ label: string;
332
+ owner: "hafezSkillBody";
333
+ invokeOnly: string;
334
+ evidence: string;
335
+ text: string;
336
+ };
337
+ opShape: {
338
+ label: string;
339
+ owner: "schema";
340
+ invokeOnly: string;
341
+ evidence: string;
342
+ };
343
+ folderMatch: {
344
+ label: string;
345
+ owner: "onboard";
346
+ invokeOnly: string;
347
+ evidence: string;
348
+ render: (matches: FolderMatch[]) => string;
349
+ };
350
+ harnessPermissions: {
351
+ label: string;
352
+ owner: "onboard";
353
+ invokeOnly: string;
354
+ evidence: string;
355
+ render: typeof renderHarnessPermissions;
356
+ };
357
+ teachingLines: {
358
+ label: string;
359
+ owner: "onboard";
360
+ invokeOnly: string;
361
+ evidence: string;
362
+ render: typeof renderTeachingLines;
363
+ };
364
+ };
365
+ export type ItemId = keyof typeof ITEMS;
366
+ export {};