counterparts 0.2.0 → 0.3.1

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 (118) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/README.md +87 -367
  3. package/docs/QUICKSTART.md +83 -1584
  4. package/docs/README.md +86 -0
  5. package/docs/module-map.md +1 -0
  6. package/package.json +6 -2
  7. package/src/adapters/claude-code/CONTRACT.md +153 -19
  8. package/src/adapters/claude-code/INTERFACE-GAPS.md +138 -2
  9. package/src/adapters/claude-code/NOTES.md +508 -0
  10. package/src/adapters/claude-code/bin/hook.ts +223 -49
  11. package/src/adapters/claude-code/bin/runner.ts +221 -101
  12. package/src/adapters/claude-code/config.ts +202 -279
  13. package/src/adapters/claude-code/doctor.ts +822 -427
  14. package/src/adapters/claude-code/embed-client.ts +165 -557
  15. package/src/adapters/claude-code/hooks.ts +414 -116
  16. package/src/adapters/claude-code/index.ts +8 -59
  17. package/src/adapters/claude-code/page-writer.ts +24 -4
  18. package/src/adapters/claude-code/spawn.ts +6 -7
  19. package/src/adapters/claude-code/standdown.ts +12 -1
  20. package/src/adapters/claude-code/transcript.ts +282 -15
  21. package/src/adapters/claude-code/vectors.ts +108 -24
  22. package/src/adapters/cli/CONTRACT.md +123 -3
  23. package/src/adapters/cli/INTERFACE-GAPS.md +49 -2
  24. package/src/adapters/cli/NOTES.md +265 -1
  25. package/src/adapters/cli/bin/counterparts.ts +9 -9
  26. package/src/adapters/cli/commands.ts +525 -438
  27. package/src/adapters/cli/help.ts +22 -27
  28. package/src/adapters/cli/index.ts +0 -2
  29. package/src/adapters/cli/install.ts +102 -89
  30. package/src/adapters/cli/removal.ts +1 -1
  31. package/src/adapters/cli/report.ts +25 -2
  32. package/src/adapters/cli/snapshot.ts +4 -27
  33. package/src/adapters/cli/uninstall.ts +182 -34
  34. package/src/adapters/cli/wire.ts +232 -35
  35. package/src/adapters/dashboard/INTERFACE-GAPS.md +18 -2
  36. package/src/adapters/dashboard/activity.ts +4 -1
  37. package/src/adapters/dashboard/bin/dashboard.ts +1 -1
  38. package/src/adapters/dashboard/registries.ts +16 -1
  39. package/src/adapters/dashboard/resolve.ts +4 -4
  40. package/src/adapters/dashboard/source.ts +8 -2
  41. package/src/adapters/dashboard/web/flow.ts +6 -0
  42. package/src/adapters/dashboard/web/narrate.ts +66 -14
  43. package/src/adapters/dashboard/web/reveal.ts +6 -6
  44. package/src/adapters/dashboard/web/views.ts +12 -4
  45. package/src/adapters/fired.ts +130 -19
  46. package/src/adapters/mcp/CONTRACT.md +73 -1
  47. package/src/adapters/mcp/INTERFACE-GAPS.md +54 -1
  48. package/src/adapters/mcp/NOTES.md +389 -0
  49. package/src/adapters/mcp/bin/serve.ts +28 -35
  50. package/src/adapters/mcp/deliberate.ts +22 -0
  51. package/src/adapters/mcp/index.ts +30 -2
  52. package/src/adapters/mcp/server.ts +429 -49
  53. package/src/adapters/mcp/tools.ts +32 -7
  54. package/src/adapters/mcp/write-up.ts +454 -0
  55. package/src/adapters/sessions.ts +1370 -0
  56. package/src/adapters/snapshots.ts +71 -39
  57. package/src/core/associate/INTERFACE-GAPS.md +8 -0
  58. package/src/core/counterpart.ts +88 -14
  59. package/src/core/embed/CONTRACT.md +85 -0
  60. package/src/core/embed/NOTES.md +93 -0
  61. package/src/core/embed/static.ts +622 -0
  62. package/src/core/encode/INTERFACE-GAPS.md +29 -0
  63. package/src/core/encode/NOTES.md +78 -0
  64. package/src/core/encode/secrets.ts +309 -9
  65. package/src/core/handoff/INTERFACE-GAPS.md +15 -1
  66. package/src/core/prospective/INTERFACE-GAPS.md +4 -0
  67. package/src/core/recall/CONTRACT.md +15 -3
  68. package/src/core/recall/INTERFACE-GAPS.md +100 -0
  69. package/src/core/recall/NOTES.md +49 -0
  70. package/src/core/recall/activate.ts +37 -3
  71. package/src/core/recall/index.ts +22 -1
  72. package/src/core/recall/session.ts +32 -0
  73. package/src/core/recall/tunables.ts +99 -2
  74. package/src/core/remember/CONTRACT.md +51 -7
  75. package/src/core/remember/INTERFACE-GAPS.md +121 -1
  76. package/src/core/remember/NOTES.md +221 -1
  77. package/src/core/remember/index.ts +28 -0
  78. package/src/core/remember/owes.ts +532 -0
  79. package/src/core/remember/owner-strike-seam.ts +34 -2
  80. package/src/core/remember/proposals.ts +25 -6
  81. package/src/core/remember/retention.ts +154 -0
  82. package/src/core/remember/spans.ts +53 -12
  83. package/src/core/remember/tunables.ts +8 -0
  84. package/src/core/remember/write-up-seam.ts +104 -0
  85. package/src/core/schemas/INTERFACE-GAPS.md +8 -0
  86. package/src/core/schemas/NOTES.md +118 -1
  87. package/src/core/schemas/index.ts +330 -40
  88. package/src/core/schemas/tunables.ts +23 -0
  89. package/src/core/schemas/types.ts +64 -1
  90. package/src/core/self/CONTRACT.md +19 -13
  91. package/src/core/self/INTERFACE-GAPS.md +18 -1
  92. package/src/core/self/NOTES.md +137 -1
  93. package/src/core/self/calendar.ts +81 -0
  94. package/src/core/self/episodes.ts +201 -38
  95. package/src/core/self/identity.ts +2 -2
  96. package/src/core/self/index.ts +96 -21
  97. package/src/core/self/tunables.ts +18 -46
  98. package/src/core/self/writer.ts +58 -9
  99. package/src/core/sleep/NOTES.md +36 -0
  100. package/src/core/sleep/cycle.ts +30 -1
  101. package/src/core/sleep/fade.ts +76 -0
  102. package/src/core/sleep/index.ts +4 -1
  103. package/src/core/sleep/prune.ts +8 -1
  104. package/src/core/sleep/tunables.ts +5 -0
  105. package/src/core/sleep/types.ts +24 -0
  106. package/src/core/store/CONTRACT.md +26 -1
  107. package/src/core/store/NOTES.md +348 -0
  108. package/src/core/store/cache.ts +585 -27
  109. package/src/core/store/db.ts +97 -0
  110. package/src/core/store/errors.ts +7 -0
  111. package/src/core/store/index.ts +612 -13
  112. package/src/core/store/operational.ts +107 -11
  113. package/src/core/store/paths.ts +15 -1
  114. package/src/core/store/pre-migration.ts +256 -0
  115. package/tools/install-loop/run.sh +52 -71
  116. package/src/adapters/claude-code/credentials.ts +0 -199
  117. package/src/adapters/claude-code/interpret-client.ts +0 -395
  118. package/src/adapters/cli/keys.ts +0 -503
