counterparts 0.3.12 → 0.3.13
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/CHANGELOG.md +184 -0
- package/docs/module-map.md +1 -1
- package/package.json +1 -1
- package/src/adapters/claude-code/CONTRACT.md +36 -10
- package/src/adapters/claude-code/INTERFACE-GAPS.md +116 -16
- package/src/adapters/claude-code/NOTES.md +131 -0
- package/src/adapters/claude-code/bin/hook.ts +35 -2
- package/src/adapters/claude-code/doctor.ts +155 -21
- package/src/adapters/claude-code/hooks.ts +49 -7
- package/src/adapters/claude-code/index.ts +11 -0
- package/src/adapters/claude-code/night-run.ts +133 -12
- package/src/adapters/claude-code/transcript.ts +268 -1
- package/src/adapters/cli/CONTRACT.md +5 -0
- package/src/adapters/cli/INTERFACE-GAPS.md +8 -4
- package/src/adapters/cli/NOTES.md +111 -0
- package/src/adapters/cli/commands.ts +65 -14
- package/src/adapters/cli/dream-core.ts +57 -42
- package/src/adapters/cli/export.ts +320 -21
- package/src/adapters/cli/index.ts +1 -0
- package/src/adapters/cli/install.ts +39 -7
- package/src/adapters/cli/mechanisms.ts +7 -1
- package/src/adapters/cli/uninstall.ts +13 -5
- package/src/adapters/cli/wire.ts +189 -63
- package/src/adapters/dashboard/INTERFACE-GAPS.md +10 -1
- package/src/adapters/dashboard/NOTES.md +79 -0
- package/src/adapters/dashboard/registries.ts +10 -2
- package/src/adapters/dashboard/web/README.md +19 -14
- package/src/adapters/dashboard/web/actions.ts +23 -1
- package/src/adapters/dashboard/web/flow.ts +4 -1
- package/src/adapters/dashboard/web/lanes.ts +3 -0
- package/src/adapters/dashboard/web/narrate.ts +30 -2
- package/src/adapters/dashboard/web/pages/flow/sections/fired.js +1 -0
- package/src/adapters/dashboard/web/pages/memories/memories.css +17 -4
- package/src/adapters/dashboard/web/pages/memories/row.js +37 -21
- package/src/adapters/dashboard/web/pages/memories/sections/search.js +279 -60
- package/src/adapters/dashboard/web/pages/memories/state.js +2 -1
- package/src/adapters/dashboard/web/server.ts +0 -5
- package/src/adapters/dashboard/web/shared/memory-marks.css +7 -0
- package/src/adapters/dashboard/web/shared/memory-marks.js +33 -0
- package/src/adapters/dashboard/web/shared/memory-modal.js +5 -3
- package/src/adapters/dashboard/web/views/health.ts +1 -1
- package/src/adapters/dashboard/web/views/search.ts +4 -45
- package/src/adapters/dashboard/web/views.ts +2 -2
- package/src/adapters/fired.ts +410 -25
- package/src/adapters/host-wiring.ts +300 -0
- package/src/adapters/lifecycle.ts +14 -0
- package/src/adapters/log/index.ts +2 -0
- package/src/adapters/mcp/CONTRACT.md +33 -3
- package/src/adapters/mcp/INTERFACE-GAPS.md +24 -2
- package/src/adapters/mcp/NOTES.md +136 -0
- package/src/adapters/mcp/bin/serve.ts +30 -0
- package/src/adapters/mcp/facts.ts +13 -1
- package/src/adapters/mcp/meaning.ts +208 -13
- package/src/adapters/mcp/server.ts +87 -15
- package/src/adapters/mcp/stdio.ts +3 -1
- package/src/adapters/mcp/stood-down.ts +51 -0
- package/src/adapters/mcp/tools.ts +27 -7
- package/src/adapters/plugin-run.sh +133 -0
- package/src/adapters/plugin.ts +329 -0
- package/src/core/associate/CONTRACT.md +2 -1
- package/src/core/associate/INTERFACE-GAPS.md +6 -1
- package/src/core/associate/NOTES.md +45 -0
- package/src/core/briefing.ts +12 -3
- package/src/core/contradictions.ts +184 -0
- package/src/core/counterpart.ts +451 -18
- package/src/core/dream/CONTRACT.md +5 -2
- package/src/core/dream/INTERFACE-GAPS.md +29 -6
- package/src/core/dream/NOTES.md +21 -0
- package/src/core/dream/index.ts +33 -1
- package/src/core/dream/reflect.ts +20 -5
- package/src/core/encode/INTERFACE-GAPS.md +3 -1
- package/src/core/fit/INTERFACE-GAPS.md +8 -2
- package/src/core/fit/NOTES.md +5 -2
- package/src/core/fit/index.ts +4 -1
- package/src/core/handoff/CONTRACT.md +37 -2
- package/src/core/handoff/INTERFACE-GAPS.md +10 -0
- package/src/core/handoff/NOTES.md +66 -0
- package/src/core/handoff/index.ts +214 -12
- package/src/core/mint.ts +8 -2
- package/src/core/physics/CONTRACT.md +11 -1
- package/src/core/physics/NOTES.md +30 -0
- package/src/core/physics/index.ts +26 -4
- package/src/core/prospective/CONTRACT.md +45 -6
- package/src/core/prospective/INTERFACE-GAPS.md +4 -0
- package/src/core/prospective/NOTES.md +138 -0
- package/src/core/prospective/derive.ts +33 -5
- package/src/core/prospective/index.ts +90 -5
- package/src/core/prospective/windows.ts +72 -1
- package/src/core/recall/CONTRACT.md +6 -2
- package/src/core/recall/INTERFACE-GAPS.md +28 -4
- package/src/core/recall/NOTES.md +57 -1
- package/src/core/recall/probe.ts +58 -0
- package/src/core/recall/session.ts +27 -3
- package/src/core/recall/time-ask.ts +116 -18
- package/src/core/remember/CONTRACT.md +4 -1
- package/src/core/remember/INTERFACE-GAPS.md +9 -1
- package/src/core/remember/proposals.ts +38 -5
- package/src/core/revision.ts +5 -0
- package/src/core/schemas/CONTRACT.md +13 -1
- package/src/core/schemas/INTERFACE-GAPS.md +20 -2
- package/src/core/schemas/NOTES.md +127 -0
- package/src/core/schemas/types.ts +2 -0
- package/src/core/self/CONTRACT.md +15 -4
- package/src/core/self/INTERFACE-GAPS.md +7 -2
- package/src/core/self/NOTES.md +49 -0
- package/src/core/self/briefing.ts +12 -2
- package/src/core/self/index.ts +82 -8
- package/src/core/self/page.ts +88 -0
- package/src/core/sleep/INTERFACE-GAPS.md +22 -3
- package/src/core/sleep/NOTES.md +11 -0
- package/src/core/sleep/prune.ts +6 -2
- package/src/core/store/NOTES.md +14 -0
- package/src/core/store/index.ts +107 -0
- package/src/core/time.ts +152 -0
- package/tools/install-loop/run.sh +48 -12
- package/src/adapters/dashboard/web/pages/memories/fold.js +0 -53
package/src/core/sleep/prune.ts
CHANGED
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
|
|
25
25
|
import { pressureAt, pruneVerdict, supersededResolvable } from "../physics/index.js";
|
|
26
26
|
import type { MemoryPhysics, PruneReason } from "../physics/index.js";
|
|
27
|
+
import { recurrenceOfRow } from "../store/index.js";
|
|
27
28
|
import { rowToPhysics } from "../store/operational.js";
|
|
28
29
|
import { PRUNE_ARCHIVE_REASON, PRUNE_RECORD_PREFIX } from "./tunables.js";
|
|
29
30
|
import type { MemoryRow, PhaseCtx, PhaseOutcome, PrunedRecord } from "./types.js";
|
|
@@ -36,7 +37,7 @@ const PRUNE_PHASE: Phase = "prune";
|
|
|
36
37
|
|
|
37
38
|
export interface PruneResult extends PhaseOutcome {
|
|
38
39
|
readonly pruned: readonly PrunedRecord[];
|
|
39
|
-
/** Every blocking gate, counted — physics names all
|
|
40
|
+
/** Every blocking gate, counted — physics names all six, not just the first. */
|
|
40
41
|
readonly blocked: Readonly<Record<string, number>>;
|
|
41
42
|
/** Memories left in place because their record could not be written. */
|
|
42
43
|
readonly recordFailures: readonly { id: string; error: string }[];
|
|
@@ -131,9 +132,12 @@ export function runPrune(ctx: PhaseCtx): PruneResult {
|
|
|
131
132
|
const p = rowToPhysics(row);
|
|
132
133
|
const verdict = pruneVerdict(p, day, {
|
|
133
134
|
inLiveRevisionChain: inLiveRevisionChain(store, id, row, p, day),
|
|
135
|
+
// A reminder date that still repeats (2026-10-09): physics refuses it by
|
|
136
|
+
// name. The meta is the row's, read here because physics cannot see it.
|
|
137
|
+
recurring: recurrenceOfRow(row) !== null,
|
|
134
138
|
});
|
|
135
139
|
if (!verdict.prune || verdict.record === null) {
|
|
136
|
-
// EVERY failing gate, not just the first — physics names all
|
|
140
|
+
// EVERY failing gate, not just the first — physics names all six, and a
|
|
137
141
|
// memory blocked by two reasons that reports one is a memory nobody can
|
|
138
142
|
// explain. Mirrored into the skip map so the cycle report carries them.
|
|
139
143
|
for (const reason of verdict.blockedBy) {
|
package/src/core/store/NOTES.md
CHANGED
|
@@ -1955,3 +1955,17 @@ store does with it:
|
|
|
1955
1955
|
writer's three fields, provenance, confidential, and `meta` for schemas and episodes only),
|
|
1956
1956
|
read in one query rather than a `row()` per candidate. Never a body. A v11 file reads the
|
|
1957
1957
|
three fields as null.
|
|
1958
|
+
|
|
1959
|
+
## 2026-10-09 — a repeating reminder date, in meta (no schema bump)
|
|
1960
|
+
|
|
1961
|
+
- **`meta.recurring` (`RECURRING_META`), not a column.** The owner wanted recurring dates
|
|
1962
|
+
without a store-format change: a new version means a migration 0.3.12 cannot read back,
|
|
1963
|
+
and format changes are batched so migrations stay rare. The word sits beside
|
|
1964
|
+
`meta.remind`, its nearest sibling, and the anchor stays on `event_date` as stated. A
|
|
1965
|
+
build that never heard of it reads the anchor as a one-off date that has passed.
|
|
1966
|
+
- **`recurringMemories()`** is the read `datedMemories` cannot be: a birthday stated as
|
|
1967
|
+
`1990-05-14` never overlaps this year's span. Live rows (archived with
|
|
1968
|
+
`{ archived: true }`) with a DAY `event_date` and `meta LIKE '%"recurring":"%'`, the
|
|
1969
|
+
parsed meta deciding — the same loose-match-then-confirm `planCandidates` uses for
|
|
1970
|
+
`unresolved`. The partial `event_date` index bounds the scan to dated rows.
|
|
1971
|
+
`datedMemories` is unchanged.
|
package/src/core/store/index.ts
CHANGED
|
@@ -48,11 +48,13 @@ import {
|
|
|
48
48
|
daysBetween,
|
|
49
49
|
isCalendarDate,
|
|
50
50
|
isDay,
|
|
51
|
+
isRecurrence,
|
|
51
52
|
localDate,
|
|
52
53
|
parseCalendarDate,
|
|
53
54
|
resolveZone,
|
|
54
55
|
utcDate,
|
|
55
56
|
} from "../time.js";
|
|
57
|
+
import type { Recurrence } from "../time.js";
|
|
56
58
|
import { LATER_FEELING_SOURCES, checkFeelings } from "./feelings.js";
|
|
57
59
|
import type { AddFeelingsResult, FeelingInput, FeelingRow, FeelingSource } from "./feelings.js";
|
|
58
60
|
import { checkTraitsRepaired } from "./traits.js";
|
|
@@ -476,6 +478,43 @@ export interface DatedMemory {
|
|
|
476
478
|
readonly eventDate: string;
|
|
477
479
|
}
|
|
478
480
|
|
|
481
|
+
/**
|
|
482
|
+
* HOW OFTEN A REMINDER DATE COMES ROUND (2026-10-09, the owner's design, held
|
|
483
|
+
* lightly): `daily`, `weekly`, `monthly` or `yearly` (`time.ts#RECURRENCES`),
|
|
484
|
+
* anchored on the memory's `event_date`, in the memory's meta bag under this
|
|
485
|
+
* key — beside `remind`, and for the same reason: NO SCHEMA BUMP, so a store
|
|
486
|
+
* written with it opens in a build that never heard of it, which reads the
|
|
487
|
+
* anchor as a one-off date already passed. Only a DAY repeats; on a month, a
|
|
488
|
+
* range or a year the key is inert. `prospective/` is its reader.
|
|
489
|
+
*/
|
|
490
|
+
export const RECURRING_META = "recurring";
|
|
491
|
+
|
|
492
|
+
/**
|
|
493
|
+
* The repeat a ROW carries, or null: a day `event_date` and a recurrence word
|
|
494
|
+
* in its meta — the one predicate `recurringMemories` and the prune's
|
|
495
|
+
* `recurring` gate (`sleep/prune.ts`, 2026-10-09) both read. Unreadable meta,
|
|
496
|
+
* a month or a range, or `recurring` dropped: null, the date is once.
|
|
497
|
+
*/
|
|
498
|
+
export function recurrenceOfRow(row: { readonly event_date: string | null; readonly meta: string }): Recurrence | null {
|
|
499
|
+
if (!isDay(row.event_date)) return null;
|
|
500
|
+
if (!row.meta.includes(`"${RECURRING_META}"`)) return null;
|
|
501
|
+
let rule: unknown;
|
|
502
|
+
try {
|
|
503
|
+
rule = (JSON.parse(row.meta) as Record<string, unknown>)[RECURRING_META];
|
|
504
|
+
} catch {
|
|
505
|
+
return null;
|
|
506
|
+
}
|
|
507
|
+
return isRecurrence(rule) ? rule : null;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
/** One memory whose reminder date repeats, as `Store.recurringMemories` returns it. */
|
|
511
|
+
export interface RecurringMemory {
|
|
512
|
+
readonly id: string;
|
|
513
|
+
/** The day as stated — the anchor every occurrence is counted from. */
|
|
514
|
+
readonly eventDate: string;
|
|
515
|
+
readonly recurring: Recurrence;
|
|
516
|
+
}
|
|
517
|
+
|
|
479
518
|
/**
|
|
480
519
|
* ONE LIVE ROW as deliberate recall's facts mode ranks and labels it (Release
|
|
481
520
|
* B, 2026-10-03): the columns, never the body (`Store#recallRows`). The
|
|
@@ -2444,6 +2483,11 @@ export class Store {
|
|
|
2444
2483
|
);
|
|
2445
2484
|
}
|
|
2446
2485
|
|
|
2486
|
+
/** How many reflections the store holds, counted in SQL — so a caller that wants every one (`export --markdown`) can ask for exactly that many. */
|
|
2487
|
+
reflectionCount(): number {
|
|
2488
|
+
return this.ops.get<{ n: number }>("SELECT COUNT(*) AS n FROM reflections")?.n ?? 0;
|
|
2489
|
+
}
|
|
2490
|
+
|
|
2447
2491
|
/** True when the owner's latest word on this memory's core membership is a demotion. */
|
|
2448
2492
|
coreDemoted(id: string): boolean {
|
|
2449
2493
|
const last = this.ops.get<{ action: string }>(
|
|
@@ -4230,6 +4274,46 @@ export class Store {
|
|
|
4230
4274
|
.map((r) => r.id);
|
|
4231
4275
|
}
|
|
4232
4276
|
|
|
4277
|
+
/**
|
|
4278
|
+
* WHAT A SESSION WROTE IN ONE DIRECTORY AFTER A MOMENT THAT MAY BE A PLAN
|
|
4279
|
+
* (2026-10-09, the handoff's "since" line): live memories a session wrote
|
|
4280
|
+
* itself (`source = 'authored'`: a note, a `session_end` entry) under one of
|
|
4281
|
+
* `scopes`, born after `after` (epoch ms), whose v12 `status` is one of
|
|
4282
|
+
* `statuses` or whose meta may say `unresolved` — a loose text match the
|
|
4283
|
+
* caller confirms on the prose. Not archived, superseded or emptied, and
|
|
4284
|
+
* not confidential unless `confidential`. Newest first, then id, at most
|
|
4285
|
+
* `limit`. The columns only, as `workCandidates`. A store without the v12
|
|
4286
|
+
* column throws; the caller wraps it.
|
|
4287
|
+
*/
|
|
4288
|
+
planCandidates(input: {
|
|
4289
|
+
readonly scopes: readonly string[];
|
|
4290
|
+
readonly after: number;
|
|
4291
|
+
readonly statuses: readonly MemoryStatus[];
|
|
4292
|
+
readonly limit: number;
|
|
4293
|
+
readonly confidential?: boolean;
|
|
4294
|
+
}): string[] {
|
|
4295
|
+
const scopes = input.scopes.filter((s) => s.length > 0);
|
|
4296
|
+
const statuses = input.statuses.filter((s) => (STATUSES as readonly string[]).includes(s));
|
|
4297
|
+
if (scopes.length === 0 || input.limit <= 0) return [];
|
|
4298
|
+
const marks = (n: number): string => Array.from({ length: n }, () => "?").join(", ");
|
|
4299
|
+
const status = statuses.length === 0 ? "" : `status IN (${marks(statuses.length)}) OR `;
|
|
4300
|
+
return this.ops
|
|
4301
|
+
.all<{ id: string }>(
|
|
4302
|
+
`SELECT id FROM memories
|
|
4303
|
+
WHERE type = 'memory' AND archived = 0 AND superseded_by IS NULL AND body != ''
|
|
4304
|
+
AND source = 'authored' AND origin_scope IN (${marks(scopes.length)}) AND created_at > ?
|
|
4305
|
+
${input.confidential === true ? "" : "AND confidential = 0"}
|
|
4306
|
+
AND (${status}meta LIKE '%"unresolved":true%')
|
|
4307
|
+
ORDER BY created_at DESC, id
|
|
4308
|
+
LIMIT ?`,
|
|
4309
|
+
...scopes,
|
|
4310
|
+
input.after,
|
|
4311
|
+
...statuses,
|
|
4312
|
+
Math.max(0, Math.floor(input.limit)),
|
|
4313
|
+
)
|
|
4314
|
+
.map((r) => r.id);
|
|
4315
|
+
}
|
|
4316
|
+
|
|
4233
4317
|
/**
|
|
4234
4318
|
* How many rows `list()` would return, counted in SQL rather than materialized.
|
|
4235
4319
|
* The same filter, the same WHERE, one number — for the callers that want the
|
|
@@ -4271,6 +4355,29 @@ export class Store {
|
|
|
4271
4355
|
.map((r) => ({ id: r.id, eventDate: r.event_date }));
|
|
4272
4356
|
}
|
|
4273
4357
|
|
|
4358
|
+
/**
|
|
4359
|
+
* LIVE memories whose reminder date REPEATS (`RECURRING_META`, 2026-10-09):
|
|
4360
|
+
* a day `event_date` and a recurrence word in meta. `datedMemories` asks
|
|
4361
|
+
* whether the date AS STATED reaches a span, and a birthday stated as
|
|
4362
|
+
* `1990-05-14` never reaches this year's; this is the other half, and
|
|
4363
|
+
* `prospective/` asks it for the occurrence that does. The SQL match is
|
|
4364
|
+
* loose (a text match on the meta, as `planCandidates` does for
|
|
4365
|
+
* `unresolved`) and the parsed meta decides. Ordered by id.
|
|
4366
|
+
*/
|
|
4367
|
+
recurringMemories(opts: { archived?: boolean } = {}): RecurringMemory[] {
|
|
4368
|
+
const rows = this.ops.all<{ id: string; event_date: string; meta: string }>(
|
|
4369
|
+
`SELECT id, event_date, meta FROM memories
|
|
4370
|
+
WHERE event_date IS NOT NULL AND meta LIKE '%"${RECURRING_META}":"%'${opts.archived === true ? "" : " AND archived = 0"}
|
|
4371
|
+
ORDER BY id`,
|
|
4372
|
+
);
|
|
4373
|
+
const out: RecurringMemory[] = [];
|
|
4374
|
+
for (const r of rows) {
|
|
4375
|
+
const rule = recurrenceOfRow(r);
|
|
4376
|
+
if (rule !== null) out.push({ id: r.id, eventDate: r.event_date, recurring: rule });
|
|
4377
|
+
}
|
|
4378
|
+
return out;
|
|
4379
|
+
}
|
|
4380
|
+
|
|
4274
4381
|
/** A memory's feelings, oldest first (then in the order written). A removed memory has none. */
|
|
4275
4382
|
feelingsFor(memoryId: string): FeelingRow[] {
|
|
4276
4383
|
return this.ops.all<FeelingRow>(
|
package/src/core/time.ts
CHANGED
|
@@ -222,6 +222,33 @@ export function localStampAfter(at: number, after: number, zone?: string): strin
|
|
|
222
222
|
return q !== null && q.month === p.month && q.day === p.day ? clock : `${p.month}-${p.day} ${clock}`;
|
|
223
223
|
}
|
|
224
224
|
|
|
225
|
+
/**
|
|
226
|
+
* The first moment of the calendar day `ymd` in `zone` — local midnight, as an
|
|
227
|
+
* instant (2026-10-09). A window over moments that is meant to be a person's
|
|
228
|
+
* days starts here, never at `${ymd}T00:00:00Z`, which is the UTC day: in
|
|
229
|
+
* Denver that opens the window six hours early, in Kiritimati fourteen hours
|
|
230
|
+
* late. Found by a search over `localDate` rather than by offset arithmetic, so
|
|
231
|
+
* a day a clock change starts at 01:00 still starts where the zone says it
|
|
232
|
+
* does. Throws on a malformed day — a caller's bug, as `addDays` does.
|
|
233
|
+
*/
|
|
234
|
+
export function startOfLocalDay(ymd: string, zone?: string): number {
|
|
235
|
+
const z = zone === undefined || !isZoneCached(zone) ? machineZone() : zone;
|
|
236
|
+
const utcMidnight = Date.parse(`${ymd}T00:00:00Z`);
|
|
237
|
+
if (!isDay(ymd) || !Number.isFinite(utcMidnight)) throw new RangeError(`startOfLocalDay: not a day: ${ymd}`);
|
|
238
|
+
const minute = 60_000;
|
|
239
|
+
// Every offset in use lies inside UTC−12..UTC+14, so local midnight lies
|
|
240
|
+
// between these two bounds, with an hour to spare on each side: the first is
|
|
241
|
+
// always the day before in `z`, the second always `ymd` or later.
|
|
242
|
+
let before = Math.floor((utcMidnight - 15 * 3_600_000) / minute);
|
|
243
|
+
let onOrAfter = Math.floor((utcMidnight + 13 * 3_600_000) / minute);
|
|
244
|
+
while (onOrAfter - before > 1) {
|
|
245
|
+
const mid = Math.floor((before + onOrAfter) / 2);
|
|
246
|
+
if (localDate(mid * minute, z) < ymd) before = mid;
|
|
247
|
+
else onOrAfter = mid;
|
|
248
|
+
}
|
|
249
|
+
return onOrAfter * minute;
|
|
250
|
+
}
|
|
251
|
+
|
|
225
252
|
/** Today's `YYYY-MM-DD` in `zone`. A store passes its own clock; the default is
|
|
226
253
|
* the ambient one, for an adapter with no store open. */
|
|
227
254
|
export function todayIn(zone?: string, at: number = Date.now()): string {
|
|
@@ -429,3 +456,128 @@ export function readableDate(ymd: string): string {
|
|
|
429
456
|
|
|
430
457
|
/** Legacy name (`self/calendar.ts`, 2026-09-23): the local date of a moment. */
|
|
431
458
|
export const calendarDate = localDate;
|
|
459
|
+
|
|
460
|
+
// ── a date that repeats (2026-10-09, the owner's design, held lightly) ───────
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* How often a stated DAY comes round again, anchored on that day: a birthday
|
|
464
|
+
* stored as `1990-05-14` with `yearly` is every May 14 from then on. Every
|
|
465
|
+
* other week, "the first Monday" and the like are not kept (loose first), and
|
|
466
|
+
* nothing finer than a day: dates and reminders here are per day.
|
|
467
|
+
*/
|
|
468
|
+
export const RECURRENCES = ["daily", "weekly", "monthly", "yearly"] as const;
|
|
469
|
+
export type Recurrence = (typeof RECURRENCES)[number];
|
|
470
|
+
|
|
471
|
+
/** Is `v` one of the four recurrence words? */
|
|
472
|
+
export function isRecurrence(v: unknown): v is Recurrence {
|
|
473
|
+
return typeof v === "string" && (RECURRENCES as readonly string[]).includes(v);
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
const MONTH_NAMES = [
|
|
477
|
+
"January", "February", "March", "April", "May", "June",
|
|
478
|
+
"July", "August", "September", "October", "November", "December",
|
|
479
|
+
] as const;
|
|
480
|
+
const WEEKDAY_NAMES = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"] as const;
|
|
481
|
+
|
|
482
|
+
/** A month `k` months after `(y, m)`, with the day held to that month's length. */
|
|
483
|
+
function monthsAfter(y: number, m: number, d: number, k: number): number {
|
|
484
|
+
const total = y * 12 + (m - 1) + k;
|
|
485
|
+
const yy = Math.floor(total / 12);
|
|
486
|
+
const mm = (total % 12) + 1;
|
|
487
|
+
return dayNumber(yy, mm, Math.min(d, daysInMonth(yy, mm)));
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
/**
|
|
491
|
+
* The `k`-th time a stated day comes round (`k = 0` is the day itself), as a
|
|
492
|
+
* day count. ALWAYS counted from the anchor, never from the last occurrence,
|
|
493
|
+
* so a short month cannot drag the rest of the year with it:
|
|
494
|
+
*
|
|
495
|
+
* - **monthly on the 29th, 30th or 31st** falls on the LAST day of a month
|
|
496
|
+
* too short to have it (Jan 31 → Feb 28, or 29 in a leap year → Mar 31 →
|
|
497
|
+
* Apr 30 → May 31);
|
|
498
|
+
* - **yearly on Feb 29** falls on Feb 28 in a year with no Feb 29.
|
|
499
|
+
*/
|
|
500
|
+
function occurrenceNumber(y: number, m: number, d: number, rule: Recurrence, k: number): number {
|
|
501
|
+
switch (rule) {
|
|
502
|
+
case "daily":
|
|
503
|
+
return dayNumber(y, m, d) + k;
|
|
504
|
+
case "weekly":
|
|
505
|
+
return dayNumber(y, m, d) + 7 * k;
|
|
506
|
+
case "monthly":
|
|
507
|
+
return monthsAfter(y, m, d, k);
|
|
508
|
+
case "yearly":
|
|
509
|
+
return monthsAfter(y, m, d, 12 * k);
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
/** The anchor read as numbers, or null when it is not one real DAY. */
|
|
514
|
+
function anchorParts(anchor: string): [number, number, number] | null {
|
|
515
|
+
if (dayOf(anchor) === null) return null;
|
|
516
|
+
const [y, m, d] = anchor.split("-").map(Number) as [number, number, number];
|
|
517
|
+
return [y, m, d];
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
/** The `k`-th occurrence of `anchor` (k ≥ 0), `YYYY-MM-DD`; null for anything but a real day. */
|
|
521
|
+
export function occurrenceOf(anchor: string, rule: Recurrence, k: number): string | null {
|
|
522
|
+
const p = anchorParts(anchor);
|
|
523
|
+
if (p === null || !Number.isInteger(k) || k < 0) return null;
|
|
524
|
+
return fromDayNumber(occurrenceNumber(p[0], p[1], p[2], rule, k));
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
/**
|
|
528
|
+
* The first occurrence of `anchor` on or after `ymd`, and its index. Never one
|
|
529
|
+
* before the anchor: a repeat starts on the day it was stated. Null when either
|
|
530
|
+
* is not a real day.
|
|
531
|
+
*/
|
|
532
|
+
export function occurrenceOnOrAfter(anchor: string, rule: Recurrence, ymd: string): { k: number; date: string } | null {
|
|
533
|
+
const p = anchorParts(anchor);
|
|
534
|
+
const target = dayOf(ymd);
|
|
535
|
+
if (p === null || target === null) return null;
|
|
536
|
+
const [y, m, d] = p;
|
|
537
|
+
const start = dayNumber(y, m, d);
|
|
538
|
+
if (target <= start) return { k: 0, date: anchor };
|
|
539
|
+
// A lower bound on k, then forward: at most a step or two past the estimate.
|
|
540
|
+
let k =
|
|
541
|
+
rule === "daily"
|
|
542
|
+
? target - start
|
|
543
|
+
: rule === "weekly"
|
|
544
|
+
? Math.floor((target - start) / 7)
|
|
545
|
+
: rule === "monthly"
|
|
546
|
+
? Math.max(0, (Number(ymd.slice(0, 4)) - y) * 12 + (Number(ymd.slice(5, 7)) - m) - 1)
|
|
547
|
+
: Math.max(0, Number(ymd.slice(0, 4)) - y - 1);
|
|
548
|
+
while (occurrenceNumber(y, m, d, rule, k) < target) k += 1;
|
|
549
|
+
return { k, date: fromDayNumber(occurrenceNumber(y, m, d, rule, k)) };
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
/** Does some occurrence of `anchor` fall on a day from `from` to `to`, inclusive? The first one that does, or null. */
|
|
553
|
+
export function occurrenceBetween(anchor: string, rule: Recurrence, from: string, to: string): string | null {
|
|
554
|
+
const next = occurrenceOnOrAfter(anchor, rule, from);
|
|
555
|
+
return next !== null && next.date <= to ? next.date : null;
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
function ordinal(n: number): string {
|
|
559
|
+
const tens = n % 100;
|
|
560
|
+
const suffix = tens >= 11 && tens <= 13 ? "th" : n % 10 === 1 ? "st" : n % 10 === 2 ? "nd" : n % 10 === 3 ? "rd" : "th";
|
|
561
|
+
return `${String(n)}${suffix}`;
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
/**
|
|
565
|
+
* The repeat as a person says it, from the ANCHOR (so a monthly 31st reads as
|
|
566
|
+
* the 31st even in a February): `every day`, `every Monday`, `every month on
|
|
567
|
+
* the 14th`, `every May 14`. Empty for an anchor that is not a real day.
|
|
568
|
+
*/
|
|
569
|
+
export function readableRecurrence(anchor: string, rule: Recurrence): string {
|
|
570
|
+
const p = anchorParts(anchor);
|
|
571
|
+
if (p === null) return "";
|
|
572
|
+
const [, m, d] = p;
|
|
573
|
+
switch (rule) {
|
|
574
|
+
case "daily":
|
|
575
|
+
return "every day";
|
|
576
|
+
case "weekly":
|
|
577
|
+
return `every ${WEEKDAY_NAMES[(((dayNumber(p[0], m, d) + 4) % 7) + 7) % 7] ?? ""}`;
|
|
578
|
+
case "monthly":
|
|
579
|
+
return `every month on the ${ordinal(d)}`;
|
|
580
|
+
case "yearly":
|
|
581
|
+
return `every ${MONTH_NAMES[m - 1] ?? ""} ${String(d)}`;
|
|
582
|
+
}
|
|
583
|
+
}
|
|
@@ -472,23 +472,25 @@ recall: $RECALL_OUT"
|
|
|
472
472
|
fi
|
|
473
473
|
fi
|
|
474
474
|
|
|
475
|
-
step "
|
|
475
|
+
step "the full answer counts its matches and says how each one stands"
|
|
476
476
|
# `answered` says the question reached something, never that it is right. The
|
|
477
|
-
#
|
|
478
|
-
#
|
|
479
|
-
#
|
|
480
|
-
#
|
|
481
|
-
#
|
|
477
|
+
# vivid / quiet / dim tiers went with #323 (0.3.12): `--full` is now the facts
|
|
478
|
+
# answer the model reads — a count first (`1 match · showing 1`, the line under
|
|
479
|
+
# `Store:`), then each fact numbered with its id and the ways it matched, who
|
|
480
|
+
# said it and its status, when it was learned, and whether it is still CURRENT.
|
|
481
|
+
# The short answer is step 18's.
|
|
482
482
|
eval 'export COUNTERPARTS_DATA_DIR="$HOME/.counterparts/store"'
|
|
483
483
|
FULL_OUT=$(eval "$RECALL_CMD --full" 2>&1)
|
|
484
484
|
unset COUNTERPARTS_DATA_DIR
|
|
485
|
-
if
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
485
|
+
if sed -n 2p <<<"$FULL_OUT" | grep -qE '^[0-9]+ match( · |$)' &&
|
|
486
|
+
grep -qE '^1\. .*port 5433.* · mem_[0-9a-f]+ · (words|meaning|subject|time|session)' <<<"$FULL_OUT" &&
|
|
487
|
+
grep -qE '^ (you said|I said|inferred|speaker unknown) · ' <<<"$FULL_OUT" &&
|
|
488
|
+
grep -qE '^ learned .* · CURRENT' <<<"$FULL_OUT" &&
|
|
489
|
+
! grep -q "Rancilio Silvia" <<<"$FULL_OUT" &&
|
|
490
|
+
! grep -qE '^ (vivid|quiet|dim) = ' <<<"$FULL_OUT"; then
|
|
489
491
|
ok
|
|
490
492
|
else
|
|
491
|
-
no "
|
|
493
|
+
no "--full did not open with the count, or a fact lacks its id, ways, speaker or standing" "short: $RECALL_OUT
|
|
492
494
|
full: $FULL_OUT"
|
|
493
495
|
fi
|
|
494
496
|
|
|
@@ -703,7 +705,8 @@ step "note then recall round-trips through the MCP server"
|
|
|
703
705
|
# The canary is deliberately plain ASCII with no quotes or backslashes, so it
|
|
704
706
|
# needs no JSON escaping to be embedded here.
|
|
705
707
|
NOTE_PARAMS=$(printf '{"name":"note","arguments":{"text":"%s"}}' "$CANARY")
|
|
706
|
-
|
|
708
|
+
# A question needs `mode` since #323 (0.3.12): without one it is refused.
|
|
709
|
+
RECALL_PARAMS='{"name":"recall","arguments":{"question":"what espresso machine is in the kitchen?","mode":"facts"}}'
|
|
707
710
|
RPC=$(
|
|
708
711
|
printf '%s\n' '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{}}}'
|
|
709
712
|
printf '%s\n' '{"jsonrpc":"2.0","method":"notifications/initialized"}'
|
|
@@ -869,6 +872,39 @@ else
|
|
|
869
872
|
$OUT"
|
|
870
873
|
fi
|
|
871
874
|
|
|
875
|
+
step "what were we about to do? a plan written after the handoff is named beside it"
|
|
876
|
+
# 2026-10-09: one session leaves a handoff in the project, another changes the
|
|
877
|
+
# plan there in a note and leaves the handoff as it was. The next session's wake
|
|
878
|
+
# carries the note under the pointer ("Since this handoff: …"), so the newer
|
|
879
|
+
# plan is not quiet. Two sessions, because what the handoff's own session writes
|
|
880
|
+
# within five minutes of it is the same answer (`handoff/index.ts`,
|
|
881
|
+
# SINCE_SAME_ANSWER_MS), and this loop runs in seconds.
|
|
882
|
+
PLAN_SESSION="install-loop-plan-$$"
|
|
883
|
+
NEXT_SESSION="install-loop-next-$$"
|
|
884
|
+
INIT='{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{}}}'
|
|
885
|
+
INITED='{"jsonrpc":"2.0","method":"notifications/initialized"}'
|
|
886
|
+
HANDOFF_CALL=$(printf '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"session_end","arguments":{"session":"%s","memories":[],"handoff":"%s"}}}' \
|
|
887
|
+
"$SESSION" "The install loop left the release half cut: the tarball is packed and not published.")
|
|
888
|
+
PLAN_CALL=$(printf '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"note","arguments":{"session":"%s","title":"%s","text":"%s","status":"planned"}}}' \
|
|
889
|
+
"$PLAN_SESSION" "Publish only after the docs pass" "Changed plan: the tarball is published only after the docs pass lands.")
|
|
890
|
+
HANDED=$(printf '%s\n' "$INIT" "$INITED" "$HANDOFF_CALL" |
|
|
891
|
+
COUNTERPARTS_DATA_DIR="$STORE" COUNTERPARTS_SCOPE="$HOME/project" counterparts-mcp 2>"$WORK/mcp-handoff.err" | grep '"id":2' || true)
|
|
892
|
+
payload SessionStart "$PLAN_SESSION" | counterparts-hook >/dev/null 2>"$WORK/hook-plan.err"
|
|
893
|
+
PLANNED=$(printf '%s\n' "$INIT" "$INITED" "$PLAN_CALL" |
|
|
894
|
+
COUNTERPARTS_DATA_DIR="$STORE" COUNTERPARTS_SCOPE="$HOME/project" counterparts-mcp 2>"$WORK/mcp-plan.err" | grep '"id":2' || true)
|
|
895
|
+
OUT=$(payload SessionStart "$NEXT_SESSION" | counterparts-hook 2>"$WORK/hook-next.err")
|
|
896
|
+
if grep -q '"isError":true' <<<"$HANDED$PLANNED"; then
|
|
897
|
+
no "the handoff or the note was refused" "$HANDED
|
|
898
|
+
$PLANNED"
|
|
899
|
+
elif grep -q "Where I left off in this directory" <<<"$OUT" &&
|
|
900
|
+
grep -q "Since this handoff: Publish only after the docs pass (planned, mem_[0-9a-f]\{12\})" <<<"$OUT"; then
|
|
901
|
+
ok
|
|
902
|
+
else
|
|
903
|
+
no "the next wake did not name the plan under the handoff" "$(cat "$WORK/hook-next.err")
|
|
904
|
+
note: $PLANNED
|
|
905
|
+
$OUT"
|
|
906
|
+
fi
|
|
907
|
+
|
|
872
908
|
step "the dashboard opens the same store"
|
|
873
909
|
CMD='counterparts-dashboard status --dir "$HOME/.counterparts/store"'
|
|
874
910
|
if true; then
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
/* Ask's answers, with a journal chapter and the memory drawn from it folded
|
|
2
|
-
into one (2026-09-27, round 3; a try, not a rule).
|
|
3
|
-
|
|
4
|
-
`counterparts ask` can return a journal chapter (`journal: true`, the entry)
|
|
5
|
-
and the memory minted from it (`isChapterMemory`) side by side, with the
|
|
6
|
-
same words. The page shows the memory once, where the better of the two was
|
|
7
|
-
ranked, with a small "from chapter …" link to the entry. Pure (no DOM), so
|
|
8
|
-
`bun test` checks it; the links come from `/api/chapters`
|
|
9
|
-
(`views/search.ts#chapterLinks`).
|
|
10
|
-
|
|
11
|
-
Since 2026-09-30 (U13) recall itself returns the pair as ONE answer — the
|
|
12
|
-
chapter (`core/recall/activate.ts`, the collapse) — so the fold below sees a
|
|
13
|
-
pair only from an older build's answer. A memory whose chapter was not in
|
|
14
|
-
the answer still gets its "from chapter …" link. */
|
|
15
|
-
|
|
16
|
-
const TIER_ORDER = { vivid: 0, quiet: 1, dim: 2 };
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* `mems`: Ask's `memories`, best first. `links`: `{ [memoryId]: { episodeId,
|
|
20
|
-
* label } }`. Returns the answers to show, best first, each with `from` (its
|
|
21
|
-
* chapter link, or null) and `chapter` (true for a chapter memory). An entry
|
|
22
|
-
* whose chapter memory is also in the answer is dropped, and the memory takes
|
|
23
|
-
* the entry's place and tier when the entry ranked higher.
|
|
24
|
-
*/
|
|
25
|
-
export function foldChapters(mems, links) {
|
|
26
|
-
const list = Array.isArray(mems) ? mems : [];
|
|
27
|
-
const L = links || {};
|
|
28
|
-
const at = new Map();
|
|
29
|
-
list.forEach((m, i) => { if (m && m.journal) at.set(m.id, i); });
|
|
30
|
-
const folded = new Set();
|
|
31
|
-
const items = list.map((m, i) => {
|
|
32
|
-
const link = L[m.id] || null;
|
|
33
|
-
let rank = i, tier = m.tier;
|
|
34
|
-
if (link && at.has(link.episodeId)) {
|
|
35
|
-
const j = at.get(link.episodeId);
|
|
36
|
-
folded.add(link.episodeId);
|
|
37
|
-
if (j < rank) rank = j;
|
|
38
|
-
const other = list[j].tier;
|
|
39
|
-
if ((TIER_ORDER[other] ?? 9) < (TIER_ORDER[tier] ?? 9)) tier = other;
|
|
40
|
-
}
|
|
41
|
-
return { m: { ...m, tier, from: link, chapter: link !== null }, rank, i };
|
|
42
|
-
});
|
|
43
|
-
return items
|
|
44
|
-
.filter((x) => !(x.m.journal && folded.has(x.m.id)))
|
|
45
|
-
.sort((a, b) => a.rank - b.rank || a.i - b.i)
|
|
46
|
-
.map((x) => x.m);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/** The link's words: `from chapter “Halfmoon pilot — 2026-06-01”`. */
|
|
50
|
-
export function fromWords(from) {
|
|
51
|
-
if (!from) return "";
|
|
52
|
-
return from.label ? "from chapter “" + from.label + "”" : "from its journal chapter";
|
|
53
|
-
}
|