@houserules/payload 0.1.1 → 0.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@houserules/payload",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "description": "houserules: shared payload libraries, copied into .claude/scripts/lib and executed on bare node with zero runtime dependencies.",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -1,3 +1,4 @@
1
+ import { type LedgerKind } from './ledger-index.mjs';
1
2
  export declare const SEPARATOR = "---";
2
3
  export declare const nowIso: () => string;
3
4
  export declare const todayDate: () => string;
@@ -39,10 +40,28 @@ export declare function ledgerPath(repoRoot: string, name: string, configuredDir
39
40
  * produces and a decision never does, since superseding leaves the entry rendered.
40
41
  */
41
42
  export declare function rebuildWouldDropEntries(file: string, nextContent: string, intentionallyDropped?: ReadonlySet<string>): boolean;
43
+ /** The local enable token a projects sync bootstrap writes into the ledger directory. */
44
+ export declare const PROJECTS_ENABLE_TOKEN = ".projects.json";
45
+ /**
46
+ * Whether the pulled index, rather than the queue, is the store this ledger's surfaces render
47
+ * from.
48
+ *
49
+ * Without a projects sync the queue is the only durable copy of an entry, so a surface holding
50
+ * entries the queue cannot account for means the queue was truncated and rewriting would
51
+ * destroy them. With a sync configured the model inverts: the queue jsonl drains to zero after
52
+ * a successful push, and the board is the durable store, pulled into the index. A fully synced
53
+ * repo therefore sits at zero queued entries with a rendered surface, which the queue
54
+ * comparison reads as corruption and refuses forever.
55
+ *
56
+ * The index has to be on disk for this. A repo that enabled the sync but has never pulled
57
+ * knows nothing about the board, so the queue comparison is still the only safe one there.
58
+ */
59
+ export declare function indexIsAuthoritative(ledgerDirectory: string, kind: LedgerKind): boolean;
42
60
  export declare function readSurface(file: string): string;
43
61
  /** Reads the body from the argument, or from stdin when it was omitted and stdin is a pipe. */
44
62
  export declare function readContentArg(content: string | undefined): string;
45
63
  export declare function relativeToRoot(repoRoot: string, p: string): string;
64
+ export declare const DEFAULT_LEDGER_DIR = ".claude/ledgers";
46
65
  /**
47
66
  * The ledger directory, from `ledgers.dir` or the default.
48
67
  *
@@ -3,6 +3,7 @@ import { appendFileSync, closeSync, existsSync, fstatSync, openSync, readFileSyn
3
3
  import { homedir } from 'node:os';
4
4
  import { dirname, relative, resolve } from 'node:path';
5
5
  import { ENTRY_HEAD } from './backlog-id.mjs';
6
+ import { loadIndex } from './ledger-index.mjs';
6
7
  export const SEPARATOR = '---';
7
8
  const TRANSCRIPT_TAIL_BYTES = 16384;
8
9
  const METADATA_LINE = /^\*\*([A-Za-z][A-Za-z ]*):\*\*\s+(.+)$/;
@@ -185,6 +186,27 @@ export function rebuildWouldDropEntries(file, nextContent, intentionallyDropped
185
186
  const after = new Set(parseEntries(nextContent).map((e) => e.id));
186
187
  return before.some((e) => !after.has(e.id) && !intentionallyDropped.has(e.id));
187
188
  }
189
+ /** The local enable token a projects sync bootstrap writes into the ledger directory. */
190
+ export const PROJECTS_ENABLE_TOKEN = '.projects.json';
191
+ /**
192
+ * Whether the pulled index, rather than the queue, is the store this ledger's surfaces render
193
+ * from.
194
+ *
195
+ * Without a projects sync the queue is the only durable copy of an entry, so a surface holding
196
+ * entries the queue cannot account for means the queue was truncated and rewriting would
197
+ * destroy them. With a sync configured the model inverts: the queue jsonl drains to zero after
198
+ * a successful push, and the board is the durable store, pulled into the index. A fully synced
199
+ * repo therefore sits at zero queued entries with a rendered surface, which the queue
200
+ * comparison reads as corruption and refuses forever.
201
+ *
202
+ * The index has to be on disk for this. A repo that enabled the sync but has never pulled
203
+ * knows nothing about the board, so the queue comparison is still the only safe one there.
204
+ */
205
+ export function indexIsAuthoritative(ledgerDirectory, kind) {
206
+ if (!existsSync(resolve(ledgerDirectory, PROJECTS_ENABLE_TOKEN)))
207
+ return false;
208
+ return loadIndex(ledgerDirectory, kind) !== null;
209
+ }
188
210
  export function readSurface(file) {
189
211
  return existsSync(file) ? readFileSync(file, 'utf8') : '';
190
212
  }
@@ -199,7 +221,7 @@ export function readContentArg(content) {
199
221
  export function relativeToRoot(repoRoot, p) {
200
222
  return relative(repoRoot, resolve(p));
201
223
  }
202
- const DEFAULT_LEDGER_DIR = '.claude/ledgers';
224
+ export const DEFAULT_LEDGER_DIR = '.claude/ledgers';
203
225
  /**
204
226
  * The ledger directory, from `ledgers.dir` or the default.
205
227
  *