@@ -19,20 +19,16 @@
19
19
  # throwaway directory. The store the loop asserts about is the store the
20
20
  # loop made, and both sides are resolved before they are compared.
21
21
  #
22
- # And one rule it enforces on the DOCS: every command it runs as a step a reader
23
- # would run must appear verbatim in `docs/QUICKSTART.md`. `doc_check` greps for
24
- # the line before it is executed, so the loop and the written install path
25
- # cannot drift apart silently — a doc edit that changes a command fails the loop.
26
- # The two NUMBERS the doc quotes about this loop — how many steps it runs, and
27
- # which step is the lazy `session_end` bind (§10) — are held to it the other way
28
- # round, by `test/install-loop.test.ts`: add or move a `step "..."` line and
29
- # `bun test` says which sentence in QUICKSTART to change.
22
+ # And one rule it enforces on the DOCS: the commands QUICKSTART shows a reader
23
+ # (install, version, scripted install, scope, connect, disconnect) must appear
24
+ # there verbatim. `doc_check` greps for the line before it is executed, so a doc
25
+ # edit that changes one of them fails the loop. The other steps run commands the
26
+ # guide does not show, and are checked for behaviour only.
30
27
  #
31
28
  # Usage: tools/install-loop/run.sh [workdir]
32
29
  # Default workdir: a fresh `install-loop-<pid>` under $TMPDIR.
