counterparts 0.1.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/CONSTITUTION.md +68 -0
- package/LICENSE +21 -0
- package/README.md +348 -0
- package/docs/ELI5.md +84 -0
- package/docs/QUICKSTART.md +1258 -0
- package/docs/module-map.md +81 -0
- package/package.json +63 -0
- package/src/adapters/claude-code/CONTRACT.md +606 -0
- package/src/adapters/claude-code/INTERFACE-GAPS.md +655 -0
- package/src/adapters/claude-code/NOTES.md +1055 -0
- package/src/adapters/claude-code/bin/hook.ts +820 -0
- package/src/adapters/claude-code/bin/runner.ts +522 -0
- package/src/adapters/claude-code/config.ts +778 -0
- package/src/adapters/claude-code/credentials.ts +199 -0
- package/src/adapters/claude-code/doctor.ts +2557 -0
- package/src/adapters/claude-code/embed-client.ts +617 -0
- package/src/adapters/claude-code/hooks.ts +2240 -0
- package/src/adapters/claude-code/index.ts +224 -0
- package/src/adapters/claude-code/interpret-client.ts +395 -0
- package/src/adapters/claude-code/page-writer.ts +462 -0
- package/src/adapters/claude-code/primacy.ts +162 -0
- package/src/adapters/claude-code/spawn.ts +241 -0
- package/src/adapters/claude-code/standdown.ts +536 -0
- package/src/adapters/claude-code/transcript.ts +661 -0
- package/src/adapters/claude-code/vectors.ts +415 -0
- package/src/adapters/cli/CONTRACT.md +255 -0
- package/src/adapters/cli/INTERFACE-GAPS.md +350 -0
- package/src/adapters/cli/NOTES.md +936 -0
- package/src/adapters/cli/bin/counterparts.ts +74 -0
- package/src/adapters/cli/commands.ts +6095 -0
- package/src/adapters/cli/export.ts +766 -0
- package/src/adapters/cli/index.ts +103 -0
- package/src/adapters/cli/install.ts +670 -0
- package/src/adapters/cli/removal.ts +1186 -0
- package/src/adapters/cli/repair-dates.ts +659 -0
- package/src/adapters/cli/self-page.ts +229 -0
- package/src/adapters/cli/snapshot.ts +279 -0
- package/src/adapters/cli/start-fresh.ts +1228 -0
- package/src/adapters/config-path.ts +342 -0
- package/src/adapters/dashboard/CONTRACT.md +67 -0
- package/src/adapters/dashboard/INTERFACE-GAPS.md +139 -0
- package/src/adapters/dashboard/NOTES.md +474 -0
- package/src/adapters/dashboard/activity.ts +121 -0
- package/src/adapters/dashboard/ansi.ts +82 -0
- package/src/adapters/dashboard/bin/dashboard.ts +479 -0
- package/src/adapters/dashboard/browse.ts +298 -0
- package/src/adapters/dashboard/identity.ts +182 -0
- package/src/adapters/dashboard/index.ts +183 -0
- package/src/adapters/dashboard/layout.ts +149 -0
- package/src/adapters/dashboard/registries.ts +291 -0
- package/src/adapters/dashboard/resolve.ts +206 -0
- package/src/adapters/dashboard/source.ts +48 -0
- package/src/adapters/dashboard/status.ts +327 -0
- package/src/adapters/dashboard/stories.ts +194 -0
- package/src/adapters/dashboard/web/app.html +1731 -0
- package/src/adapters/dashboard/web/brain.html +463 -0
- package/src/adapters/dashboard/web/fired.ts +31 -0
- package/src/adapters/dashboard/web/flow.ts +457 -0
- package/src/adapters/dashboard/web/narrate.ts +1042 -0
- package/src/adapters/dashboard/web/reveal.ts +135 -0
- package/src/adapters/dashboard/web/server.ts +287 -0
- package/src/adapters/dashboard/web/views.ts +1744 -0
- package/src/adapters/expansions.ts +569 -0
- package/src/adapters/fired.ts +1580 -0
- package/src/adapters/mcp/CONTRACT.md +240 -0
- package/src/adapters/mcp/INTERFACE-GAPS.md +271 -0
- package/src/adapters/mcp/NOTES.md +205 -0
- package/src/adapters/mcp/bin/serve.ts +349 -0
- package/src/adapters/mcp/deliberate.ts +619 -0
- package/src/adapters/mcp/index.ts +101 -0
- package/src/adapters/mcp/protocol.ts +170 -0
- package/src/adapters/mcp/server.ts +1740 -0
- package/src/adapters/mcp/stdio.ts +56 -0
- package/src/adapters/mcp/tools.ts +779 -0
- package/src/adapters/scopes.ts +657 -0
- package/src/adapters/sessions.ts +402 -0
- package/src/adapters/snapshots.ts +1069 -0
- package/src/adapters/stance-env.ts +137 -0
- package/src/core/associate/CONTRACT.md +118 -0
- package/src/core/associate/INTERFACE-GAPS.md +173 -0
- package/src/core/associate/NOTES.md +194 -0
- package/src/core/associate/buffer.ts +66 -0
- package/src/core/associate/edges.ts +188 -0
- package/src/core/associate/index.ts +570 -0
- package/src/core/associate/pending.ts +383 -0
- package/src/core/associate/spread.ts +149 -0
- package/src/core/associate/tunables.ts +123 -0
- package/src/core/bridge.ts +272 -0
- package/src/core/briefing.ts +67 -0
- package/src/core/counterpart.ts +3855 -0
- package/src/core/encode/CONTRACT.md +151 -0
- package/src/core/encode/INTERFACE-GAPS.md +135 -0
- package/src/core/encode/NOTES.md +146 -0
- package/src/core/encode/aliases.ts +71 -0
- package/src/core/encode/battery.ts +284 -0
- package/src/core/encode/chunk.ts +265 -0
- package/src/core/encode/emotion.ts +119 -0
- package/src/core/encode/floor.ts +76 -0
- package/src/core/encode/index.ts +100 -0
- package/src/core/encode/precision.ts +162 -0
- package/src/core/encode/preselect.ts +269 -0
- package/src/core/encode/salience.ts +108 -0
- package/src/core/encode/secrets.ts +265 -0
- package/src/core/encode/tunables.ts +99 -0
- package/src/core/encode/types.ts +286 -0
- package/src/core/encode/words.ts +75 -0
- package/src/core/handoff/CONTRACT.md +199 -0
- package/src/core/handoff/INTERFACE-GAPS.md +166 -0
- package/src/core/handoff/NOTES.md +206 -0
- package/src/core/handoff/index.ts +957 -0
- package/src/core/mint.ts +279 -0
- package/src/core/observer.ts +28 -0
- package/src/core/physics/CONTRACT.md +341 -0
- package/src/core/physics/NOTES.md +155 -0
- package/src/core/physics/clock.ts +51 -0
- package/src/core/physics/index.ts +1054 -0
- package/src/core/prospective/CONTRACT.md +137 -0
- package/src/core/prospective/INTERFACE-GAPS.md +112 -0
- package/src/core/prospective/NOTES.md +160 -0
- package/src/core/prospective/derive.ts +188 -0
- package/src/core/prospective/index.ts +1030 -0
- package/src/core/prospective/tunables.ts +72 -0
- package/src/core/prospective/windows.ts +187 -0
- package/src/core/recall/CONTRACT.md +326 -0
- package/src/core/recall/INTERFACE-GAPS.md +163 -0
- package/src/core/recall/NOTES.md +472 -0
- package/src/core/recall/activate.ts +521 -0
- package/src/core/recall/cues.ts +275 -0
- package/src/core/recall/gate.ts +441 -0
- package/src/core/recall/index.ts +692 -0
- package/src/core/recall/probe.ts +239 -0
- package/src/core/recall/reference.ts +201 -0
- package/src/core/recall/render.ts +285 -0
- package/src/core/recall/session.ts +403 -0
- package/src/core/recall/tunables.ts +329 -0
- package/src/core/remember/CONTRACT.md +293 -0
- package/src/core/remember/INTERFACE-GAPS.md +189 -0
- package/src/core/remember/NOTES.md +373 -0
- package/src/core/remember/fallback.ts +452 -0
- package/src/core/remember/index.ts +103 -0
- package/src/core/remember/owner-strike-seam.ts +479 -0
- package/src/core/remember/proposals.ts +609 -0
- package/src/core/remember/spans.ts +1310 -0
- package/src/core/remember/tunables.ts +111 -0
- package/src/core/remember/updates.ts +198 -0
- package/src/core/retrieval.ts +96 -0
- package/src/core/revision.ts +441 -0
- package/src/core/schemas/CONTRACT.md +190 -0
- package/src/core/schemas/INTERFACE-GAPS.md +172 -0
- package/src/core/schemas/NOTES.md +260 -0
- package/src/core/schemas/aliases.ts +160 -0
- package/src/core/schemas/index.ts +1459 -0
- package/src/core/schemas/tunables.ts +44 -0
- package/src/core/schemas/types.ts +387 -0
- package/src/core/self/CONTRACT.md +459 -0
- package/src/core/self/INTERFACE-GAPS.md +284 -0
- package/src/core/self/NOTES.md +1057 -0
- package/src/core/self/briefing.ts +980 -0
- package/src/core/self/episodes.ts +483 -0
- package/src/core/self/freeze.ts +103 -0
- package/src/core/self/identity.ts +604 -0
- package/src/core/self/index.ts +2130 -0
- package/src/core/self/journal-file.ts +760 -0
- package/src/core/self/page.ts +404 -0
- package/src/core/self/tunables.ts +244 -0
- package/src/core/self/writer.ts +714 -0
- package/src/core/sleep/CONTRACT.md +298 -0
- package/src/core/sleep/INTERFACE-GAPS.md +262 -0
- package/src/core/sleep/NOTES.md +770 -0
- package/src/core/sleep/briefing.ts +86 -0
- package/src/core/sleep/consolidate.ts +241 -0
- package/src/core/sleep/cycle.ts +598 -0
- package/src/core/sleep/decay.ts +237 -0
- package/src/core/sleep/dedup.ts +373 -0
- package/src/core/sleep/index.ts +112 -0
- package/src/core/sleep/log.ts +116 -0
- package/src/core/sleep/markers.ts +164 -0
- package/src/core/sleep/prune.ts +170 -0
- package/src/core/sleep/strength-cache.ts +176 -0
- package/src/core/sleep/tunables.ts +135 -0
- package/src/core/sleep/types.ts +542 -0
- package/src/core/store/CONTRACT.md +446 -0
- package/src/core/store/NOTES.md +1068 -0
- package/src/core/store/cache.ts +709 -0
- package/src/core/store/db.ts +275 -0
- package/src/core/store/errors.ts +134 -0
- package/src/core/store/index.ts +2450 -0
- package/src/core/store/operational.ts +610 -0
- package/src/core/store/owner-op-seam.ts +428 -0
- package/src/core/store/paths.ts +494 -0
- package/src/core/store/prose.ts +165 -0
- package/src/core/store/render.ts +87 -0
- package/src/core/store/walk-seam.ts +78 -0
- package/src/core/types.ts +68 -0
- package/tools/install-loop/run.sh +1063 -0
|
@@ -0,0 +1,1063 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
#
|
|
3
|
+
# The clean-room install loop.
|
|
4
|
+
#
|
|
5
|
+
# It installs Counterparts the way a stranger would — from the packed tarball,
|
|
6
|
+
# into a HOME that has never seen this project, with no repo checkout on its
|
|
7
|
+
# PATH — and then exercises the three things an install has to produce: the
|
|
8
|
+
# owner's console, a wake block out of the SessionStart hook, and a note ->
|
|
9
|
+
# recall round trip through the MCP server over stdio JSON-RPC.
|
|
10
|
+
#
|
|
11
|
+
# Two rules it enforces on itself, in this order, before anything runs:
|
|
12
|
+
#
|
|
13
|
+
# 1. **It refuses to run in the real home.** `~/.counterparts` is somebody's
|
|
14
|
+
# live memory. Every command below resolves its paths from `$HOME`, so a
|
|
15
|
+
# loop that ran with the real `$HOME` would install over it. The guard is
|
|
16
|
+
# first, it is unconditional, and there is no flag to skip it.
|
|
17
|
+
# 2. **It refuses a pre-set `COUNTERPARTS_DATA_DIR`.** cli CONTRACT §5 G3: no
|
|
18
|
+
# tool honors an inherited data-directory variable when it claims a
|
|
19
|
+
# throwaway directory. The store the loop asserts about is the store the
|
|
20
|
+
# loop made, and both sides are resolved before they are compared.
|
|
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.
|
|
30
|
+
#
|
|
31
|
+
# Usage: tools/install-loop/run.sh [workdir]
|
|
32
|
+
# Default workdir: a fresh `install-loop-<pid>` under $TMPDIR.
|
|
33
|
+
#
|
|
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
|
|
36
|
+
# checked as files and processes, never as a live session.
|
|
37
|
+
|
|
38
|
+
set -uo pipefail
|
|
39
|
+
|
|
40
|
+
REAL_HOME="$HOME"
|
|
41
|
+
REAL_PATH="$PATH"
|
|
42
|
+
REPO="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd -P)"
|
|
43
|
+
QUICKSTART="$REPO/docs/QUICKSTART.md"
|
|
44
|
+
|
|
45
|
+
# ── the guard ───────────────────────────────────────────────────────────────
|
|
46
|
+
|
|
47
|
+
WORK="${1:-${TMPDIR:-/tmp}/install-loop-$$}"
|
|
48
|
+
WORK="${WORK%/}"
|
|
49
|
+
|
|
50
|
+
if [ -z "${REAL_HOME:-}" ]; then
|
|
51
|
+
echo "REFUSED: \$HOME is unset; the guard cannot tell the real home from a temp one."
|
|
52
|
+
exit 1
|
|
53
|
+
fi
|
|
54
|
+
# BEFORE `mkdir`, on the path as GIVEN: a guard that creates the directory it is
|
|
55
|
+
# about to refuse has already written into somebody's home. Checked again below
|
|
56
|
+
# on the resolved path, because this first test cannot see through a symlink.
|
|
57
|
+
case "$WORK/" in
|
|
58
|
+
"$REAL_HOME"/*)
|
|
59
|
+
echo "REFUSED: the workdir ($WORK) is inside the real home ($REAL_HOME)."
|
|
60
|
+
echo "The loop writes a whole HOME; it may not write one inside yours."
|
|
61
|
+
exit 1
|
|
62
|
+
;;
|
|
63
|
+
esac
|
|
64
|
+
mkdir -p "$WORK" || { echo "cannot create $WORK"; exit 1; }
|
|
65
|
+
WORK="$(cd "$WORK" && pwd -P)"
|
|
66
|
+
# And again, resolved: scar §2.13 — a path guard resolves both sides before it
|
|
67
|
+
# compares, so a symlink into the home is caught too.
|
|
68
|
+
case "$WORK/" in
|
|
69
|
+
"$REAL_HOME"/*)
|
|
70
|
+
echo "REFUSED: the workdir resolves to $WORK, inside the real home ($REAL_HOME)."
|
|
71
|
+
exit 1
|
|
72
|
+
;;
|
|
73
|
+
esac
|
|
74
|
+
if [ -n "${COUNTERPARTS_DATA_DIR:-}" ]; then
|
|
75
|
+
echo "REFUSED: COUNTERPARTS_DATA_DIR is already set ($COUNTERPARTS_DATA_DIR)."
|
|
76
|
+
echo "A tool that claims a throwaway directory never honors an inherited one (cli §5 G3)."
|
|
77
|
+
exit 1
|
|
78
|
+
fi
|
|
79
|
+
if [ -n "${COUNTERPARTS_CONFIG:-}" ]; then
|
|
80
|
+
# Same rule, same reason, one level along: this variable names the file that
|
|
81
|
+
# says where the store is and whose keys to use. A clean room that inherited
|
|
82
|
+
# one would be testing somebody else's install.
|
|
83
|
+
echo "REFUSED: COUNTERPARTS_CONFIG is already set ($COUNTERPARTS_CONFIG)."
|
|
84
|
+
echo "The loop resolves its own configuration; it never honors an inherited one."
|
|
85
|
+
exit 1
|
|
86
|
+
fi
|
|
87
|
+
# UNSET, not refused, and not armed: `COUNTERPARTS_REQUIRE_EXPLICIT_DIR=1` makes
|
|
88
|
+
# the store and the config resolver refuse their `~/.counterparts` defaults
|
|
89
|
+
# (`store/paths.ts`, `adapters/config-path.ts#implicitConfigRefusal`). It is
|
|
90
|
+
# exported in every agent shell of this repo, so the loop inherits it — and
|
|
91
|
+
# inside the clean room it would fight the loop's own design: the stranger's
|
|
92
|
+
# path IS the defaults (`counterparts install` with no `--config`, the hook
|
|
93
|
+
# with no flag, `rebrief` falling back to the hooks' config), resolved in a HOME
|
|
94
|
+
# that the guards above have already made throwaway. A stranger has no such
|
|
95
|
+
# variable; the loop measures a stranger. One step below arms it on purpose,
|
|
96
|
+
# to prove the installed console and hook carry the refusal.
|
|
97
|
+
unset COUNTERPARTS_REQUIRE_EXPLICIT_DIR
|
|
98
|
+
|
|
99
|
+
FAKE_HOME="$WORK/home"
|
|
100
|
+
rm -rf "$FAKE_HOME"
|
|
101
|
+
mkdir -p "$FAKE_HOME"
|
|
102
|
+
FAKE_HOME="$(cd "$FAKE_HOME" && pwd -P)"
|
|
103
|
+
|
|
104
|
+
export HOME="$FAKE_HOME"
|
|
105
|
+
if [ "$HOME" = "$REAL_HOME" ]; then
|
|
106
|
+
echo "REFUSED: HOME did not change."
|
|
107
|
+
exit 1
|
|
108
|
+
fi
|
|
109
|
+
|
|
110
|
+
# bun is the runtime a reader is told to install; here it comes from the real
|
|
111
|
+
# home, because this machine has one bun. Its BINARY is borrowed; its HOME is
|
|
112
|
+
# not — `BUN_INSTALL` puts every installed package under the temp home, so the
|
|
113
|
+
# global install cannot reach the real one.
|
|
114
|
+
BUN_BIN="$(command -v bun || echo "$REAL_HOME/.bun/bin/bun")"
|
|
115
|
+
if [ ! -x "$BUN_BIN" ]; then
|
|
116
|
+
echo "REFUSED: no bun executable found."
|
|
117
|
+
exit 1
|
|
118
|
+
fi
|
|
119
|
+
# npm is used for ONE thing — packing the tarball — which is the maintainer's
|
|
120
|
+
# step, not the reader's. It is resolved now, from the real PATH, because the
|
|
121
|
+
# clean room's PATH deliberately has no package manager on it.
|
|
122
|
+
NPM_BIN="$(command -v npm || true)"
|
|
123
|
+
if [ ! -x "${NPM_BIN:-}" ]; then
|
|
124
|
+
echo "REFUSED: no npm executable found; the loop packs the tarball with it."
|
|
125
|
+
exit 1
|
|
126
|
+
fi
|
|
127
|
+
|
|
128
|
+
export BUN_INSTALL="$HOME/.bun"
|
|
129
|
+
# A PATH with no repo on it and no user bin dir: bun's own directory, the temp
|
|
130
|
+
# install's bin, and the system.
|
|
131
|
+
export PATH="$BUN_INSTALL/bin:$(dirname "$BUN_BIN"):/usr/bin:/bin:/usr/sbin:/sbin"
|
|
132
|
+
|
|
133
|
+
STORE="$HOME/.counterparts/store"
|
|
134
|
+
BASE="$HOME/.counterparts"
|
|
135
|
+
SESSION="install-loop-$$"
|
|
136
|
+
mkdir -p "$HOME/project"
|
|
137
|
+
|
|
138
|
+
echo "clean room"
|
|
139
|
+
echo " HOME $HOME"
|
|
140
|
+
echo " BUN_INSTALL $BUN_INSTALL"
|
|
141
|
+
echo " PATH $PATH"
|
|
142
|
+
echo " bun $("$BUN_BIN" --version)"
|
|
143
|
+
echo " repo $REPO (packed only; never on PATH)"
|
|
144
|
+
echo
|
|
145
|
+
|
|
146
|
+
# ── plumbing ────────────────────────────────────────────────────────────────
|
|
147
|
+
|
|
148
|
+
PASS=0
|
|
149
|
+
FAIL=0
|
|
150
|
+
STEP=0
|
|
151
|
+
CURRENT=""
|
|
152
|
+
STEP_T0=0
|
|
153
|
+
|
|
154
|
+
# Milliseconds. macOS `date` has no %N, so this falls back to perl and then to
|
|
155
|
+
# whole seconds rather than printing a wrong number.
|
|
156
|
+
now_ms() {
|
|
157
|
+
local n
|
|
158
|
+
n=$(date +%s%3N 2>/dev/null)
|
|
159
|
+
case "$n" in
|
|
160
|
+
*[!0-9]*|"") ;;
|
|
161
|
+
*) echo "$n"; return ;;
|
|
162
|
+
esac
|
|
163
|
+
if command -v perl >/dev/null 2>&1; then
|
|
164
|
+
perl -MTime::HiRes -e 'printf("%d", Time::HiRes::time()*1000)' && return
|
|
165
|
+
fi
|
|
166
|
+
echo $(( $(date +%s) * 1000 ))
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
step() {
|
|
170
|
+
STEP=$((STEP + 1))
|
|
171
|
+
CURRENT="$1"
|
|
172
|
+
STEP_T0=$(now_ms)
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
ok() {
|
|
176
|
+
PASS=$((PASS + 1))
|
|
177
|
+
printf 'PASS %-54s %6s ms\n' "$STEP. $CURRENT" "$(( $(now_ms) - STEP_T0 ))"
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
no() { # no <why> [output]
|
|
181
|
+
FAIL=$((FAIL + 1))
|
|
182
|
+
printf 'FAIL %-54s %6s ms\n' "$STEP. $CURRENT" "$(( $(now_ms) - STEP_T0 ))"
|
|
183
|
+
printf ' %s\n' "$1"
|
|
184
|
+
if [ -n "${2:-}" ]; then
|
|
185
|
+
printf ' --- output ---\n'
|
|
186
|
+
printf '%s\n' "$2" | sed 's/^/ /'
|
|
187
|
+
fi
|
|
188
|
+
}
|
|
189
|
+
|
|
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.
|
|
193
|
+
doc_check() {
|
|
194
|
+
grep -qF -- "$1" "$QUICKSTART"
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
# A realistic hook payload: the four fields `bin/hook.ts#toHookInput` reads.
|
|
198
|
+
payload() { # payload <event> [session id]
|
|
199
|
+
printf '{"hook_event_name":"%s","session_id":"%s","cwd":"%s","transcript_path":"%s"}' \
|
|
200
|
+
"$1" "${2:-$SESSION}" "$HOME/project" "$HOME/project/transcript.jsonl"
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
T0=$(date +%s)
|
|
204
|
+
|
|
205
|
+
# ── 1. install from the packed tarball ──────────────────────────────────────
|
|
206
|
+
|
|
207
|
+
step "npm pack produces a tarball"
|
|
208
|
+
# STDERR GOES TO A FILE, NOT INTO THE PIPE (2026-09-20, finding 5). `npm pack`
|
|
209
|
+
# prints the tarball name on stdout and its notices — npm's update banner, a
|
|
210
|
+
# workspace warning, an audit line — on stderr. With `2>&1` the two are
|
|
211
|
+
# interleaved, so `tail -1` returned whatever npm said last and the step failed
|
|
212
|
+
# about one run in five with a name that was never a file.
|
|
213
|
+
PACK_ERR="$WORK/npm-pack.stderr"
|
|
214
|
+
PACK_OUT=$(cd "$REPO" && PATH="$REAL_PATH" "$NPM_BIN" pack --pack-destination "$WORK" 2>"$PACK_ERR")
|
|
215
|
+
TARBALL=$(printf '%s\n' "$PACK_OUT" | tail -1)
|
|
216
|
+
if [ -f "$WORK/$TARBALL" ]; then
|
|
217
|
+
ok
|
|
218
|
+
else
|
|
219
|
+
no "npm pack produced no tarball" "$(printf 'stdout:\n%s\nstderr:\n%s\n' "$PACK_OUT" "$(cat "$PACK_ERR" 2>/dev/null)")"
|
|
220
|
+
fi
|
|
221
|
+
|
|
222
|
+
step "the tarball ships sources and licence, and no tests or internal tools"
|
|
223
|
+
LISTING=$(tar -tzf "$WORK/$TARBALL" 2>&1)
|
|
224
|
+
STOWAWAYS=$(printf '%s\n' "$LISTING" | grep -E '^package/(test|docs/harvest|\.claude|tools/(parallel|migrate|replay|demo|audit|recall-bench))/' || true)
|
|
225
|
+
if printf '%s\n' "$LISTING" | grep -q '^package/LICENSE$' &&
|
|
226
|
+
printf '%s\n' "$LISTING" | grep -q '^package/src/adapters/cli/bin/counterparts.ts$' &&
|
|
227
|
+
printf '%s\n' "$LISTING" | grep -q '^package/docs/QUICKSTART.md$' &&
|
|
228
|
+
[ -z "$STOWAWAYS" ]; then
|
|
229
|
+
ok
|
|
230
|
+
else
|
|
231
|
+
no "tarball contents are wrong (stowaways: ${STOWAWAYS:-none})" "$LISTING"
|
|
232
|
+
fi
|
|
233
|
+
|
|
234
|
+
step "every relative file the shipped docs link to is IN the tarball"
|
|
235
|
+
# A README that points at five files the package does not contain is a package
|
|
236
|
+
# whose own evidence is unauditable by its reader (cold-stranger review, §6.6).
|
|
237
|
+
mkdir -p "$WORK/unpacked"
|
|
238
|
+
tar -xzf "$WORK/$TARBALL" -C "$WORK/unpacked"
|
|
239
|
+
DEAD=""
|
|
240
|
+
for doc in README.md docs/QUICKSTART.md; do
|
|
241
|
+
# Links to an ABSOLUTE url are deliberate pointers at the repository and are
|
|
242
|
+
# struck out first, label and all — otherwise the backticked path inside the
|
|
243
|
+
# label reads as a broken relative reference.
|
|
244
|
+
BODY=$(sed -E 's/\[[^]]*\]\(https?:[^)]*\)//g' "$REPO/$doc")
|
|
245
|
+
# What is left: markdown links to a repo path, and backticked repo paths.
|
|
246
|
+
for ref in $(printf '%s\n' "$BODY" |
|
|
247
|
+
grep -oE '\]\((docs|tools|src)/[A-Za-z0-9._/-]+\)|`(docs|tools|src)/[A-Za-z0-9._/-]+\.(md|sh|ts)`' |
|
|
248
|
+
sed -E 's/^\]\(//; s/\)$//; s/^`//; s/`$//'); do
|
|
249
|
+
[ -e "$WORK/unpacked/package/$ref" ] || DEAD="$DEAD $doc->$ref"
|
|
250
|
+
done
|
|
251
|
+
done
|
|
252
|
+
if [ -z "$DEAD" ]; then ok; else no "shipped docs link to files not in the package:$DEAD"; fi
|
|
253
|
+
|
|
254
|
+
step "bun installs the tarball globally into the clean HOME"
|
|
255
|
+
mkdir -p "$WORK/pkg"
|
|
256
|
+
# The REAL filename npm produced, not a convenient rename: the docs tell the
|
|
257
|
+
# reader to install `counterparts-*.tgz`, and so does this.
|
|
258
|
+
cp "$WORK/$TARBALL" "$WORK/pkg/$TARBALL"
|
|
259
|
+
cd "$WORK/pkg" || exit 1
|
|
260
|
+
CMD='bun add -g "$PWD"/counterparts-*.tgz'
|
|
261
|
+
if ! doc_check "$CMD"; then
|
|
262
|
+
no "not in QUICKSTART verbatim: $CMD"
|
|
263
|
+
else
|
|
264
|
+
OUT=$(eval "$CMD" 2>&1)
|
|
265
|
+
if [ -x "$BUN_INSTALL/bin/counterparts" ]; then ok; else no "no counterparts executable after install" "$OUT"; fi
|
|
266
|
+
fi
|
|
267
|
+
|
|
268
|
+
step "the four executables are on PATH, and are the installed ones"
|
|
269
|
+
MISSING=""
|
|
270
|
+
for b in counterparts counterparts-hook counterparts-mcp counterparts-dashboard; do
|
|
271
|
+
p=$(command -v "$b" 2>/dev/null)
|
|
272
|
+
case "$p" in
|
|
273
|
+
"$BUN_INSTALL"/bin/*) ;;
|
|
274
|
+
*) MISSING="$MISSING $b(${p:-absent})" ;;
|
|
275
|
+
esac
|
|
276
|
+
done
|
|
277
|
+
if [ -z "$MISSING" ]; then ok; else no "not installed, or resolved elsewhere:$MISSING"; fi
|
|
278
|
+
|
|
279
|
+
step "the installed CLI prints its usage and EXITS 0 on --help"
|
|
280
|
+
CMD='counterparts --help'
|
|
281
|
+
if ! doc_check "$CMD"; then
|
|
282
|
+
no "not in QUICKSTART verbatim: $CMD"
|
|
283
|
+
else
|
|
284
|
+
OUT=$(eval "$CMD" 2>&1)
|
|
285
|
+
CODE=$?
|
|
286
|
+
# The second command a stranger runs. Exit 1 here kills any `set -e` wrapper
|
|
287
|
+
# and reads as a failure on the help text.
|
|
288
|
+
if [ "$CODE" = "0" ] && printf '%s' "$OUT" | grep -q "the owner's console"; then
|
|
289
|
+
ok
|
|
290
|
+
else
|
|
291
|
+
no "expected the usage and exit 0, got exit $CODE" "$OUT"
|
|
292
|
+
fi
|
|
293
|
+
fi
|
|
294
|
+
|
|
295
|
+
# ── 2. the install command ──────────────────────────────────────────────────
|
|
296
|
+
|
|
297
|
+
step "counterparts install writes the store, the config and the credentials"
|
|
298
|
+
# Verbatim, placeholder included: what the loop runs is the line the docs print,
|
|
299
|
+
# down to the name a reader is told to replace.
|
|
300
|
+
CMD='counterparts install --budget 9000 --name "Your Name"'
|
|
301
|
+
INSTALL_OUT=""
|
|
302
|
+
if ! doc_check "$CMD"; then
|
|
303
|
+
no "not in QUICKSTART verbatim: $CMD"
|
|
304
|
+
else
|
|
305
|
+
INSTALL_OUT=$(eval "$CMD" 2>&1)
|
|
306
|
+
if [ -f "$STORE/counterparts.sqlite" ] && [ -f "$BASE/claude-code.json" ] && [ -f "$BASE/credentials.env" ]; then
|
|
307
|
+
ok
|
|
308
|
+
else
|
|
309
|
+
no "install did not produce store + config + credentials" "$INSTALL_OUT"
|
|
310
|
+
fi
|
|
311
|
+
fi
|
|
312
|
+
|
|
313
|
+
step "the data dir it made is inside the clean room"
|
|
314
|
+
RESOLVED=$(cd "$STORE" 2>/dev/null && pwd -P)
|
|
315
|
+
case "${RESOLVED:-/nowhere}/" in
|
|
316
|
+
"$WORK"/*) ok ;;
|
|
317
|
+
*) no "the store resolved to ${RESOLVED:-nothing}, which is outside $WORK" ;;
|
|
318
|
+
esac
|
|
319
|
+
|
|
320
|
+
step "the config sits BESIDE the store, and the store still opens"
|
|
321
|
+
if [ -f "$STORE/claude-code.json" ]; then
|
|
322
|
+
no "the config landed INSIDE the data dir; the layout check refuses that at open"
|
|
323
|
+
else
|
|
324
|
+
OUT=$(counterparts status --dir "$STORE" 2>&1)
|
|
325
|
+
if printf '%s' "$OUT" | grep -q "^Memories: "; then ok; else no "status could not open the store" "$OUT"; fi
|
|
326
|
+
fi
|
|
327
|
+
|
|
328
|
+
step "the credentials file is 0600"
|
|
329
|
+
MODE=$(stat -f '%OLp' "$BASE/credentials.env" 2>/dev/null || stat -c '%a' "$BASE/credentials.env" 2>/dev/null)
|
|
330
|
+
if [ "$MODE" = "600" ]; then ok; else no "credentials.env is mode ${MODE:-unknown}, not 600"; fi
|
|
331
|
+
|
|
332
|
+
step "install PRINTED the host's two steps and wrote no host file"
|
|
333
|
+
if printf '%s' "$INSTALL_OUT" | grep -q 'claude mcp add counterparts' &&
|
|
334
|
+
printf '%s' "$INSTALL_OUT" | grep -q 'bin/hook.ts' &&
|
|
335
|
+
[ ! -e "$HOME/.claude/settings.json" ] && [ ! -e "$HOME/.claude.json" ]; then
|
|
336
|
+
ok
|
|
337
|
+
else
|
|
338
|
+
no "either the blocks were not printed, or a host file was written" "$INSTALL_OUT"
|
|
339
|
+
fi
|
|
340
|
+
|
|
341
|
+
step "the printed hook command runs on a PATH with no bun on it"
|
|
342
|
+
# The failure this catches is the one the rest of the loop is blind to: the loop
|
|
343
|
+
# deliberately puts bun on PATH, and a real host does not. The printed command is
|
|
344
|
+
# lifted out of install's own output and run with a system-only PATH — if it
|
|
345
|
+
# names a bare `counterparts-hook`, this is "command not found" and no memory.
|
|
346
|
+
HOOK_CMD=$(printf '%s\n' "$INSTALL_OUT" | sed -n 's/.*"command": "\(.*\)".*/\1/p' | head -1 | sed 's/\\"/"/g')
|
|
347
|
+
if [ -z "$HOOK_CMD" ]; then
|
|
348
|
+
no "no hook command found in install's output" "$INSTALL_OUT"
|
|
349
|
+
else
|
|
350
|
+
OUT=$(payload SessionStart "bunless-$$" | env -i HOME="$HOME" PATH="/usr/bin:/bin" sh -c "$HOOK_CMD" 2>"$WORK/bunless.err")
|
|
351
|
+
CODE=$?
|
|
352
|
+
if [ "$CODE" = "0" ] && printf '%s' "$OUT" | grep -q "has not lived a boundary"; then
|
|
353
|
+
ok
|
|
354
|
+
else
|
|
355
|
+
no "the printed hook command failed without bun on PATH (exit $CODE): $HOOK_CMD" "$OUT
|
|
356
|
+
$(cat "$WORK/bunless.err")"
|
|
357
|
+
fi
|
|
358
|
+
fi
|
|
359
|
+
|
|
360
|
+
step "counterparts status runs read-only against the fresh store"
|
|
361
|
+
CMD='counterparts status --dir "$HOME/.counterparts/store"'
|
|
362
|
+
if ! doc_check "$CMD"; then
|
|
363
|
+
no "not in QUICKSTART verbatim: $CMD"
|
|
364
|
+
else
|
|
365
|
+
BEFORE=$(find "$STORE" -type f | sort | wc -l)
|
|
366
|
+
OUT=$(eval "$CMD" 2>&1)
|
|
367
|
+
AFTER=$(find "$STORE" -type f | sort | wc -l)
|
|
368
|
+
if printf '%s' "$OUT" | grep -q "^Memories: " && [ "$BEFORE" = "$AFTER" ]; then ok; else no "status failed or was not a pure read" "$OUT"; fi
|
|
369
|
+
fi
|
|
370
|
+
|
|
371
|
+
# ── 3. the product, from the console ────────────────────────────────────────
|
|
372
|
+
|
|
373
|
+
# THE STRANGER'S REAL FIRST ACT, and the one the loop was blind to until round 2:
|
|
374
|
+
# a store with exactly one memory in it, asked for that memory. It failed for a
|
|
375
|
+
# day — `considered: 0` at store size one, because rarity was exactly zero when
|
|
376
|
+
# every memory in the store held the term — and it is a permanent step now, not
|
|
377
|
+
# a regression test filed away, because a bug at n=1 is invisible to every check
|
|
378
|
+
# that seeds two rows.
|
|
379
|
+
FIRSTSTORE="$WORK/first-memory-store"
|
|
380
|
+
step "the ONLY memory in a fresh store is recallable by question"
|
|
381
|
+
counterparts init --dir "$FIRSTSTORE" >/dev/null 2>&1
|
|
382
|
+
OUT=$(counterparts note "The espresso machine in the kitchen is a Rancilio Silvia." --dir "$FIRSTSTORE" 2>&1)
|
|
383
|
+
if ! printf '%s' "$OUT" | grep -q "Remembered mem_"; then
|
|
384
|
+
no "the note itself failed" "$OUT"
|
|
385
|
+
else
|
|
386
|
+
OUT=$(counterparts recall "what espresso machine is in the kitchen?" --dir "$FIRSTSTORE" 2>&1)
|
|
387
|
+
if printf '%s' "$OUT" | grep -q "Rancilio Silvia"; then
|
|
388
|
+
ok
|
|
389
|
+
else
|
|
390
|
+
no "the store's only memory did not come back (storeSize==1 regression)" "$OUT"
|
|
391
|
+
fi
|
|
392
|
+
fi
|
|
393
|
+
|
|
394
|
+
step "a mistyped --dir is REFUSED, and the note does not land somewhere else"
|
|
395
|
+
# The critical finding of 2026-09-04, as a step. `note "…" --dirr <store2>` used
|
|
396
|
+
# to print `Remembered mem_… — minted.` while store2 stayed empty and the DEFAULT
|
|
397
|
+
# store took the words — which on a real machine is the owner's live memory. The
|
|
398
|
+
# assertion is in three parts: the command refuses, it names the flag, and NO
|
|
399
|
+
# store anywhere grew a memory.
|
|
400
|
+
BEFORE_DEFAULT=$(counterparts status --dir "$STORE" 2>/dev/null | sed -n 's/^Memories: \([0-9]*\).*/\1/p' | head -1)
|
|
401
|
+
OUT=$(counterparts note "This must not land anywhere." --dirr "$FIRSTSTORE" 2>&1)
|
|
402
|
+
CODE=$?
|
|
403
|
+
AFTER_DEFAULT=$(counterparts status --dir "$STORE" 2>/dev/null | sed -n 's/^Memories: \([0-9]*\).*/\1/p' | head -1)
|
|
404
|
+
if [ "$CODE" = "2" ] &&
|
|
405
|
+
printf '%s' "$OUT" | grep -q "unknown flag --dirr" &&
|
|
406
|
+
printf '%s' "$OUT" | grep -q "did you mean --dir?" &&
|
|
407
|
+
[ "$BEFORE_DEFAULT" = "$AFTER_DEFAULT" ]; then
|
|
408
|
+
ok
|
|
409
|
+
else
|
|
410
|
+
no "a mistyped --dir was not refused, or something was written (exit $CODE, live $BEFORE_DEFAULT -> $AFTER_DEFAULT)" "$OUT"
|
|
411
|
+
fi
|
|
412
|
+
|
|
413
|
+
step "COUNTERPARTS_REQUIRE_EXPLICIT_DIR=1 refuses an UNNAMED store and an UNNAMED config"
|
|
414
|
+
# LAUNCH-STATUS I21, through the installed binaries rather than the source: an
|
|
415
|
+
# agent's shell on a machine with an install exports this, and a command that
|
|
416
|
+
# names no store must then refuse by name — before any open — rather than reach
|
|
417
|
+
# `$HOME/.counterparts/store`. Three parts: the console refuses and names the
|
|
418
|
+
# guard and the remedy; the hook stands down for the same reason (the default
|
|
419
|
+
# config NAMES a store); and neither wrote a thing — the sessions count is the
|
|
420
|
+
# tripwire. The loop's own environment stays unarmed (see the guard block).
|
|
421
|
+
BEFORE_SESSIONS=$(ls "$STORE/sessions" 2>/dev/null | wc -l | tr -d ' ')
|
|
422
|
+
OUT=$(COUNTERPARTS_REQUIRE_EXPLICIT_DIR=1 counterparts status 2>&1)
|
|
423
|
+
CODE=$?
|
|
424
|
+
HOOK_OUT=$(payload SessionStart "install-loop-guard-$$" | COUNTERPARTS_REQUIRE_EXPLICIT_DIR=1 counterparts-hook 2>"$WORK/hook-guard.err")
|
|
425
|
+
HOOK_CODE=$?
|
|
426
|
+
AFTER_SESSIONS=$(ls "$STORE/sessions" 2>/dev/null | wc -l | tr -d ' ')
|
|
427
|
+
if [ "$CODE" = "2" ] &&
|
|
428
|
+
printf '%s' "$OUT" | grep -q "COUNTERPARTS_REQUIRE_EXPLICIT_DIR=1" &&
|
|
429
|
+
printf '%s' "$OUT" | grep -q "$STORE" &&
|
|
430
|
+
printf '%s' "$OUT" | grep -q -- "--dir" &&
|
|
431
|
+
[ "$HOOK_CODE" = "0" ] && [ -z "$HOOK_OUT" ] &&
|
|
432
|
+
grep -q "stood down" "$WORK/hook-guard.err" &&
|
|
433
|
+
grep -q "COUNTERPARTS_REQUIRE_EXPLICIT_DIR=1" "$WORK/hook-guard.err" &&
|
|
434
|
+
[ "$BEFORE_SESSIONS" = "$AFTER_SESSIONS" ]; then
|
|
435
|
+
ok
|
|
436
|
+
else
|
|
437
|
+
no "the guard did not refuse the unnamed default (console exit $CODE, hook exit $HOOK_CODE, sessions $BEFORE_SESSIONS -> $AFTER_SESSIONS)" "$OUT
|
|
438
|
+
$HOOK_OUT
|
|
439
|
+
$(cat "$WORK/hook-guard.err")"
|
|
440
|
+
fi
|
|
441
|
+
|
|
442
|
+
step "note and recall NAME the store they wrote to or read from"
|
|
443
|
+
OUT=$(counterparts note "A memory that says where it went." --dir "$FIRSTSTORE" 2>&1)
|
|
444
|
+
OUT2=$(counterparts recall "where did it go?" --dir "$FIRSTSTORE" 2>&1)
|
|
445
|
+
if printf '%s\n' "$OUT" | head -1 | grep -q "^Store: $FIRSTSTORE$" &&
|
|
446
|
+
printf '%s\n' "$OUT2" | head -1 | grep -q "^Store: $FIRSTSTORE$"; then
|
|
447
|
+
ok
|
|
448
|
+
else
|
|
449
|
+
no "the destination was not the first line" "note: $OUT
|
|
450
|
+
recall: $OUT2"
|
|
451
|
+
fi
|
|
452
|
+
|
|
453
|
+
step "the §7 demo DISCRIMINATES: two notes, one question, the right memory"
|
|
454
|
+
# The one-row case (step 14) proves the store answers. It cannot prove RECALL,
|
|
455
|
+
# because a store with one row returns that row to any question at all — the
|
|
456
|
+
# cold-stranger review asked a one-row store about Mars and got the espresso
|
|
457
|
+
# machine. So §7's demo is two notes and a question only one of them answers,
|
|
458
|
+
# and this step asserts the OTHER note stayed out of the result.
|
|
459
|
+
NOTE_A='counterparts note "The espresso machine in the kitchen is a Rancilio Silvia."'
|
|
460
|
+
NOTE_B='counterparts note "Postgres in dev listens on port 5433, not 5432."'
|
|
461
|
+
RECALL_CMD='counterparts recall "which port does postgres use in dev?"'
|
|
462
|
+
if ! doc_check "$NOTE_A" || ! doc_check "$NOTE_B" || ! doc_check "$RECALL_CMD"; then
|
|
463
|
+
no "not in QUICKSTART verbatim: $NOTE_A / $NOTE_B / $RECALL_CMD"
|
|
464
|
+
elif ! doc_check 'export COUNTERPARTS_DATA_DIR="$HOME/.counterparts/store"'; then
|
|
465
|
+
no "the export that makes those commands work is not in QUICKSTART verbatim"
|
|
466
|
+
else
|
|
467
|
+
# The doc's own line, evaluated: `$HOME` is the clean room's.
|
|
468
|
+
eval 'export COUNTERPARTS_DATA_DIR="$HOME/.counterparts/store"'
|
|
469
|
+
OUT=$(eval "$NOTE_A" 2>&1; eval "$NOTE_B" 2>&1)
|
|
470
|
+
RECALL_OUT=$(eval "$RECALL_CMD" 2>&1)
|
|
471
|
+
unset COUNTERPARTS_DATA_DIR
|
|
472
|
+
if printf '%s' "$RECALL_OUT" | grep -q "port 5433" &&
|
|
473
|
+
! printf '%s' "$RECALL_OUT" | grep -q "Rancilio Silvia" &&
|
|
474
|
+
printf '%s' "$RECALL_OUT" | grep -q "semantic embedder-off"; then
|
|
475
|
+
ok
|
|
476
|
+
else
|
|
477
|
+
no "recall did not pick the one memory that answers the question" "notes: $OUT
|
|
478
|
+
recall: $RECALL_OUT"
|
|
479
|
+
fi
|
|
480
|
+
fi
|
|
481
|
+
|
|
482
|
+
step "an answer names the TIER it came back at"
|
|
483
|
+
# `answered` says the question reached something, never that it is right. The
|
|
484
|
+
# tier is the only confidence signal there is, so it is glossed on screen.
|
|
485
|
+
if printf '%s' "$RECALL_OUT" | grep -qE '^ (vivid|quiet|dim) = '; then
|
|
486
|
+
ok
|
|
487
|
+
else
|
|
488
|
+
no "no tier gloss under the results" "$RECALL_OUT"
|
|
489
|
+
fi
|
|
490
|
+
|
|
491
|
+
step "a recall that finds nothing SAYS so, in a sentence"
|
|
492
|
+
OUT=$(counterparts recall "xylophone quokka semaphore" --dir "$FIRSTSTORE" 2>&1)
|
|
493
|
+
if printf '%s' "$OUT" | grep -q "NOTHING CAME BACK"; then ok; else no "an empty recall did not announce itself" "$OUT"; fi
|
|
494
|
+
|
|
495
|
+
step "the §7 removal plan NAMES the span buffer, and says it will be chased"
|
|
496
|
+
# §I2's surface, in the clean room. The dry run is all a non-interactive console
|
|
497
|
+
# can reach — `remove --confirm` refuses without a prompt, which the next step
|
|
498
|
+
# asserts — but the dry run is where the disclosure lives, and it is the line
|
|
499
|
+
# QUICKSTART §7 quotes. Both halves are checked against the doc verbatim, so a
|
|
500
|
+
# code change that reworded the sentence and a doc edit that did are the same
|
|
501
|
+
# failed step.
|
|
502
|
+
# The doc WRAPS the sentence inside its fenced block, so the lockstep is on the
|
|
503
|
+
# two halves the wrap leaves whole — the count line and the verdict clause.
|
|
504
|
+
SPAN_COUNT="chase spans: 1"
|
|
505
|
+
SPAN_TAIL="the removal strikes them out of it."
|
|
506
|
+
SPAN_LINE="the raw capture buffer holds this"
|
|
507
|
+
OUT=$(counterparts note "A note whose words ride the capture buffer before they are minted." --dir "$FIRSTSTORE" 2>&1)
|
|
508
|
+
DOOMED=$(printf '%s\n' "$OUT" | grep -o 'mem_[0-9a-f]*' | head -1)
|
|
509
|
+
if ! doc_check "counterparts remove " ; then
|
|
510
|
+
no "QUICKSTART does not carry the remove command verbatim"
|
|
511
|
+
elif ! doc_check "$SPAN_COUNT" || ! doc_check "$SPAN_TAIL" || ! doc_check "$SPAN_LINE"; then
|
|
512
|
+
no "QUICKSTART does not quote the span-surface lines the command prints"
|
|
513
|
+
elif [ -z "$DOOMED" ]; then
|
|
514
|
+
no "the note printed no id to remove" "$OUT"
|
|
515
|
+
else
|
|
516
|
+
PLAN=$(counterparts remove "$DOOMED" --dir "$FIRSTSTORE" 2>&1)
|
|
517
|
+
if printf '%s' "$PLAN" | grep -qF "$SPAN_COUNT" &&
|
|
518
|
+
printf '%s' "$PLAN" | grep -qF "chased — spans/" &&
|
|
519
|
+
printf '%s' "$PLAN" | grep -qF "$SPAN_LINE" &&
|
|
520
|
+
printf '%s' "$PLAN" | grep -qF "$SPAN_TAIL" &&
|
|
521
|
+
printf '%s' "$PLAN" | grep -q "Dry run. Nothing has changed."; then
|
|
522
|
+
ok
|
|
523
|
+
else
|
|
524
|
+
no "the plan did not name the buffer as a chased surface" "$PLAN"
|
|
525
|
+
fi
|
|
526
|
+
fi
|
|
527
|
+
|
|
528
|
+
step "remove --confirm REFUSES without an interactive prompt, and nothing moves"
|
|
529
|
+
# Its OWN note and its own id: a step that borrows the previous step's variable
|
|
530
|
+
# reports a false pass when that step failed before setting it.
|
|
531
|
+
OUT=$(counterparts note "A second note, taken so this step owns the id it removes." --dir "$FIRSTSTORE" 2>&1)
|
|
532
|
+
TARGET=$(printf '%s\n' "$OUT" | grep -o 'mem_[0-9a-f]*' | head -1)
|
|
533
|
+
if [ -z "$TARGET" ]; then
|
|
534
|
+
no "the note printed no id to remove" "$OUT"
|
|
535
|
+
else
|
|
536
|
+
BEFORE=$(counterparts status --dir "$FIRSTSTORE" 2>&1)
|
|
537
|
+
OUT=$(counterparts remove "$TARGET" --confirm --dir "$FIRSTSTORE" 2>&1)
|
|
538
|
+
RC=$?
|
|
539
|
+
AFTER=$(counterparts status --dir "$FIRSTSTORE" 2>&1)
|
|
540
|
+
if [ "$RC" -ne 0 ] &&
|
|
541
|
+
printf '%s' "$OUT" | grep -q "interactive confirmation" &&
|
|
542
|
+
[ "$BEFORE" = "$AFTER" ]; then
|
|
543
|
+
ok
|
|
544
|
+
else
|
|
545
|
+
no "a non-interactive --confirm did not refuse cleanly (rc=$RC)" "$OUT"
|
|
546
|
+
fi
|
|
547
|
+
fi
|
|
548
|
+
|
|
549
|
+
step "the plan says WHAT it matched by, and refuses a content chase it cannot scope"
|
|
550
|
+
# The two disclosures the adversarial review made blocking: the plan names the
|
|
551
|
+
# evidence it is acting on, and a memory with no recorded scope is NOT chased by
|
|
552
|
+
# content across every project on the machine.
|
|
553
|
+
MATCHED_BY="matched by the span hash its mint recorded"
|
|
554
|
+
REFUSAL="would have to visit EVERY project on this machine"
|
|
555
|
+
if ! doc_check "$MATCHED_BY"; then
|
|
556
|
+
no "QUICKSTART does not quote the line that says what the chase matched by"
|
|
557
|
+
elif ! doc_check "--strike-by-content-across-scopes"; then
|
|
558
|
+
no "QUICKSTART does not name the flag the refusal points at"
|
|
559
|
+
elif [ -z "$DOOMED" ]; then
|
|
560
|
+
no "no id from the earlier note"
|
|
561
|
+
else
|
|
562
|
+
PLAN=$(counterparts remove "$DOOMED" --dir "$FIRSTSTORE" 2>&1)
|
|
563
|
+
if printf '%s' "$PLAN" | grep -qF "$MATCHED_BY"; then ok; else no "the plan did not say what it matched by" "$PLAN"; fi
|
|
564
|
+
fi
|
|
565
|
+
|
|
566
|
+
# ── 4. the SessionStart hook ────────────────────────────────────────────────
|
|
567
|
+
|
|
568
|
+
step "SessionStart returns the honest bootstrap line on a store that never woke"
|
|
569
|
+
OUT=$(payload SessionStart | counterparts-hook 2>"$WORK/hook.err")
|
|
570
|
+
HOOK_CODE=$?
|
|
571
|
+
if [ "$HOOK_CODE" = "0" ] && printf '%s' "$OUT" | grep -q "has not lived a boundary"; then
|
|
572
|
+
ok
|
|
573
|
+
else
|
|
574
|
+
no "expected the bootstrap line and exit 0 (got exit $HOOK_CODE)" "$OUT
|
|
575
|
+
$(cat "$WORK/hook.err")"
|
|
576
|
+
fi
|
|
577
|
+
|
|
578
|
+
step "the hook registered the session under <dataDir>/sessions/"
|
|
579
|
+
if [ -f "$STORE/sessions/$SESSION.json" ]; then ok; else no "no session record at $STORE/sessions/$SESSION.json"; fi
|
|
580
|
+
|
|
581
|
+
# THE STEP NOBODY COULD RUN BEFORE. Until the one-config rule (2026-09-05) the
|
|
582
|
+
# hook read `$HOME/.counterparts/claude-code.json` and took no flag, so the only
|
|
583
|
+
# way to drive it at another store was to move a whole HOME — which is what this
|
|
584
|
+
# loop does and what a machine with an existing install cannot. With `--config`
|
|
585
|
+
# the hook is redirectable like every other entry point, and the assertion is in
|
|
586
|
+
# three parts: it worked on the named store, it RECORDED which file sent it
|
|
587
|
+
# there, and the clean room's own default store never heard of the session.
|
|
588
|
+
SECOND_BASE="$WORK/second-install"
|
|
589
|
+
SECOND_STORE="$SECOND_BASE/store"
|
|
590
|
+
SECOND_CONFIG="$SECOND_BASE/claude-code.json"
|
|
591
|
+
SECOND_SESSION="install-loop-second-$$"
|
|
592
|
+
mkdir -p "$SECOND_BASE"
|
|
593
|
+
printf '{\n "dataDir": "%s",\n "injectionBudgetBytes": 9000\n}\n' "$SECOND_STORE" > "$SECOND_CONFIG"
|
|
594
|
+
|
|
595
|
+
step "counterparts-hook --config drives the hook at a SECOND store"
|
|
596
|
+
OUT=$(payload SessionStart "$SECOND_SESSION" | counterparts-hook --config "$SECOND_CONFIG" 2>"$WORK/hook-config.err")
|
|
597
|
+
CODE=$?
|
|
598
|
+
if [ "$CODE" != "0" ] || ! printf '%s' "$OUT" | grep -q "has not lived a boundary"; then
|
|
599
|
+
no "the hook did not run against the named config (exit $CODE)" "$OUT
|
|
600
|
+
$(cat "$WORK/hook-config.err")"
|
|
601
|
+
elif [ ! -f "$SECOND_STORE/sessions/$SECOND_SESSION.json" ]; then
|
|
602
|
+
no "no session record under the named store at $SECOND_STORE/sessions/$SECOND_SESSION.json"
|
|
603
|
+
elif ! grep -q "$SECOND_CONFIG" "$SECOND_STORE/sessions/$SECOND_SESSION.json"; then
|
|
604
|
+
# A hook cannot print to the owner — its stdout is the model's context — so
|
|
605
|
+
# the durable answer to "which config was that?" is this field.
|
|
606
|
+
no "the session record does not name the config it read" "$(cat "$SECOND_STORE/sessions/$SECOND_SESSION.json")"
|
|
607
|
+
elif [ -f "$STORE/sessions/$SECOND_SESSION.json" ]; then
|
|
608
|
+
no "the DEFAULT store also got a record for that session — the flag did not redirect"
|
|
609
|
+
else
|
|
610
|
+
ok
|
|
611
|
+
fi
|
|
612
|
+
|
|
613
|
+
step "an absolute --config that is NOT THERE stands the hook down too"
|
|
614
|
+
# The hole the PR's own review found: an absolute path to a file that does not
|
|
615
|
+
# exist was honoured silently — read as an absent config, resolved to observer,
|
|
616
|
+
# and then fallen through to the default data dir, which on a machine with an
|
|
617
|
+
# install is the live store. A typo in the one flag that says WHICH MEMORY has
|
|
618
|
+
# to be as loud as a typo in --dir already is.
|
|
619
|
+
BEFORE_SESSIONS=$(ls "$STORE/sessions" 2>/dev/null | wc -l | tr -d ' ')
|
|
620
|
+
OUT=$(payload SessionStart "install-loop-missing-$$" | counterparts-hook --config "$WORK/nowhere/claude-code.json" 2>"$WORK/hook-missing.err")
|
|
621
|
+
CODE=$?
|
|
622
|
+
AFTER_SESSIONS=$(ls "$STORE/sessions" 2>/dev/null | wc -l | tr -d ' ')
|
|
623
|
+
# STDOUT CARRIES A NOTICE AND NO CONTEXT, since H1 (`30a9b91`, 2026-09-18): a
|
|
624
|
+
# stand-down that is a FAULT says so where the owner will see it. This step used
|
|
625
|
+
# to demand an empty stdout and has been failing ever since; the property it
|
|
626
|
+
# guards is unchanged and one clause stronger — nothing is injected, and the
|
|
627
|
+
# terminal is told why. `additionalContext` is what must not be there.
|
|
628
|
+
if [ "$CODE" = "0" ] &&
|
|
629
|
+
! printf '%s' "$OUT" | grep -q "additionalContext" &&
|
|
630
|
+
printf '%s' "$OUT" | grep -q "memory is OFF for this session" &&
|
|
631
|
+
grep -q "stood down" "$WORK/hook-missing.err" &&
|
|
632
|
+
grep -q "could not be read" "$WORK/hook-missing.err" &&
|
|
633
|
+
[ ! -e "$WORK/nowhere" ] &&
|
|
634
|
+
[ "$BEFORE_SESSIONS" = "$AFTER_SESSIONS" ]; then
|
|
635
|
+
ok
|
|
636
|
+
else
|
|
637
|
+
no "a missing --config was not a clean stand-down (exit $CODE, sessions $BEFORE_SESSIONS -> $AFTER_SESSIONS)" "$OUT
|
|
638
|
+
$(cat "$WORK/hook-missing.err")"
|
|
639
|
+
fi
|
|
640
|
+
|
|
641
|
+
step "a relative --config STANDS THE HOOK DOWN rather than using the default store"
|
|
642
|
+
# The failure direction that matters: an entry point told to use a config it
|
|
643
|
+
# cannot honour must not quietly fall back, because on a real machine the
|
|
644
|
+
# default is somebody's live memory. Exit 0 all the same — a hook never fails
|
|
645
|
+
# the host — and nothing INJECTED, which since H1 is the honest test rather
|
|
646
|
+
# than an empty stdout (see the step above).
|
|
647
|
+
BEFORE_SESSIONS=$(ls "$STORE/sessions" 2>/dev/null | wc -l | tr -d ' ')
|
|
648
|
+
OUT=$(payload SessionStart "install-loop-relative-$$" | counterparts-hook --config claude-code.json 2>"$WORK/hook-relative.err")
|
|
649
|
+
CODE=$?
|
|
650
|
+
AFTER_SESSIONS=$(ls "$STORE/sessions" 2>/dev/null | wc -l | tr -d ' ')
|
|
651
|
+
if [ "$CODE" = "0" ] &&
|
|
652
|
+
! printf '%s' "$OUT" | grep -q "additionalContext" &&
|
|
653
|
+
printf '%s' "$OUT" | grep -q "memory is OFF for this session" &&
|
|
654
|
+
grep -q "stood down" "$WORK/hook-relative.err" &&
|
|
655
|
+
[ "$BEFORE_SESSIONS" = "$AFTER_SESSIONS" ]; then
|
|
656
|
+
ok
|
|
657
|
+
else
|
|
658
|
+
no "a relative --config was not a clean stand-down (exit $CODE, sessions $BEFORE_SESSIONS -> $AFTER_SESSIONS)" "$OUT
|
|
659
|
+
$(cat "$WORK/hook-relative.err")"
|
|
660
|
+
fi
|
|
661
|
+
|
|
662
|
+
# THE DAY-0 WAKE. The finding (LAUNCH-STATUS round 2, self/NOTES §11): `install
|
|
663
|
+
# --name` seeds an identity core that no lane could reach — `scanActive` lists
|
|
664
|
+
# `{ type: "memory" }` and the core is a schema row — so the first composed wake
|
|
665
|
+
# was 385 bytes of furniture that named nobody, over a store whose one live row
|
|
666
|
+
# was the stranger's own name.
|
|
667
|
+
step "the first composed wake has an empty identity lane and zero elements"
|
|
668
|
+
OUT=$(counterparts rebrief --dir "$HOME/.counterparts/store" 2>&1)
|
|
669
|
+
if printf '%s' "$OUT" | grep -q "Re-rendered the wake bundle" &&
|
|
670
|
+
printf '%s' "$OUT" | grep -q "identity 0" &&
|
|
671
|
+
printf '%s' "$OUT" | grep -q "elements 0"; then
|
|
672
|
+
ok
|
|
673
|
+
else
|
|
674
|
+
no "the first rebrief declined, or ranked an identity element it should not have" "$OUT"
|
|
675
|
+
fi
|
|
676
|
+
|
|
677
|
+
step "SessionStart injects it, and an empty identity lane still names the core"
|
|
678
|
+
OUT=$(payload SessionStart | counterparts-hook 2>"$WORK/hook-day0.err")
|
|
679
|
+
if printf '%s' "$OUT" | grep -q "has not lived a boundary"; then
|
|
680
|
+
no "still the bootstrap line after a rebrief" "$OUT"
|
|
681
|
+
elif printf '%s' "$OUT" | grep -q "Who I am:" &&
|
|
682
|
+
printf '%s' "$OUT" | grep -q "This memory is for Your Name" &&
|
|
683
|
+
printf '%s' "$OUT" | grep -q "identity=0"; then
|
|
684
|
+
ok
|
|
685
|
+
else
|
|
686
|
+
no "the wake did not name the core the install seeded" "$OUT
|
|
687
|
+
$(cat "$WORK/hook-day0.err")"
|
|
688
|
+
fi
|
|
689
|
+
|
|
690
|
+
# ── 5. the MCP round trip ───────────────────────────────────────────────────
|
|
691
|
+
|
|
692
|
+
CANARY="The install loop canary: the espresso machine in the kitchen is a Rancilio Silvia."
|
|
693
|
+
|
|
694
|
+
step "the MCP server handshakes over stdio JSON-RPC and declares its tools"
|
|
695
|
+
RPC=$(
|
|
696
|
+
printf '%s\n' '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{}}}'
|
|
697
|
+
printf '%s\n' '{"jsonrpc":"2.0","method":"notifications/initialized"}'
|
|
698
|
+
printf '%s\n' '{"jsonrpc":"2.0","id":2,"method":"tools/list"}'
|
|
699
|
+
)
|
|
700
|
+
# `printf '%s\n'`, not `%s`: command substitution strips the trailing newline,
|
|
701
|
+
# and the server's framer holds an unterminated final line rather than parsing
|
|
702
|
+
# it — so a missing newline silently drops the last request.
|
|
703
|
+
MCP_OUT=$(printf '%s\n' "$RPC" | COUNTERPARTS_DATA_DIR="$STORE" counterparts-mcp 2>"$WORK/mcp.err")
|
|
704
|
+
if printf '%s' "$MCP_OUT" | grep -q '"serverInfo"' && printf '%s' "$MCP_OUT" | grep -q '"recall"'; then
|
|
705
|
+
ok
|
|
706
|
+
else
|
|
707
|
+
no "no handshake, or no tools declared" "$MCP_OUT
|
|
708
|
+
$(cat "$WORK/mcp.err")"
|
|
709
|
+
fi
|
|
710
|
+
|
|
711
|
+
step "note then recall round-trips through the MCP server"
|
|
712
|
+
# The canary is deliberately plain ASCII with no quotes or backslashes, so it
|
|
713
|
+
# needs no JSON escaping to be embedded here.
|
|
714
|
+
NOTE_PARAMS=$(printf '{"name":"note","arguments":{"text":"%s"}}' "$CANARY")
|
|
715
|
+
RECALL_PARAMS='{"name":"recall","arguments":{"question":"what espresso machine is in the kitchen?"}}'
|
|
716
|
+
RPC=$(
|
|
717
|
+
printf '%s\n' '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{}}}'
|
|
718
|
+
printf '%s\n' '{"jsonrpc":"2.0","method":"notifications/initialized"}'
|
|
719
|
+
printf '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":%s}\n' "$NOTE_PARAMS"
|
|
720
|
+
printf '{"jsonrpc":"2.0","id":3,"method":"tools/call","params":%s}\n' "$RECALL_PARAMS"
|
|
721
|
+
)
|
|
722
|
+
MCP_OUT=$(printf '%s\n' "$RPC" | COUNTERPARTS_DATA_DIR="$STORE" counterparts-mcp 2>"$WORK/mcp2.err")
|
|
723
|
+
printf '%s' "$MCP_OUT" > "$WORK/mcp-roundtrip.jsonl"
|
|
724
|
+
NOTED=$(printf '%s\n' "$MCP_OUT" | grep '"id":2' || true)
|
|
725
|
+
RECALLED=$(printf '%s\n' "$MCP_OUT" | grep '"id":3' || true)
|
|
726
|
+
if printf '%s' "$NOTED" | grep -q '"isError":true'; then
|
|
727
|
+
no "the note was refused" "$NOTED"
|
|
728
|
+
elif printf '%s' "$RECALLED" | grep -q 'Rancilio Silvia'; then
|
|
729
|
+
ok
|
|
730
|
+
else
|
|
731
|
+
no "recall did not return the note" "note: $NOTED
|
|
732
|
+
recall: $RECALLED
|
|
733
|
+
$(cat "$WORK/mcp2.err")"
|
|
734
|
+
fi
|
|
735
|
+
|
|
736
|
+
step "recall says out loud that it ran without an embedder"
|
|
737
|
+
# The no-key mode is a documented mode, not a silent one. QUICKSTART §6 quotes
|
|
738
|
+
# this exact field; the loop is what keeps that quote true.
|
|
739
|
+
if printf '%s' "$RECALLED" | grep -q '"semantic":"embedder-off"'; then ok; else no "recall did not report the embedder as off" "$RECALLED"; fi
|
|
740
|
+
|
|
741
|
+
step "session_end binds LAZILY through the hooks' registry and writes the day"
|
|
742
|
+
# THE FIFTH HOST BEHAVIOUR, and the only one nobody had exercised outside the
|
|
743
|
+
# owner's machine. Claude Code launches MCP servers from a static configuration,
|
|
744
|
+
# so the server never receives `--session`; the hooks know the id and leave a
|
|
745
|
+
# record at <dataDir>/sessions/<id>.json, and the server binds to it on the first
|
|
746
|
+
# claim. Until now this loop asserted only that the RECORD exists — the thing the
|
|
747
|
+
# bind reads, not the bind — and the docs claimed more than that.
|
|
748
|
+
#
|
|
749
|
+
# Two things have to line up for a bind: the id must be live in the registry (the
|
|
750
|
+
# SessionStart step above wrote it), and the session's scope must match this
|
|
751
|
+
# server's. The hook recorded the payload's cwd, so the server is told the same
|
|
752
|
+
# scope rather than being run from that directory.
|
|
753
|
+
SESSION_END_PARAMS=$(printf '{"name":"session_end","arguments":{"session":"%s","memories":[{"content":"%s"}]}}' \
|
|
754
|
+
"$SESSION" "The install loop proved the lazy session bind end to end.")
|
|
755
|
+
RPC=$(
|
|
756
|
+
printf '%s\n' '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{}}}'
|
|
757
|
+
printf '%s\n' '{"jsonrpc":"2.0","method":"notifications/initialized"}'
|
|
758
|
+
printf '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":%s}\n' "$SESSION_END_PARAMS"
|
|
759
|
+
)
|
|
760
|
+
MCP_OUT=$(printf '%s\n' "$RPC" |
|
|
761
|
+
COUNTERPARTS_DATA_DIR="$STORE" COUNTERPARTS_SCOPE="$HOME/project" counterparts-mcp 2>"$WORK/mcp3.err")
|
|
762
|
+
printf '%s' "$MCP_OUT" > "$WORK/mcp-session-end.jsonl"
|
|
763
|
+
ENDED=$(printf '%s\n' "$MCP_OUT" | grep '"id":2' || true)
|
|
764
|
+
# The refusals this step exists to catch, by name: a server that could not find
|
|
765
|
+
# the record says `session-unknown`; one in the wrong project says
|
|
766
|
+
# `scope-mismatch`; one that was never told an id says `session-required`.
|
|
767
|
+
if printf '%s' "$ENDED" | grep -qE 'session-unknown|scope-mismatch|session-required|session-not-live'; then
|
|
768
|
+
no "the lazy bind refused — the registry record was not usable" "$ENDED
|
|
769
|
+
$(cat "$WORK/mcp3.err")"
|
|
770
|
+
elif printf '%s' "$ENDED" | grep -q '"stored":true'; then
|
|
771
|
+
ok
|
|
772
|
+
else
|
|
773
|
+
no "session_end did not report a deposit" "$ENDED
|
|
774
|
+
$(cat "$WORK/mcp3.err")"
|
|
775
|
+
fi
|
|
776
|
+
|
|
777
|
+
step "COUNTERPARTS_CONFIG points the MCP server at another install's config"
|
|
778
|
+
# The flag's equivalent for a host that launches from a STATIC registration —
|
|
779
|
+
# which is how this host launches MCP servers, so `-e COUNTERPARTS_CONFIG=…` in
|
|
780
|
+
# the `claude mcp add` line is the only channel there is. The server says which
|
|
781
|
+
# file it read on stderr (stdout is the JSON-RPC wire) and serves normally.
|
|
782
|
+
RPC=$(
|
|
783
|
+
printf '%s\n' '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{}}}'
|
|
784
|
+
printf '%s\n' '{"jsonrpc":"2.0","method":"notifications/initialized"}'
|
|
785
|
+
printf '%s\n' '{"jsonrpc":"2.0","id":2,"method":"tools/list"}'
|
|
786
|
+
)
|
|
787
|
+
MCP_OUT=$(printf '%s\n' "$RPC" |
|
|
788
|
+
COUNTERPARTS_DATA_DIR="$SECOND_STORE" COUNTERPARTS_CONFIG="$SECOND_CONFIG" counterparts-mcp 2>"$WORK/mcp-config.err")
|
|
789
|
+
if printf '%s' "$MCP_OUT" | grep -q '"serverInfo"' &&
|
|
790
|
+
grep -q "config: $SECOND_CONFIG (named by COUNTERPARTS_CONFIG)" "$WORK/mcp-config.err"; then
|
|
791
|
+
ok
|
|
792
|
+
else
|
|
793
|
+
no "the server did not start on the named config, or did not name it" "$MCP_OUT
|
|
794
|
+
$(cat "$WORK/mcp-config.err")"
|
|
795
|
+
fi
|
|
796
|
+
|
|
797
|
+
step "a relative COUNTERPARTS_CONFIG REFUSES the server rather than falling back"
|
|
798
|
+
OUT=$(printf '%s\n' "$RPC" |
|
|
799
|
+
COUNTERPARTS_DATA_DIR="$SECOND_STORE" COUNTERPARTS_CONFIG=claude-code.json counterparts-mcp 2>"$WORK/mcp-relative.err")
|
|
800
|
+
CODE=$?
|
|
801
|
+
if [ "$CODE" != "0" ] && grep -q "ABSOLUTE" "$WORK/mcp-relative.err" && [ -z "$OUT" ]; then
|
|
802
|
+
ok
|
|
803
|
+
else
|
|
804
|
+
no "a relative COUNTERPARTS_CONFIG did not refuse the launch (exit $CODE)" "$OUT
|
|
805
|
+
$(cat "$WORK/mcp-relative.err")"
|
|
806
|
+
fi
|
|
807
|
+
|
|
808
|
+
step "the note is durable: the console counts it after both processes exited"
|
|
809
|
+
OUT=$(counterparts status --dir "$STORE" 2>&1)
|
|
810
|
+
LIVE=$(printf '%s\n' "$OUT" | sed -n 's/^Memories: \([0-9]*\).*/\1/p' | head -1)
|
|
811
|
+
# The four populations are on ONE line now, each labelled, because adding them
|
|
812
|
+
# together and calling the total "memories" is how three surfaces came to report
|
|
813
|
+
# three different sizes (round 8). `Memories:` is the number the wake states.
|
|
814
|
+
if [ -n "$LIVE" ] && [ "$LIVE" -ge 1 ] 2>/dev/null &&
|
|
815
|
+
printf '%s' "$OUT" | grep -q 'Journal: ' &&
|
|
816
|
+
printf '%s' "$OUT" | grep -q 'Beliefs and entities: '; then
|
|
817
|
+
ok
|
|
818
|
+
else
|
|
819
|
+
no "expected at least one memory and the labelled census, read '${LIVE:-nothing}'" "$OUT"
|
|
820
|
+
fi
|
|
821
|
+
|
|
822
|
+
# ── 6. the wake carries something ───────────────────────────────────────────
|
|
823
|
+
|
|
824
|
+
step "counterparts rebrief renders a wake bundle from the store"
|
|
825
|
+
CMD='counterparts rebrief --dir "$HOME/.counterparts/store"'
|
|
826
|
+
if ! doc_check "$CMD"; then
|
|
827
|
+
no "not in QUICKSTART verbatim: $CMD"
|
|
828
|
+
else
|
|
829
|
+
OUT=$(eval "$CMD" 2>&1)
|
|
830
|
+
# It must NAME the file the ceiling came from. On the default layout that is
|
|
831
|
+
# the config beside the store — the same file the hooks read.
|
|
832
|
+
if printf '%s' "$OUT" | grep -q "Re-rendered the wake bundle" &&
|
|
833
|
+
printf '%s' "$OUT" | grep -q "budget 9000 bytes from $BASE/claude-code.json"; then
|
|
834
|
+
ok
|
|
835
|
+
else
|
|
836
|
+
no "rebrief declined, or did not name the config it read" "$OUT"
|
|
837
|
+
fi
|
|
838
|
+
fi
|
|
839
|
+
|
|
840
|
+
step "rebrief on a store with NO config beside it says which file it fell back to"
|
|
841
|
+
# The divergence the cold-stranger review found and this loop could not see: the
|
|
842
|
+
# default layout puts the beside-the-store config and the hooks' config at the
|
|
843
|
+
# same path, so the fallback never showed. A SECOND store, with no config of its
|
|
844
|
+
# own, is the only shape that exercises it — and the point of the step is the
|
|
845
|
+
# printed source line, not the number.
|
|
846
|
+
OUT=$(counterparts rebrief --dir "$FIRSTSTORE" 2>&1)
|
|
847
|
+
if printf '%s' "$OUT" | grep -q "budget 9000 bytes from $BASE/claude-code.json"; then
|
|
848
|
+
ok
|
|
849
|
+
else
|
|
850
|
+
no "the fallback to the hooks' config was silent, or named the wrong file" "$OUT"
|
|
851
|
+
fi
|
|
852
|
+
|
|
853
|
+
step "rebrief with no ceiling anywhere refuses and lists every path it tried"
|
|
854
|
+
NOCONFIG="$WORK/no-config-store"
|
|
855
|
+
counterparts init --dir "$NOCONFIG" >/dev/null 2>&1
|
|
856
|
+
OUT=$(env HOME="$WORK/empty-home" counterparts rebrief --dir "$NOCONFIG" 2>&1)
|
|
857
|
+
if printf '%s' "$OUT" | grep -q "no injection ceiling" &&
|
|
858
|
+
printf '%s' "$OUT" | grep -q "$WORK/claude-code.json" &&
|
|
859
|
+
printf '%s' "$OUT" | grep -q "$WORK/empty-home/.counterparts/claude-code.json"; then
|
|
860
|
+
ok
|
|
861
|
+
else
|
|
862
|
+
no "the refusal did not name both places it looked" "$OUT"
|
|
863
|
+
fi
|
|
864
|
+
|
|
865
|
+
step "SessionStart injects the re-rendered bundle, still naming the core"
|
|
866
|
+
# The identity lane is still empty here — a promotion needs reinforcement on
|
|
867
|
+
# several distinct lived days, and this loop lives one — so the day-0 line is
|
|
868
|
+
# still the honest thing to say, now over a store that has memories in it.
|
|
869
|
+
OUT=$(payload SessionStart | counterparts-hook 2>"$WORK/hook2.err")
|
|
870
|
+
if printf '%s' "$OUT" | grep -q "has not lived a boundary"; then
|
|
871
|
+
no "still the bootstrap line after a rebrief" "$OUT"
|
|
872
|
+
elif printf '%s' "$OUT" | grep -q "This memory is for Your Name"; then
|
|
873
|
+
ok
|
|
874
|
+
else
|
|
875
|
+
no "the hook injected nothing, or stopped naming the core" "$(cat "$WORK/hook2.err")
|
|
876
|
+
$OUT"
|
|
877
|
+
fi
|
|
878
|
+
|
|
879
|
+
step "the dashboard opens the same store"
|
|
880
|
+
CMD='counterparts-dashboard status --dir "$HOME/.counterparts/store"'
|
|
881
|
+
if ! doc_check "$CMD"; then
|
|
882
|
+
no "not in QUICKSTART verbatim: $CMD"
|
|
883
|
+
else
|
|
884
|
+
OUT=$(eval "$CMD" 2>&1)
|
|
885
|
+
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
|
|
886
|
+
fi
|
|
887
|
+
|
|
888
|
+
step "the web dashboard REFUSES to open the default store without --dir"
|
|
889
|
+
# The default data dir is the owner's live memory on any machine with an
|
|
890
|
+
# install, and `serve` used to open it behind a warning printed AFTER the socket
|
|
891
|
+
# was bound. The alarm is the point of the perl wrapper: if the refusal ever
|
|
892
|
+
# regresses, the server starts and never returns, and a hanging loop is a loop
|
|
893
|
+
# nobody reads. With the alarm, a regression fails this step in ten seconds.
|
|
894
|
+
# The way through is `--default-store`, and it is the ONLY flag that means it:
|
|
895
|
+
# `--yes` means "skip an interactive confirmation" everywhere in this package
|
|
896
|
+
# (owner ruling 2026-09-05), `serve` has none to skip, so `serve --yes` is an
|
|
897
|
+
# unknown flag — refused before the store is resolved, under the same alarm.
|
|
898
|
+
OUT=$(perl -e 'alarm 10; exec @ARGV or exit 127' counterparts-dashboard serve 2>&1)
|
|
899
|
+
CODE=$?
|
|
900
|
+
YES_OUT=$(perl -e 'alarm 10; exec @ARGV or exit 127' counterparts-dashboard serve --yes 2>&1)
|
|
901
|
+
YES_CODE=$?
|
|
902
|
+
if [ "$CODE" = "1" ] &&
|
|
903
|
+
printf '%s' "$OUT" | grep -q "Refused" &&
|
|
904
|
+
printf '%s' "$OUT" | grep -q -- "--default-store" &&
|
|
905
|
+
! printf '%s' "$OUT" | grep -q -- "--yes" &&
|
|
906
|
+
[ "$YES_CODE" = "1" ] &&
|
|
907
|
+
printf '%s' "$YES_OUT" | grep -q -- "unknown flag --yes"; then
|
|
908
|
+
ok
|
|
909
|
+
else
|
|
910
|
+
no "a stray 'serve' was not refused, or 'serve --yes' was not refused as unknown (exit $CODE / $YES_CODE)" "$OUT
|
|
911
|
+
$YES_OUT"
|
|
912
|
+
fi
|
|
913
|
+
|
|
914
|
+
step "counterparts status on a MISSING store exits non-zero and offers the right --dir"
|
|
915
|
+
# Two halves of one cold-stranger finding (#11): a census of nothing at all is
|
|
916
|
+
# not a success — `set -e` around it sailed straight past a typo'd --dir — and
|
|
917
|
+
# `counterparts init` offered on its own would create the store in the DEFAULT
|
|
918
|
+
# place rather than the one the sentence above it just named.
|
|
919
|
+
NOWHERE="$WORK/no-store-here"
|
|
920
|
+
OUT=$(counterparts status --dir "$NOWHERE" 2>&1)
|
|
921
|
+
CODE=$?
|
|
922
|
+
if [ "$CODE" != "0" ] &&
|
|
923
|
+
printf '%s' "$OUT" | grep -q "No store at $NOWHERE" &&
|
|
924
|
+
printf '%s' "$OUT" | grep -q "counterparts init --dir $NOWHERE" &&
|
|
925
|
+
[ ! -d "$NOWHERE" ]; then
|
|
926
|
+
ok
|
|
927
|
+
else
|
|
928
|
+
no "status on a missing store did not refuse, or minted one (exit $CODE)" "$OUT"
|
|
929
|
+
fi
|
|
930
|
+
|
|
931
|
+
step "counterparts <command> --help prints THAT command's flags"
|
|
932
|
+
# It printed the whole console's usage, so the flags a command takes were
|
|
933
|
+
# listed nowhere a person could ask for them.
|
|
934
|
+
OUT=$(counterparts note --help 2>&1)
|
|
935
|
+
CODE=$?
|
|
936
|
+
if [ "$CODE" = "0" ] &&
|
|
937
|
+
printf '%s' "$OUT" | grep -q "^counterparts note — " &&
|
|
938
|
+
printf '%s' "$OUT" | grep -q -- "--salience" &&
|
|
939
|
+
! printf '%s' "$OUT" | grep -q -- "--confirm"; then
|
|
940
|
+
ok
|
|
941
|
+
else
|
|
942
|
+
no "note --help did not print note's own flags (exit $CODE)" "$OUT"
|
|
943
|
+
fi
|
|
944
|
+
|
|
945
|
+
# ── 6. which directories it remembers (QUICKSTART §8) ───────────────────────
|
|
946
|
+
|
|
947
|
+
# The scope registry is HOST configuration, beside `claude-code.json` — so these
|
|
948
|
+
# steps open no store and name none, and the one that matters is the third: a
|
|
949
|
+
# directory set `off` produces a hook that writes NOTHING and says NOTHING. The
|
|
950
|
+
# scratch directory is its own, so the loop's earlier hook steps (which run in
|
|
951
|
+
# $HOME/project) are untouched by it.
|
|
952
|
+
SCOPED="$HOME/scoped-project"
|
|
953
|
+
mkdir -p "$SCOPED"
|
|
954
|
+
|
|
955
|
+
step "counterparts scope --list says nothing is set on a fresh install"
|
|
956
|
+
CMD='counterparts scope --list'
|
|
957
|
+
if ! doc_check "$CMD"; then
|
|
958
|
+
no "not in QUICKSTART verbatim: $CMD"
|
|
959
|
+
else
|
|
960
|
+
OUT=$(eval "$CMD" 2>&1)
|
|
961
|
+
if printf '%s' "$OUT" | grep -q "Nothing is set"; then ok; else no "scope --list did not report an empty registry" "$OUT"; fi
|
|
962
|
+
fi
|
|
963
|
+
|
|
964
|
+
step "counterparts scope . --off writes the registry beside the config"
|
|
965
|
+
CMD='counterparts scope . --off'
|
|
966
|
+
if ! doc_check "$CMD"; then
|
|
967
|
+
no "not in QUICKSTART verbatim: $CMD"
|
|
968
|
+
else
|
|
969
|
+
OUT=$( (cd "$SCOPED" && eval "$CMD") 2>&1 )
|
|
970
|
+
if ! printf '%s' "$OUT" | grep -q "Scope set:"; then
|
|
971
|
+
no "scope --off did not report what it wrote" "$OUT"
|
|
972
|
+
elif [ ! -f "$BASE/scopes.json" ]; then
|
|
973
|
+
no "no registry at $BASE/scopes.json"
|
|
974
|
+
elif ! grep -q '"off"' "$BASE/scopes.json"; then
|
|
975
|
+
no "the registry does not hold the mode it printed" "$(cat "$BASE/scopes.json")"
|
|
976
|
+
else
|
|
977
|
+
ok
|
|
978
|
+
fi
|
|
979
|
+
fi
|
|
980
|
+
|
|
981
|
+
step "the SessionStart hook in an OFF directory prints nothing and writes nothing"
|
|
982
|
+
# The whole guarantee: nothing is constructed, so there is nothing to print and
|
|
983
|
+
# nothing to write. Byte-for-byte empty stdout, and no session record.
|
|
984
|
+
OFF_SESSION="install-loop-off-$$"
|
|
985
|
+
OFF_PAYLOAD=$(printf '{"hook_event_name":"SessionStart","session_id":"%s","cwd":"%s"}' "$OFF_SESSION" "$SCOPED")
|
|
986
|
+
OUT=$(printf '%s' "$OFF_PAYLOAD" | counterparts-hook 2>"$WORK/hook-off.err")
|
|
987
|
+
CODE=$?
|
|
988
|
+
if [ "$CODE" != "0" ]; then
|
|
989
|
+
no "the hook did not exit 0 in an off directory (exit $CODE)" "$(cat "$WORK/hook-off.err")"
|
|
990
|
+
elif [ -n "$OUT" ]; then
|
|
991
|
+
no "the hook produced output in an off directory" "$OUT"
|
|
992
|
+
elif [ -s "$WORK/hook-off.err" ]; then
|
|
993
|
+
no "the hook wrote to stderr in an off directory" "$(cat "$WORK/hook-off.err")"
|
|
994
|
+
elif [ -f "$STORE/sessions/$OFF_SESSION.json" ]; then
|
|
995
|
+
no "the hook registered a session in an off directory"
|
|
996
|
+
else
|
|
997
|
+
ok
|
|
998
|
+
fi
|
|
999
|
+
|
|
1000
|
+
step "counterparts scope . says the mode and which entry decided it"
|
|
1001
|
+
CMD='counterparts scope .'
|
|
1002
|
+
if ! doc_check "$CMD"; then
|
|
1003
|
+
no "not in QUICKSTART verbatim: $CMD"
|
|
1004
|
+
else
|
|
1005
|
+
OUT=$( (cd "$SCOPED" && eval "$CMD") 2>&1 )
|
|
1006
|
+
if printf '%s' "$OUT" | grep -q "off" && printf '%s' "$OUT" | grep -q "Decided by"; then ok; else no "scope did not report the effective mode and its entry" "$OUT"; fi
|
|
1007
|
+
fi
|
|
1008
|
+
|
|
1009
|
+
step "counterparts scope . --resume gives the directory back, and the hook wakes there"
|
|
1010
|
+
CMD='counterparts scope . --resume'
|
|
1011
|
+
if ! doc_check "$CMD"; then
|
|
1012
|
+
no "not in QUICKSTART verbatim: $CMD"
|
|
1013
|
+
else
|
|
1014
|
+
OUT=$( (cd "$SCOPED" && eval "$CMD") 2>&1 )
|
|
1015
|
+
BACK_SESSION="install-loop-back-$$"
|
|
1016
|
+
BACK_PAYLOAD=$(printf '{"hook_event_name":"SessionStart","session_id":"%s","cwd":"%s"}' "$BACK_SESSION" "$SCOPED")
|
|
1017
|
+
HOOK_OUT=$(printf '%s' "$BACK_PAYLOAD" | counterparts-hook 2>"$WORK/hook-back.err")
|
|
1018
|
+
if ! printf '%s' "$OUT" | grep -q -- "— on."; then
|
|
1019
|
+
no "scope --resume did not put the directory back on" "$OUT"
|
|
1020
|
+
elif [ -z "$HOOK_OUT" ]; then
|
|
1021
|
+
no "the hook stayed silent after --resume" "$(cat "$WORK/hook-back.err")"
|
|
1022
|
+
elif [ ! -f "$STORE/sessions/$BACK_SESSION.json" ]; then
|
|
1023
|
+
no "the hook did not register the session after --resume"
|
|
1024
|
+
else
|
|
1025
|
+
ok
|
|
1026
|
+
fi
|
|
1027
|
+
fi
|
|
1028
|
+
|
|
1029
|
+
step "the package's own exports map resolves as a library import"
|
|
1030
|
+
# package.json declares `main` and `exports`. A declared entry point nobody
|
|
1031
|
+
# imports is a claim, not a fact.
|
|
1032
|
+
mkdir -p "$WORK/lib"
|
|
1033
|
+
cd "$WORK/lib" || exit 1
|
|
1034
|
+
LIB_OUT=$("$BUN_BIN" add "$WORK/pkg/$TARBALL" 2>&1 &&
|
|
1035
|
+
"$BUN_BIN" -e 'import("counterparts").then((m) => console.log("Counterpart:" + typeof m.Counterpart))' 2>&1)
|
|
1036
|
+
if printf '%s' "$LIB_OUT" | grep -q "Counterpart:function"; then ok; else no "importing the package did not yield Counterpart" "$LIB_OUT"; fi
|
|
1037
|
+
cd "$WORK/pkg" || exit 1
|
|
1038
|
+
|
|
1039
|
+
step "everything the run wrote is inside the clean room"
|
|
1040
|
+
# Deliberately phrased as "what did we write", not "did we touch the real home":
|
|
1041
|
+
# the real `~/.counterparts` is somebody's live memory and this loop does not
|
|
1042
|
+
# stat it to find out. Instead: every path the run produced is resolved and must
|
|
1043
|
+
# live under $WORK, and the session record must be the one in the temp store.
|
|
1044
|
+
STRAY=""
|
|
1045
|
+
for p in "$STORE" "$BASE/claude-code.json" "$BASE/credentials.env" "$BUN_INSTALL/bin/counterparts"; do
|
|
1046
|
+
r=$(cd "$(dirname "$p")" 2>/dev/null && pwd -P)
|
|
1047
|
+
case "${r:-/nowhere}/" in
|
|
1048
|
+
"$WORK"/*) ;;
|
|
1049
|
+
*) STRAY="$STRAY $p->${r:-absent}" ;;
|
|
1050
|
+
esac
|
|
1051
|
+
done
|
|
1052
|
+
if [ -z "$STRAY" ] && [ -f "$STORE/sessions/$SESSION.json" ]; then ok; else no "wrote outside the clean room:${STRAY:- (no session record)}"; fi
|
|
1053
|
+
|
|
1054
|
+
# ── done ────────────────────────────────────────────────────────────────────
|
|
1055
|
+
|
|
1056
|
+
T1=$(date +%s)
|
|
1057
|
+
echo
|
|
1058
|
+
echo "steps: $((PASS + FAIL)) PASS $PASS FAIL $FAIL total $((T1 - T0))s"
|
|
1059
|
+
echo "clean room left at $WORK (rm -rf it when you are done)"
|
|
1060
|
+
# Any failure exits non-zero. There is no category of failure this loop tolerates:
|
|
1061
|
+
# a loop that returned success beside a live bug would be the "verify says
|
|
1062
|
+
# everything is fine" failure the cold-stranger review already caught once.
|
|
1063
|
+
[ "$FAIL" -eq 0 ] || exit 1
|