33
30
  #
34
- # What this loop CANNOT verify is named in QUICKSTART §10 and in the report: it
35
- # never launches Claude Code, so the hooks block and the MCP registration are
31
+ # What this loop CANNOT verify: it never launches Claude Code, so the hooks block and the MCP registration are
36
32
  # checked as files and processes, never as a live session.
37
33
 
38
34
  set -uo pipefail
@@ -187,9 +183,8 @@ no() { # no <why> [output]
187
183
  fi
188
184
  }
189
185
 
190
- # Lockstep. Every command a READER would run is checked against QUICKSTART.md
191
- # before it is executed; a command the docs do not contain, verbatim, is a
192
- # failed step whatever it would have done.
186
+ # Lockstep. A command QUICKSTART shows is checked against it before it is
187
+ # executed; if the doc no longer contains it verbatim, the step fails.
193
188
  doc_check() {
194
189
  grep -qF -- "$1" "$QUICKSTART"
195
190
  }
@@ -296,7 +291,7 @@ fi
296
291
 
297
292
  # ── 2. the install command ──────────────────────────────────────────────────
298
293
 
299
- step "counterparts install writes the store, the config and the credentials"
294
+ step "counterparts install writes the store and the config"
300
295
  # Verbatim, placeholder included: what the loop runs is the line the docs print,
301
296
  # down to the name a reader is told to replace.
302
297
  CMD='counterparts install --budget 9000 --name "Your Name"'
@@ -305,10 +300,10 @@ if ! doc_check "$CMD"; then
305
300
  no "not in QUICKSTART verbatim: $CMD"
306
301
  else
307
302
  INSTALL_OUT=$(eval "$CMD" 2>&1)
308
- if [ -f "$STORE/counterparts.sqlite" ] && [ -f "$BASE/claude-code.json" ] && [ -f "$BASE/credentials.env" ]; then
303
+ if [ -f "$STORE/counterparts.sqlite" ] && [ -f "$BASE/claude-code.json" ]; then
309
304
  ok
310
305
  else
311
- no "install did not produce store + config + credentials" "$INSTALL_OUT"
306
+ no "install did not produce store + config" "$INSTALL_OUT"
312
307
  fi
313
308
  fi
314
309
 
@@ -327,9 +322,8 @@ else
327
322
  if printf '%s' "$OUT" | grep -q "^Memories: "; then ok; else no "status could not open the store" "$OUT"; fi
328
323
  fi
329
324
 
330
- step "the credentials file is 0600"
331
- MODE=$(stat -f '%OLp' "$BASE/credentials.env" 2>/dev/null || stat -c '%a' "$BASE/credentials.env" 2>/dev/null)
332
- if [ "$MODE" = "600" ]; then ok; else no "credentials.env is mode ${MODE:-unknown}, not 600"; fi
325
+ step "install wrote no credentials file (the package reads no API keys)"
326
+ if [ ! -e "$BASE/credentials.env" ]; then ok; else no "install wrote $BASE/credentials.env"; fi
333
327
 
334
328
  step "install PRINTED the host's two steps and wrote no host file"
335
329
  if printf '%s' "$INSTALL_OUT" | grep -q 'claude mcp add counterparts' &&
@@ -361,9 +355,7 @@ fi
361
355
 
362
356
  step "counterparts status runs read-only against the fresh store"
363
357
  CMD='counterparts status --dir "$HOME/.counterparts/store"'
364
- if ! doc_check "$CMD"; then
365
- no "not in QUICKSTART verbatim: $CMD"
366
- else
358
+ if true; then
367
359
  BEFORE=$(find "$STORE" -type f | sort | wc -l)
368
360
  OUT=$(eval "$CMD" 2>&1)
369
361
  AFTER=$(find "$STORE" -type f | sort | wc -l)
@@ -452,28 +444,23 @@ else
452
444
  recall: $OUT2"
453
445
  fi
454
446
 
455
- step "the §7 demo DISCRIMINATES: two notes, one question, the right memory"
447
+ step "the note-and-ask demo DISCRIMINATES: two notes, one question, the right memory"
456
448
  # The one-row case (step 14) proves the store answers. It cannot prove RECALL,
457
449
  # because a store with one row returns that row to any question at all — the
458
450
  # cold-stranger review asked a one-row store about Mars and got the espresso
459
- # machine. So §7's demo is two notes and a question only one of them answers,
451
+ # machine. So this demo is two notes and a question only one of them answers,
460
452
  # and this step asserts the OTHER note stayed out of the result.
461
453
  NOTE_A='counterparts note "The espresso machine in the kitchen is a Rancilio Silvia."'
462
454
  NOTE_B='counterparts note "Postgres in dev listens on port 5433, not 5432."'
463
455
  RECALL_CMD='counterparts ask "which port does postgres use in dev?"'
464
- if ! doc_check "$NOTE_A" || ! doc_check "$NOTE_B" || ! doc_check "$RECALL_CMD"; then
465
- no "not in QUICKSTART verbatim: $NOTE_A / $NOTE_B / $RECALL_CMD"
466
- elif ! doc_check 'export COUNTERPARTS_DATA_DIR="$HOME/.counterparts/store"'; then
467
- no "the export that makes those commands work is not in QUICKSTART verbatim"
468
- else
469
- # The doc's own line, evaluated: `$HOME` is the clean room's.
456
+ if true; then
470
457
  eval 'export COUNTERPARTS_DATA_DIR="$HOME/.counterparts/store"'
471
458
  OUT=$(eval "$NOTE_A" 2>&1; eval "$NOTE_B" 2>&1)
472
459
  RECALL_OUT=$(eval "$RECALL_CMD" 2>&1)
473
460
  unset COUNTERPARTS_DATA_DIR
474
461
  if printf '%s' "$RECALL_OUT" | grep -q "port 5433" &&
475
462
  ! printf '%s' "$RECALL_OUT" | grep -q "Rancilio Silvia" &&
476
- printf '%s' "$RECALL_OUT" | grep -q "semantic embedder-off"; then
463
+ printf '%s' "$RECALL_OUT" | grep -qE "found, by meaning and words\.( The top [0-9]+:)?$"; then
477
464
  ok
478
465
  else
479
466
  no "recall did not pick the one memory that answers the question" "notes: $OUT
@@ -483,36 +470,38 @@ fi
483
470
 
484
471
  step "an answer names the TIER it came back at"
485
472
  # `answered` says the question reached something, never that it is right. The
486
- # tier is the only confidence signal there is, so it is glossed on screen.
487
- if printf '%s' "$RECALL_OUT" | grep -qE '^ (vivid|quiet|dim) = '; then
473
+ # tier is the only confidence signal there is, and `--full` glosses every tier
474
+ # on screen — and says "treat these as leads" when nothing came back vividly
475
+ # (and only then). The SHORT answer no longer says it (owner, 2026-09-24: it
476
+ # read as doubt about an answer that was right). Since `note` embeds on write,
477
+ # the demo's answer may come back vivid.
478
+ eval 'export COUNTERPARTS_DATA_DIR="$HOME/.counterparts/store"'
479
+ FULL_OUT=$(eval "$RECALL_CMD --full" 2>&1)
480
+ unset COUNTERPARTS_DATA_DIR
481
+ if printf '%s' "$FULL_OUT" | grep -q '^ vivid = '; then VIVID=1; else VIVID=0; fi
482
+ if printf '%s' "$FULL_OUT" | grep -q "treat these as leads"; then LEADS=1; else LEADS=0; fi
483
+ if printf '%s' "$FULL_OUT" | grep -qE '^ (vivid|quiet|dim) = ' && [ "$VIVID" != "$LEADS" ] &&
484
+ ! printf '%s' "$RECALL_OUT" | grep -q "treat these as leads"; then
488
485
  ok
489
486
  else
490
- no "no tier gloss under the results" "$RECALL_OUT"
487
+ no "no tier gloss under --full, its leads line disagrees with it, or the short answer still says it" "short: $RECALL_OUT
488
+ full: $FULL_OUT"
491
489
  fi
492
490
 
493
491
  step "a recall that finds nothing SAYS so, in a sentence"
494
492
  OUT=$(counterparts recall "xylophone quokka semaphore" --dir "$FIRSTSTORE" 2>&1)
495
- if printf '%s' "$OUT" | grep -q "NOTHING CAME BACK"; then ok; else no "an empty recall did not announce itself" "$OUT"; fi
493
+ if printf '%s' "$OUT" | grep -q "^Nothing found"; then ok; else no "an empty recall did not announce itself" "$OUT"; fi
496
494
 
497
- step "the §7 removal plan NAMES the span buffer, and says it will be chased"
495
+ step "the removal plan NAMES the span buffer, and says it will be chased"
498
496
  # §I2's surface, in the clean room. The dry run is all a non-interactive console
499
497
  # can reach — `remove --confirm` refuses without a prompt, which the next step
500
- # asserts — but the dry run is where the disclosure lives, and it is the line
501
- # QUICKSTART §7 quotes. Both halves are checked against the doc verbatim, so a
502
- # code change that reworded the sentence and a doc edit that did are the same
503
- # failed step.
504
- # The doc WRAPS the sentence inside its fenced block, so the lockstep is on the
505
- # two halves the wrap leaves whole — the count line and the verdict clause.
498
+ # asserts — but the dry run is where the disclosure lives.
506
499
  SPAN_COUNT="chase spans: 1"
507
500
  SPAN_TAIL="the removal strikes them out of it."
508
501
  SPAN_LINE="the raw capture buffer holds this"
509
502
  OUT=$(counterparts note "A note whose words ride the capture buffer before they are minted." --dir "$FIRSTSTORE" 2>&1)
510
503
  DOOMED=$(printf '%s\n' "$OUT" | grep -o 'mem_[0-9a-f]*' | head -1)
511
- if ! doc_check "counterparts remove " ; then
512
- no "QUICKSTART does not carry the remove command verbatim"
513
- elif ! doc_check "$SPAN_COUNT" || ! doc_check "$SPAN_TAIL" || ! doc_check "$SPAN_LINE"; then
514
- no "QUICKSTART does not quote the span-surface lines the command prints"
515
- elif [ -z "$DOOMED" ]; then
504
+ if [ -z "$DOOMED" ]; then
516
505
  no "the note printed no id to remove" "$OUT"
517
506
  else
518
507
  PLAN=$(counterparts remove "$DOOMED" --dir "$FIRSTSTORE" 2>&1)
@@ -554,11 +543,7 @@ step "the plan says WHAT it matched by, and refuses a content chase it cannot sc
554
543
  # content across every project on the machine.
555
544
  MATCHED_BY="matched by the span hash its mint recorded"
556
545
  REFUSAL="would have to visit EVERY project on this machine"
557
- if ! doc_check "$MATCHED_BY"; then
558
- no "QUICKSTART does not quote the line that says what the chase matched by"
559
- elif ! doc_check "--strike-by-content-across-scopes"; then
560
- no "QUICKSTART does not name the flag the refusal points at"
561
- elif [ -z "$DOOMED" ]; then
546
+ if [ -z "$DOOMED" ]; then
562
547
  no "no id from the earlier note"
563
548
  else
564
549
  PLAN=$(counterparts remove "$DOOMED" --dir "$FIRSTSTORE" 2>&1)
@@ -735,10 +720,14 @@ recall: $RECALLED
735
720
  $(cat "$WORK/mcp2.err")"
736
721
  fi
737
722
 
738
- step "recall says out loud that it ran without an embedder"
739
- # The no-key mode is a documented mode, not a silent one. QUICKSTART §6 quotes
740
- # this exact field; the loop is what keeps that quote true.
741
- if printf '%s' "$RECALLED" | grep -q '"semantic":"embedder-off"'; then ok; else no "recall did not report the embedder as off" "$RECALLED"; fi
723
+ step "recall embeds the question with the local table the package installed"
724
+ # KEYLESS BY DEFAULT (roadmap C3, 2026-09-23). The scripted install writes no
725
+ # embedder block, and an absent block reads as the local table
726
+ # (config.ts#resolveEmbedder). So the server embeds the question
727
+ # itself, with the weights package the global install pulled in as the one
728
+ # dependency — the keyless semantic channel, end to end, from an install. The
729
+ # field used to read `embedder-off` here; `in-line` is the channel running.
730
+ if printf '%s' "$RECALLED" | grep -q '"semantic":"in-line"'; then ok; else no "recall did not embed the question with the local table" "$RECALLED"; fi
742
731
 
743
732
  step "session_end binds LAZILY through the hooks' registry and writes the day"
744
733
  # THE FIFTH HOST BEHAVIOUR, and the only one nobody had exercised outside the
@@ -825,9 +814,7 @@ fi
825
814
 
826
815
  step "counterparts rebrief renders a wake bundle from the store"
827
816
  CMD='counterparts rebrief --dir "$HOME/.counterparts/store"'
828
- if ! doc_check "$CMD"; then
829
- no "not in QUICKSTART verbatim: $CMD"
830
- else
817
+ if true; then
831
818
  OUT=$(eval "$CMD" 2>&1)
832
819
  # It must NAME the file the ceiling came from. On the default layout that is
833
820
  # the config beside the store — the same file the hooks read.
@@ -880,9 +867,7 @@ fi
880
867
 
881
868
  step "the dashboard opens the same store"
882
869
  CMD='counterparts-dashboard status --dir "$HOME/.counterparts/store"'
883
- if ! doc_check "$CMD"; then
884
- no "not in QUICKSTART verbatim: $CMD"
885
- else
870
+ if true; then
886
871
  OUT=$(eval "$CMD" 2>&1)
887
872
  if printf '%s' "$OUT" | grep -q "What I am, right now"; then ok; else no "the dashboard did not render its status view" "$OUT"; fi
888
873
  fi
@@ -944,7 +929,7 @@ else
944
929
  no "note --help did not print note's own flags (exit $CODE)" "$OUT"
945
930
  fi
946
931
 
947
- # ── 6. which directories it remembers (QUICKSTART §8) ───────────────────────
932
+ # ── 6. which directories it remembers ───────────────────────
948
933
 
949
934
  # The scope registry is HOST configuration, beside `claude-code.json` — so these
950
935
  # steps open no store and name none, and the one that matters is the third: a
@@ -1044,7 +1029,7 @@ step "everything the run wrote is inside the clean room"
1044
1029
  # stat it to find out. Instead: every path the run produced is resolved and must
1045
1030
  # live under $WORK, and the session record must be the one in the temp store.
1046
1031
  STRAY=""
1047
- for p in "$STORE" "$BASE/claude-code.json" "$BASE/credentials.env" "$BUN_INSTALL/bin/counterparts"; do
1032
+ for p in "$STORE" "$BASE/claude-code.json" "$BUN_INSTALL/bin/counterparts"; do
1048
1033
  r=$(cd "$(dirname "$p")" 2>/dev/null && pwd -P)
1049
1034
  case "${r:-/nowhere}/" in
1050
1035
  "$WORK"/*) ;;
@@ -1053,7 +1038,7 @@ for p in "$STORE" "$BASE/claude-code.json" "$BASE/credentials.env" "$BUN_INSTALL
1053
1038
  done
1054
1039
  if [ -z "$STRAY" ] && [ -f "$STORE/sessions/$SESSION.json" ]; then ok; else no "wrote outside the clean room:${STRAY:- (no session record)}"; fi
1055
1040
 
1056
- # ── 7. the host's own files, and leaving (QUICKSTART §4a, §9b) ──────────────
1041
+ # ── 7. the host's own files, and leaving ──────────────
1057
1042
  #
1058
1043
  # THESE RUN LAST, and they have to: the last of them RENAMES `$BASE`, which is
1059
1044
  # the directory every step above resolves its paths from. The clean-room check
@@ -1151,9 +1136,7 @@ step "counterparts uninstall leaves the memory where it is, and names what remov
1151
1136
  # Re-connected first, so the plain uninstall has something to take out.
1152
1137
  counterparts connect >/dev/null 2>&1
1153
1138
  CMD='counterparts uninstall --yes'
1154
- if ! doc_check "$CMD"; then
1155
- no "not in QUICKSTART verbatim: $CMD"
1156
- else
1139
+ if true; then
1157
1140
  OUT=$(eval "$CMD" 2>&1)
1158
1141
  if [ ! -f "$STORE/counterparts.sqlite" ]; then
1159
1142
  no "the store is gone — uninstall never deletes memory by default" "$OUT"
@@ -1198,9 +1181,7 @@ step "counterparts uninstall --park moves the whole directory aside, or refuses
1198
1181
  # developer with a live install of their own gets the refusal and a bare CI box
1199
1182
  # gets the rename. The step asserts whichever one it got, in full.
1200
1183
  CMD='counterparts uninstall --park --yes'
1201
- if ! doc_check "$CMD"; then
1202
- no "not in QUICKSTART verbatim: $CMD"
1203
- else
1184
+ if true; then
1204
1185
  OUT=$(eval "$CMD" 2>&1)
1205
1186
  CODE=$?
1206
1187
  PARKED=$(ls -d "$BASE".parked-* 2>/dev/null | head -1)
@@ -1,199 +0,0 @@
1
- /**
2
- * The credential file — the ONE file the package's own configuration names.
3
- *
4
- * MEASURED, day 0 of the parallel run: this host's hook processes carry neither
5
- * `ANTHROPIC_API_KEY` nor `VOYAGE_API_KEY`, even with both exported in the
6
- * owner's `~/.zshrc`. The host's process environment is not the login shell's.
7
- * A v2 that reads `process.env` and nothing else therefore never opens the
8
- * embedder, and its worker skips the crash-fallback sweep at every boundary:
9
- * the run is blind, and blind on day 0 is a run that measured nothing.
10
- *
11
- * Until 2026-09-11 the consequence was worse than blind — `planSpawn` refused
12
- * the whole spawn on the missing key, so an EMPTY file stopped the clock, the
13
- * sleep cycle and the day's ask cap as well (I32). The worker degrades one step
14
- * at a time now; this file is still the thing that keeps it from having to.
15
- *
16
- * §2.18 is also the FIX, not just the diagnosis. The scar says a guarantee
17
- * carried by something you don't own is not a guarantee, and the CONTRACT's
18
- * rule is "credentials come from one configured source the package owns". A
19
- * file whose PATH IS NAMED IN THIS PACKAGE'S OWN CONFIG is that source. v1's
20
- * `.env`-found-by-convention is not, and stays forbidden: convention means the
21
- * process's working directory decides which credential a run uses, which is the
22
- * same class of mistake as inheriting one from whatever shell launched it.
23
- *
24
- * The rules this file mechanizes:
25
- *
26
- * - **The environment stays the FIRST source; the file fills the gap.** A
27
- * name already answered in `env` is never overwritten — so an owner who
28
- * does have the variable exported keeps exactly the behaviour they had, and
29
- * the file cannot silently redirect a live session to another account.
30
- * - **Only the two documented names are honored** (`API_KEY_ENV`,
31
- * `EMBED_KEY_ENV`). Anything else in the file is ignored and COUNTED, so a
32
- * file the owner filled with a third name reads as "1 ignored" rather than
33
- * as a general-purpose env loader nobody bounded.
34
- * - **Values are never logged, never emitted, never hashed.** Everything that
35
- * leaves this module is a NAME or a COUNT. The only place a value goes is
36
- * `env[name]`.
37
- * - **It never throws.** An absent file is ordinary; an unreadable one is a
38
- * named reason. Neither may fail a hook (CONTRACT §5 G2).
39
- */
40
- import { readFileSync, statSync } from "node:fs";
41
-
42
- import { API_KEY_ENV, EMBED_KEY_ENV } from "./config.js";
43
-
44
- /**
45
- * The ONLY names this file honors. Two, because the package documents two — a
46
- * loader that honored whatever it found would be an inherited environment with
47
- * extra steps.
48
- */
49
- export const CREDENTIAL_NAMES: readonly string[] = [API_KEY_ENV, EMBED_KEY_ENV];
50
-
51
- /** The event the entry points emit when the file actually answered. */
52
- export const CREDENTIAL_FILE_EVENT = "adapter.credentials.file";
53
-
54
- export interface CredentialLoad {
55
- /** Names this load filled FROM THE FILE. Names only — never values. */
56
- readonly loaded: string[];
57
- /** Names the file offered and `env` had already answered. The env wins. */
58
- readonly skippedPresent: string[];
59
- /** Lines that produced no credential: foreign names, malformed lines, empty
60
- * values, and repeats of a name already taken. Blank and `#` lines are not
61
- * counted — they are not attempts at anything. */
62
- readonly ignoredLines: number;
63
- readonly reason: "absent" | "unreadable" | "loaded" | "not-configured";
64
- /** The file's permission bits, octal (e.g. `"600"`). Null when unread. */
65
- readonly mode: string | null;
66
- /** True when group or other may READ this file. Reported, never refused: it
67
- * is the owner's machine and their call (§4 warn, do not refuse). */
68
- readonly permissive: boolean;
69
- }
70
-
71
- const nothing = (reason: CredentialLoad["reason"]): CredentialLoad => ({
72
- loaded: [],
73
- skippedPresent: [],
74
- ignoredLines: 0,
75
- reason,
76
- mode: null,
77
- permissive: false,
78
- });
79
-
80
- /** Present means NON-EMPTY, the same test every reader of these two names makes
81
- * (`interpret-client`, `embed-client`, `planSpawn` all `.trim()`). An exported
82
- * but empty variable is a gap the file may fill, not an answer. */
83
- function answered(value: string | undefined): boolean {
84
- return value !== undefined && value.trim().length > 0;
85
- }
86
-
87
- /**
88
- * Strip one layer of matching quotes, tolerating the shapes a human actually
89
- * writes: `KEY=v`, `KEY="v"`, `KEY='v'`, `export KEY=v`, and any of them with a
90
- * CR still attached from a CRLF file.
91
- */
92
- function unquote(raw: string): string {
93
- const value = raw.trim();
94
- if (value.length < 2) return value;
95
- const first = value[0];
96
- const last = value[value.length - 1];
97
- if ((first === '"' || first === "'") && last === first) return value.slice(1, -1);
98
- return value;
99
- }
100
-
101
- /**
102
- * Read the configured credential file and fill the gaps in `env`.
103
- *
104
- * Pure over the injected environment: it mutates `env` for the two documented
105
- * names and touches nothing else, so a test hands it `{}` and reads the result
106
- * rather than the process.
107
- */
108
- export function loadCredentials(
109
- path: string | undefined,
110
- env: NodeJS.ProcessEnv,
111
- ): CredentialLoad {
112
- if (path === undefined || path.trim().length === 0) return nothing("not-configured");
113
-
114
- let text: string;
115
- let mode: string | null = null;
116
- let permissive = false;
117
- try {
118
- const stat = statSync(path);
119
- mode = (stat.mode & 0o777).toString(8).padStart(3, "0");
120
- permissive = (stat.mode & 0o077) !== 0;
121
- text = readFileSync(path, "utf8");
122
- } catch (err) {
123
- // ENOENT is ORDINARY — an owner who exports the variables configures no
124
- // file and never sees this. Anything else (a directory, a permission
125
- // error, a device) is a different record: "we looked and could not read".
126
- const code =
127
- err !== null && typeof err === "object" && typeof (err as { code?: unknown }).code === "string"
128
- ? (err as { code: string }).code
129
- : "";
130
- return { ...nothing(code === "ENOENT" ? "absent" : "unreadable"), mode, permissive };
131
- }
132
-
133
- const loaded: string[] = [];
134
- const skippedPresent: string[] = [];
135
- let ignoredLines = 0;
136
-
137
- for (const rawLine of text.split(/\r?\n/)) {
138
- const line = rawLine.trim();
139
- if (line.length === 0 || line.startsWith("#")) continue;
140
- const body = line.startsWith("export ") ? line.slice("export ".length).trim() : line;
141
- const eq = body.indexOf("=");
142
- if (eq <= 0) {
143
- ignoredLines += 1;
144
- continue;
145
- }
146
- const name = body.slice(0, eq).trim();
147
- const value = unquote(body.slice(eq + 1));
148
- if (!CREDENTIAL_NAMES.includes(name)) {
149
- // The bound, made countable: a third name in the file is not honored, and
150
- // the count is how the owner sees that it was not.
151
- ignoredLines += 1;
152
- continue;
153
- }
154
- if (value.length === 0 || loaded.includes(name) || skippedPresent.includes(name)) {
155
- // An empty value is not a credential (writing `""` would make the
156
- // capability row say "reported" of nothing), and the FIRST occurrence of
157
- // a name wins — a second line for the same name is ignored and counted.
158
- ignoredLines += 1;
159
- continue;
160
- }
161
- if (answered(env[name])) {
162
- // THE ENVIRONMENT WINS. The file fills gaps; it never redirects a session
163
- // whose credential was already answered.
164
- skippedPresent.push(name);
165
- continue;
166
- }
167
- env[name] = value;
168
- loaded.push(name);
169
- }
170
-
171
- return { loaded, skippedPresent, ignoredLines, reason: "loaded", mode, permissive };
172
- }
173
-
174
- /**
175
- * The one line a process says about a credential file, for the ring and for
176
- * stderr. NAMES AND COUNTS ONLY — this string is emitted, so nothing that could
177
- * carry a value may enter it.
178
- */
179
- export function credentialRow(load: CredentialLoad): Record<string, string | number | boolean> {
180
- return {
181
- reason: load.reason,
182
- loaded: load.loaded.join(","),
183
- skipped: load.skippedPresent.join(","),
184
- ignoredLines: load.ignoredLines,
185
- mode: load.mode ?? "",
186
- permissive: load.permissive,
187
- };
188
- }
189
-
190
- /**
191
- * The permission warning, or null. A file the group or the world can read is
192
- * WARNED about by name and mode and never refused: it is the owner's machine,
193
- * and a refusal here would be this package deciding a security policy for them
194
- * (CONTRACT §5 G2 — and a throw would fail the host besides).
195
- */
196
- export function permissionWarning(path: string | undefined, load: CredentialLoad): string | null {
197
- if (!load.permissive || load.mode === null || path === undefined) return null;
198
- return `[counterparts] credentials file is group/other-readable (mode ${load.mode}): ${path}`;
199
- }