@wipcomputer/wip-ldm-os 0.4.85-alpha.30 → 0.4.85-alpha.32
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/bin/ldm.js +103 -0
- package/package.json +8 -2
- package/scripts/test-boot-hook-registration.mjs +136 -0
- package/scripts/test-boot-payload-trim.mjs +200 -0
- package/scripts/test-crc-pair-login-flow.mjs +76 -1
- package/scripts/test-doctor-hook-dedupe.mjs +188 -0
- package/scripts/test-kaleidoscope-onboarding-copy.mjs +170 -0
- package/scripts/test-kaleidoscope-public-stats-baseline.mjs +129 -0
- package/scripts/test-kaleidoscope-qr-authenticator-confirmation.mjs +89 -0
- package/shared/boot/boot-config.json +18 -8
- package/shared/docs/dev-guide-wipcomputerinc.md.tmpl +5 -4
- package/shared/rules/security.md +4 -0
- package/src/boot/README.md +24 -1
- package/src/boot/boot-config.json +18 -8
- package/src/boot/boot-hook.mjs +118 -28
- package/src/boot/installer.mjs +33 -10
- package/src/hosted-mcp/.env.example +4 -0
- package/src/hosted-mcp/app/footer.js +2 -2
- package/src/hosted-mcp/app/kaleidoscope-login.html +486 -42
- package/src/hosted-mcp/app/wip-logo.png +0 -0
- package/src/hosted-mcp/demo/footer.js +2 -2
- package/src/hosted-mcp/demo/index.html +166 -44
- package/src/hosted-mcp/demo/login.html +87 -23
- package/src/hosted-mcp/demo/privacy.html +4 -214
- package/src/hosted-mcp/demo/tos.html +4 -189
- package/src/hosted-mcp/legal/internet-services/kaleidoscope/index.html +257 -0
- package/src/hosted-mcp/legal/internet-services/terms/site.html +224 -168
- package/src/hosted-mcp/legal/legal-footer.js +75 -0
- package/src/hosted-mcp/legal/legal.css +166 -0
- package/src/hosted-mcp/legal/privacy/en-ww/index.html +4 -221
- package/src/hosted-mcp/legal/privacy/index.html +253 -0
- package/src/hosted-mcp/server.mjs +662 -35
package/bin/ldm.js
CHANGED
|
@@ -3099,6 +3099,109 @@ async function cmdDoctor() {
|
|
|
3099
3099
|
}
|
|
3100
3100
|
}
|
|
3101
3101
|
|
|
3102
|
+
// Duplicate hook entries + invalid model value in ~/.claude/settings.json.
|
|
3103
|
+
// Duplicates: the same hook (event + matcher + commands) registered more
|
|
3104
|
+
// than once runs once per copy every session. 10 duplicate SessionStart
|
|
3105
|
+
// boot-hook entries observed 2026-07-04 (~450KB of boot context per
|
|
3106
|
+
// session start). Invalid model: a paste carrying ANSI escape codes can
|
|
3107
|
+
// land in /model and get persisted (e.g. "opus" + ESC + "[1m"); every new
|
|
3108
|
+
// session then fails its first API call. The corruption signal is a
|
|
3109
|
+
// CONTROL character (ESC 0x1B etc.), never the visible charset: bracketed
|
|
3110
|
+
// IDs like "claude-fable-5[1m]" are legitimate 1M-context variants and
|
|
3111
|
+
// must be left untouched.
|
|
3112
|
+
// Reported always; collapsed/removed under --fix with a timestamped
|
|
3113
|
+
// backup written before the first mutation.
|
|
3114
|
+
// See ai/product/bugs/installer/open-tickets/2026-07-04--cc-mini--installer-sessionstart-hook-duplicate-registration.md
|
|
3115
|
+
// and ai/product/bugs/guard/2026-07-04--cc-mini--no-blessed-recipe-for-live-settings-remediation.md
|
|
3116
|
+
{
|
|
3117
|
+
const settingsPath = join(HOME, '.claude', 'settings.json');
|
|
3118
|
+
const settings = readJSON(settingsPath);
|
|
3119
|
+
if (!settings && existsSync(settingsPath)) {
|
|
3120
|
+
console.log(' ! ~/.claude/settings.json exists but is not valid JSON; skipping hook/model checks');
|
|
3121
|
+
issues++;
|
|
3122
|
+
}
|
|
3123
|
+
let settingsDirty = false;
|
|
3124
|
+
let backupDone = false;
|
|
3125
|
+
const backupSettingsOnce = () => {
|
|
3126
|
+
if (backupDone) return;
|
|
3127
|
+
const stamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
3128
|
+
const bak = `${settingsPath}.bak-${stamp}`;
|
|
3129
|
+
copyFileSync(settingsPath, bak);
|
|
3130
|
+
console.log(` + Backup written: ${bak}`);
|
|
3131
|
+
backupDone = true;
|
|
3132
|
+
};
|
|
3133
|
+
|
|
3134
|
+
// Duplicate hook entries (same event + matcher + hook command list).
|
|
3135
|
+
// Deliberately ignores type/timeout: entries differing only in timeout
|
|
3136
|
+
// are treated as duplicates and collapse to the first.
|
|
3137
|
+
if (settings?.hooks) {
|
|
3138
|
+
const dupes = [];
|
|
3139
|
+
for (const [event, groups] of Object.entries(settings.hooks)) {
|
|
3140
|
+
if (!Array.isArray(groups)) continue;
|
|
3141
|
+
const seen = new Map();
|
|
3142
|
+
groups.forEach((g, i) => {
|
|
3143
|
+
const key = JSON.stringify({
|
|
3144
|
+
matcher: g?.matcher,
|
|
3145
|
+
hooks: (g?.hooks || []).map((h) => h?.command),
|
|
3146
|
+
});
|
|
3147
|
+
if (!seen.has(key)) seen.set(key, []);
|
|
3148
|
+
seen.get(key).push(i);
|
|
3149
|
+
});
|
|
3150
|
+
for (const idxs of seen.values()) {
|
|
3151
|
+
if (idxs.length > 1) dupes.push({ event, idxs });
|
|
3152
|
+
}
|
|
3153
|
+
}
|
|
3154
|
+
const extra = dupes.reduce((n, d) => n + d.idxs.length - 1, 0);
|
|
3155
|
+
if (extra > 0) {
|
|
3156
|
+
for (const d of dupes) {
|
|
3157
|
+
const cmd = settings.hooks[d.event][d.idxs[0]]?.hooks?.[0]?.command || '(no command)';
|
|
3158
|
+
console.log(` ! ${d.event}: ${d.idxs.length} identical hook entries for: ${cmd}`);
|
|
3159
|
+
}
|
|
3160
|
+
if (FIX_FLAG) {
|
|
3161
|
+
backupSettingsOnce();
|
|
3162
|
+
for (const d of dupes) {
|
|
3163
|
+
// Keep the first, drop the rest. Right-to-left so indices stay valid.
|
|
3164
|
+
for (let j = d.idxs.length - 1; j >= 1; j--) {
|
|
3165
|
+
settings.hooks[d.event].splice(d.idxs[j], 1);
|
|
3166
|
+
}
|
|
3167
|
+
}
|
|
3168
|
+
settingsDirty = true;
|
|
3169
|
+
console.log(` + Collapsed ${extra} duplicate hook entr${extra === 1 ? 'y' : 'ies'}`);
|
|
3170
|
+
} else {
|
|
3171
|
+
console.log(` Run: ldm doctor --fix to collapse ${extra} duplicate hook entr${extra === 1 ? 'y' : 'ies'}`);
|
|
3172
|
+
issues += extra;
|
|
3173
|
+
}
|
|
3174
|
+
}
|
|
3175
|
+
}
|
|
3176
|
+
|
|
3177
|
+
// Invalid model value. Corruption means CONTROL characters (ESC 0x1B
|
|
3178
|
+
// from ANSI fragments, NUL, DEL...) or an impossible length, never a
|
|
3179
|
+
// visible-charset judgment: "claude-fable-5[1m]" is a legitimate
|
|
3180
|
+
// 1M-context model ID and must pass.
|
|
3181
|
+
if (settings && typeof settings.model === 'string') {
|
|
3182
|
+
const valid =
|
|
3183
|
+
settings.model.length > 0 &&
|
|
3184
|
+
settings.model.length <= 256 &&
|
|
3185
|
+
!/[\x00-\x1f\x7f]/.test(settings.model);
|
|
3186
|
+
if (!valid) {
|
|
3187
|
+
console.log(` ! settings.json model value is invalid: ${JSON.stringify(settings.model)}`);
|
|
3188
|
+
if (FIX_FLAG) {
|
|
3189
|
+
backupSettingsOnce();
|
|
3190
|
+
delete settings.model;
|
|
3191
|
+
settingsDirty = true;
|
|
3192
|
+
console.log(' + Removed invalid model value (re-pick with /model in Claude Code)');
|
|
3193
|
+
} else {
|
|
3194
|
+
console.log(' Run: ldm doctor --fix to remove it, then re-pick with /model in Claude Code');
|
|
3195
|
+
issues++;
|
|
3196
|
+
}
|
|
3197
|
+
}
|
|
3198
|
+
}
|
|
3199
|
+
|
|
3200
|
+
if (settingsDirty) {
|
|
3201
|
+
writeFileSync(settingsPath, JSON.stringify(settings, null, 2) + '\n');
|
|
3202
|
+
}
|
|
3203
|
+
}
|
|
3204
|
+
|
|
3102
3205
|
// --fix: clean registry entries with /tmp/ sources or ldm-install- names (#54)
|
|
3103
3206
|
if (FIX_FLAG) {
|
|
3104
3207
|
const registry = readJSON(REGISTRY_PATH);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wipcomputer/wip-ldm-os",
|
|
3
|
-
"version": "0.4.85-alpha.
|
|
3
|
+
"version": "0.4.85-alpha.32",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "LDM OS: identity, memory, and sovereignty infrastructure for AI agents",
|
|
6
6
|
"engines": {
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
"test:installer-skill-dry-run-destinations": "node scripts/test-installer-skill-dry-run-destinations.mjs",
|
|
34
34
|
"test:ldm-install-bin-shim": "node scripts/test-ldm-install-preserves-foreign-bin.mjs",
|
|
35
35
|
"test:doctor-cron-target": "node scripts/test-doctor-cron-target.mjs",
|
|
36
|
+
"test:boot-payload-trim": "node scripts/test-boot-payload-trim.mjs",
|
|
36
37
|
"test:bin-manifest": "node scripts/test-bin-manifest.mjs",
|
|
37
38
|
"test:crc-agentid-tenant-boundary": "node scripts/test-crc-agentid-tenant-boundary.mjs",
|
|
38
39
|
"test:crc-pair-login-flow": "node scripts/test-crc-pair-login-flow.mjs",
|
|
@@ -41,8 +42,13 @@
|
|
|
41
42
|
"test:crc-e2ee-key-persistence": "node scripts/test-crc-e2ee-key-persistence.mjs",
|
|
42
43
|
"test:crc-e2ee-session-route": "node scripts/test-crc-e2ee-session-route.mjs",
|
|
43
44
|
"test:crc-websocket-abuse-limits": "node scripts/test-crc-websocket-abuse-limits.mjs",
|
|
45
|
+
"test:kaleidoscope-qr-authenticator-confirmation": "node scripts/test-kaleidoscope-qr-authenticator-confirmation.mjs",
|
|
46
|
+
"test:kaleidoscope-onboarding-copy": "node scripts/test-kaleidoscope-onboarding-copy.mjs",
|
|
47
|
+
"test:kaleidoscope-public-stats-baseline": "node scripts/test-kaleidoscope-public-stats-baseline.mjs",
|
|
44
48
|
"fmt": "npx prettier --write 'src/**/*.{ts,mjs}' 'lib/**/*.mjs' 'bin/**/*.js'",
|
|
45
|
-
"fmt:check": "npx prettier --check 'src/**/*.{ts,mjs}' 'lib/**/*.mjs' 'bin/**/*.js'"
|
|
49
|
+
"fmt:check": "npx prettier --check 'src/**/*.{ts,mjs}' 'lib/**/*.mjs' 'bin/**/*.js'",
|
|
50
|
+
"test:boot-hook-registration": "node scripts/test-boot-hook-registration.mjs",
|
|
51
|
+
"test:doctor-hook-dedupe": "node scripts/test-doctor-hook-dedupe.mjs"
|
|
46
52
|
},
|
|
47
53
|
"claudeCode": {
|
|
48
54
|
"hook": {
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Regression test: configureSessionStartHook() registration semantics.
|
|
3
|
+
//
|
|
4
|
+
// Covers the 2026-07-04 tickets:
|
|
5
|
+
// ai/product/bugs/installer/open-tickets/2026-07-04--cc-mini--boot-hook-update-in-place-never-persists.md
|
|
6
|
+
// ai/product/bugs/installer/open-tickets/2026-07-04--cc-mini--installer-sessionstart-hook-duplicate-registration.md
|
|
7
|
+
//
|
|
8
|
+
// Cases:
|
|
9
|
+
// 1. Fresh install: entry added and persisted.
|
|
10
|
+
// 2. Repeat run: no duplicate, file byte-identical (no write).
|
|
11
|
+
// 3. Changed entry (old command path, old timeout): updated ON DISK.
|
|
12
|
+
// This is the update-in-place-never-persists bug.
|
|
13
|
+
// 4. Duplicate-laden settings (10 boot-hook copies + 1 unrelated hook):
|
|
14
|
+
// collapses to 1 boot entry, unrelated hook preserved, persisted.
|
|
15
|
+
|
|
16
|
+
import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
17
|
+
import { join } from 'node:path';
|
|
18
|
+
import { tmpdir } from 'node:os';
|
|
19
|
+
|
|
20
|
+
// Note: the temp prefix must not contain "boot-hook" or "shared/boot".
|
|
21
|
+
// Those substrings are the installer's ownership matchers, and the temp
|
|
22
|
+
// HOME path ends up inside every fixture hook command.
|
|
23
|
+
const tempHome = mkdtempSync(join(tmpdir(), 'ldm-bootreg-'));
|
|
24
|
+
|
|
25
|
+
let failed = 0;
|
|
26
|
+
function assert(cond, label, detail = '') {
|
|
27
|
+
if (cond) {
|
|
28
|
+
console.log(` [PASS] ${label}`);
|
|
29
|
+
} else {
|
|
30
|
+
console.log(` [FAIL] ${label}`);
|
|
31
|
+
if (detail) console.log(` ${detail}`);
|
|
32
|
+
failed++;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const settingsPath = join(tempHome, '.claude', 'settings.json');
|
|
37
|
+
function seedSettings(obj) {
|
|
38
|
+
mkdirSync(join(tempHome, '.claude'), { recursive: true });
|
|
39
|
+
writeFileSync(settingsPath, JSON.stringify(obj, null, 2) + '\n');
|
|
40
|
+
}
|
|
41
|
+
function readSettings() {
|
|
42
|
+
return JSON.parse(readFileSync(settingsPath, 'utf-8'));
|
|
43
|
+
}
|
|
44
|
+
function bootEntries(settings) {
|
|
45
|
+
return (settings.hooks?.SessionStart || []).filter((entry) =>
|
|
46
|
+
(entry?.hooks || []).some((h) => h?.command?.includes('boot-hook'))
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
try {
|
|
51
|
+
// HOME must be set before the module import: installer.mjs resolves
|
|
52
|
+
// homedir() into module-level constants at import time.
|
|
53
|
+
process.env.HOME = tempHome;
|
|
54
|
+
const { configureSessionStartHook } = await import('../src/boot/installer.mjs');
|
|
55
|
+
const expectedCommand = `node ${join(tempHome, '.ldm', 'shared', 'boot', 'boot-hook.mjs')}`;
|
|
56
|
+
|
|
57
|
+
console.log('Test 1: fresh install adds and persists the entry');
|
|
58
|
+
{
|
|
59
|
+
seedSettings({ hooks: {} });
|
|
60
|
+
const msg = configureSessionStartHook();
|
|
61
|
+
const s = readSettings();
|
|
62
|
+
assert(/added/.test(msg), `reports added (got: ${msg})`);
|
|
63
|
+
assert(bootEntries(s).length === 1, 'exactly one boot-hook entry on disk');
|
|
64
|
+
assert(s.hooks.SessionStart[0].hooks[0].command === expectedCommand, 'command path is BOOT_DIR boot-hook.mjs');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
console.log('Test 2: repeat run is a no-op, byte-identical file');
|
|
68
|
+
{
|
|
69
|
+
const before = readFileSync(settingsPath, 'utf-8');
|
|
70
|
+
const msg = configureSessionStartHook();
|
|
71
|
+
const after = readFileSync(settingsPath, 'utf-8');
|
|
72
|
+
assert(/already configured/.test(msg), `reports already configured (got: ${msg})`);
|
|
73
|
+
assert(before === after, 'settings.json byte-identical after second run');
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
console.log('Test 3: changed entry is updated ON DISK (the persist bug)');
|
|
77
|
+
{
|
|
78
|
+
seedSettings({
|
|
79
|
+
hooks: {
|
|
80
|
+
SessionStart: [
|
|
81
|
+
{
|
|
82
|
+
matcher: '*',
|
|
83
|
+
hooks: [{ type: 'command', command: 'node /old/path/shared/boot/boot-hook.mjs', timeout: 10 }],
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
const msg = configureSessionStartHook();
|
|
89
|
+
const s = readSettings();
|
|
90
|
+
assert(/updated/.test(msg), `reports updated (got: ${msg})`);
|
|
91
|
+
assert(bootEntries(s).length === 1, 'still exactly one boot-hook entry');
|
|
92
|
+
assert(
|
|
93
|
+
s.hooks.SessionStart[0].hooks[0].command === expectedCommand,
|
|
94
|
+
'new command path persisted to disk',
|
|
95
|
+
`on disk: ${s.hooks.SessionStart[0].hooks[0].command}`
|
|
96
|
+
);
|
|
97
|
+
assert(s.hooks.SessionStart[0].hooks[0].timeout === 15, 'new timeout persisted to disk');
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
console.log('Test 4: duplicate-laden settings collapse to one, unrelated hooks preserved');
|
|
101
|
+
{
|
|
102
|
+
const bootEntry = {
|
|
103
|
+
matcher: '*',
|
|
104
|
+
hooks: [{ type: 'command', command: expectedCommand, timeout: 15 }],
|
|
105
|
+
};
|
|
106
|
+
const guardEntry = {
|
|
107
|
+
hooks: [{ type: 'command', command: `node ${join(tempHome, '.ldm', 'extensions', 'wip-branch-guard', 'guard.mjs')}`, timeout: 10 }],
|
|
108
|
+
};
|
|
109
|
+
seedSettings({
|
|
110
|
+
hooks: {
|
|
111
|
+
SessionStart: [
|
|
112
|
+
...Array.from({ length: 5 }, () => structuredClone(bootEntry)),
|
|
113
|
+
guardEntry,
|
|
114
|
+
...Array.from({ length: 5 }, () => structuredClone(bootEntry)),
|
|
115
|
+
],
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
const msg = configureSessionStartHook();
|
|
119
|
+
const s = readSettings();
|
|
120
|
+
assert(/removed 9 duplicate entries/.test(msg), `reports 9 duplicates removed (got: ${msg})`);
|
|
121
|
+
assert(bootEntries(s).length === 1, 'exactly one boot-hook entry after collapse');
|
|
122
|
+
assert(s.hooks.SessionStart.length === 2, 'boot hook + branch guard remain');
|
|
123
|
+
assert(
|
|
124
|
+
s.hooks.SessionStart.some((e) => e.hooks?.[0]?.command?.includes('wip-branch-guard')),
|
|
125
|
+
'unrelated branch-guard entry preserved'
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
} finally {
|
|
129
|
+
rmSync(tempHome, { recursive: true, force: true });
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (failed > 0) {
|
|
133
|
+
console.log(`\n${failed} assertion(s) failed`);
|
|
134
|
+
process.exit(1);
|
|
135
|
+
}
|
|
136
|
+
console.log('\nAll boot-hook registration tests passed');
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Regression test: boot-hook payload trimming (CC speedup master plan, Task 4b).
|
|
3
|
+
//
|
|
4
|
+
// Covers:
|
|
5
|
+
// 1. A step with no maxLines in config gets the code default cap + a
|
|
6
|
+
// truncation marker that names the full path.
|
|
7
|
+
// 2. A per-step maxLines in config overrides the default.
|
|
8
|
+
// 3. A most-recent step whose newest file is older than stalenessDays is
|
|
9
|
+
// NOT injected: a path-only stale line is emitted instead.
|
|
10
|
+
// 4. A fresh most-recent file IS injected in full.
|
|
11
|
+
// 5. The payload ends with a one-line summary (bytes/lines/sections, capped,
|
|
12
|
+
// stale).
|
|
13
|
+
// 6. maxTotalLines still stops the loop early.
|
|
14
|
+
//
|
|
15
|
+
// The hook resolves homedir() into a module-level constant at import time and
|
|
16
|
+
// loads boot-config.json relative to its own file. So each case copies the
|
|
17
|
+
// hook into a temp workdir next to a generated boot-config.json and runs it as
|
|
18
|
+
// a subprocess with HOME pointed at a temp fixture. The hook's dynamic imports
|
|
19
|
+
// of ../../lib/*.mjs fail harmlessly (they are wrapped in try/catch) from the
|
|
20
|
+
// temp location, which is fine: this test only exercises payload assembly.
|
|
21
|
+
|
|
22
|
+
import { mkdirSync, mkdtempSync, copyFileSync, writeFileSync, rmSync } from 'node:fs';
|
|
23
|
+
import { join, dirname } from 'node:path';
|
|
24
|
+
import { tmpdir } from 'node:os';
|
|
25
|
+
import { execFileSync } from 'node:child_process';
|
|
26
|
+
import { fileURLToPath } from 'node:url';
|
|
27
|
+
|
|
28
|
+
const repo = dirname(dirname(fileURLToPath(import.meta.url)));
|
|
29
|
+
const HOOK_SRC = join(repo, 'src', 'boot', 'boot-hook.mjs');
|
|
30
|
+
|
|
31
|
+
let failed = 0;
|
|
32
|
+
function assert(cond, label, detail = '') {
|
|
33
|
+
if (cond) {
|
|
34
|
+
console.log(` [PASS] ${label}`);
|
|
35
|
+
} else {
|
|
36
|
+
console.log(` [FAIL] ${label}`);
|
|
37
|
+
if (detail) console.log(` ${detail}`);
|
|
38
|
+
failed++;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Compute today/yesterday in the hook's timezone so daily-log and fresh-journal
|
|
43
|
+
// filenames match what the hook looks for.
|
|
44
|
+
function ymd(offsetDays = 0) {
|
|
45
|
+
const now = new Date();
|
|
46
|
+
now.setDate(now.getDate() + offsetDays);
|
|
47
|
+
return new Intl.DateTimeFormat('en-CA', {
|
|
48
|
+
timeZone: 'America/Los_Angeles',
|
|
49
|
+
year: 'numeric',
|
|
50
|
+
month: '2-digit',
|
|
51
|
+
day: '2-digit',
|
|
52
|
+
}).format(now);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function lines(n, marker) {
|
|
56
|
+
const out = [];
|
|
57
|
+
for (let i = 1; i <= n; i++) out.push(`${marker} line ${i}`);
|
|
58
|
+
return out.join('\n') + '\n';
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Run the hook with a given config object and a HOME-populating callback.
|
|
62
|
+
// Returns the injected additionalContext string.
|
|
63
|
+
function runHook(configObj, populateHome) {
|
|
64
|
+
const work = mkdtempSync(join(tmpdir(), 'ldm-bootpay-work-'));
|
|
65
|
+
const home = mkdtempSync(join(tmpdir(), 'ldm-bootpay-home-'));
|
|
66
|
+
try {
|
|
67
|
+
copyFileSync(HOOK_SRC, join(work, 'boot-hook.mjs'));
|
|
68
|
+
writeFileSync(join(work, 'boot-config.json'), JSON.stringify(configObj, null, 2));
|
|
69
|
+
populateHome(home);
|
|
70
|
+
|
|
71
|
+
const stdout = execFileSync('node', [join(work, 'boot-hook.mjs')], {
|
|
72
|
+
input: JSON.stringify({ session_id: 'test', hook_event_name: 'SessionStart', cwd: home }),
|
|
73
|
+
env: { ...process.env, HOME: home },
|
|
74
|
+
encoding: 'utf-8',
|
|
75
|
+
timeout: 30000,
|
|
76
|
+
});
|
|
77
|
+
const parsed = JSON.parse(stdout);
|
|
78
|
+
return parsed?.hookSpecificOutput?.additionalContext || '';
|
|
79
|
+
} finally {
|
|
80
|
+
rmSync(work, { recursive: true, force: true });
|
|
81
|
+
rmSync(home, { recursive: true, force: true });
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function writeHomeFile(home, rel, content) {
|
|
86
|
+
const full = join(home, rel);
|
|
87
|
+
mkdirSync(dirname(full), { recursive: true });
|
|
88
|
+
writeFileSync(full, content);
|
|
89
|
+
return full;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// ── Case 1 + 2 + 5: default cap, config override, payload summary ──
|
|
93
|
+
console.log('Case 1/2/5: default cap, config override, payload summary');
|
|
94
|
+
{
|
|
95
|
+
const config = {
|
|
96
|
+
agentId: 'test-agent',
|
|
97
|
+
timezone: 'America/Los_Angeles',
|
|
98
|
+
maxTotalLines: 2000,
|
|
99
|
+
steps: {
|
|
100
|
+
// no maxLines -> code default for sharedContext is 80
|
|
101
|
+
sharedContext: { path: '~/shared.md', label: 'SHARED', stepNumber: 2, critical: true },
|
|
102
|
+
// no maxLines -> code default for soul is 80
|
|
103
|
+
soul: { path: '~/soul.md', label: 'SOUL', stepNumber: 7 },
|
|
104
|
+
// explicit maxLines overrides
|
|
105
|
+
overridden: { path: '~/capped.md', label: 'CAPPED', stepNumber: 11, maxLines: 5 },
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
let soulPath, cappedPath;
|
|
109
|
+
const ctx = runHook(config, (home) => {
|
|
110
|
+
writeHomeFile(home, 'shared.md', lines(20, 'SHARED_BODY')); // under cap, not truncated
|
|
111
|
+
soulPath = writeHomeFile(home, 'soul.md', lines(200, 'SOUL_BODY')); // over default 80
|
|
112
|
+
cappedPath = writeHomeFile(home, 'capped.md', lines(100, 'CAP_BODY')); // over explicit 5
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
assert(/truncated at 80 of \d+ lines/.test(ctx), 'soul truncated at default cap 80', ctx.match(/truncated at[^\n]*soul[^\n]*/)?.[0] || ctx.slice(0, 300));
|
|
116
|
+
assert(ctx.includes(`Read the rest: ${soulPath}`), 'soul truncation marker names full path');
|
|
117
|
+
assert(/truncated at 5 of \d+ lines/.test(ctx), 'config maxLines=5 override respected');
|
|
118
|
+
assert(ctx.includes(`Read the rest: ${cappedPath}`), 'capped truncation marker names full path');
|
|
119
|
+
assert(/SHARED_BODY line 20\b/.test(ctx), 'under-cap file not truncated (body fully present)');
|
|
120
|
+
const summaryLine = ctx.match(/== Boot payload:[^\n]*/)?.[0] || '';
|
|
121
|
+
assert(/== Boot payload: \d+ bytes, \d+ lines, \d+ sections\./.test(summaryLine), 'payload summary line present', summaryLine);
|
|
122
|
+
const cappedPart = summaryLine.match(/Capped:([^.]*)\./)?.[1] || '';
|
|
123
|
+
assert(/Step 7\b/.test(cappedPart) && /Step 11\b/.test(cappedPart), 'summary lists capped steps 7 and 11', summaryLine);
|
|
124
|
+
assert(/Stale\/path-only: none\./.test(summaryLine), 'summary reports no stale steps', summaryLine);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// ── Case 3: stale most-recent journal emits path-only line ──
|
|
128
|
+
console.log('Case 3: stale journal is path-only, body not injected');
|
|
129
|
+
{
|
|
130
|
+
const config = {
|
|
131
|
+
agentId: 'test-agent',
|
|
132
|
+
timezone: 'America/Los_Angeles',
|
|
133
|
+
maxTotalLines: 2000,
|
|
134
|
+
stalenessDays: 14,
|
|
135
|
+
steps: {
|
|
136
|
+
ccJournals: { dir: '~/journals', label: 'JOURNAL', stepNumber: 8, maxLines: 80, strategy: 'most-recent' },
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
const staleDate = ymd(-100);
|
|
140
|
+
let journalPath;
|
|
141
|
+
const ctx = runHook(config, (home) => {
|
|
142
|
+
journalPath = writeHomeFile(home, `journals/${staleDate}-journal.md`, lines(50, 'STALE_JOURNAL_BODY'));
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
assert(!/STALE_JOURNAL_BODY/.test(ctx), 'stale journal body is NOT injected');
|
|
146
|
+
assert(new RegExp(`stale: newest file is ${staleDate}`).test(ctx), 'stale line names the file date');
|
|
147
|
+
assert(/cutoff 14d/.test(ctx), 'stale line names the cutoff');
|
|
148
|
+
assert(ctx.includes(`Read if needed: ${journalPath}`), 'stale line names the full path');
|
|
149
|
+
assert(/Stale\/path-only: Step 8\b/.test(ctx), 'summary lists stale step 8');
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// ── Case 4: fresh most-recent journal is injected in full ──
|
|
153
|
+
console.log('Case 4: fresh journal body IS injected');
|
|
154
|
+
{
|
|
155
|
+
const config = {
|
|
156
|
+
agentId: 'test-agent',
|
|
157
|
+
timezone: 'America/Los_Angeles',
|
|
158
|
+
maxTotalLines: 2000,
|
|
159
|
+
stalenessDays: 14,
|
|
160
|
+
steps: {
|
|
161
|
+
ccJournals: { dir: '~/journals', label: 'JOURNAL', stepNumber: 8, maxLines: 80, strategy: 'most-recent' },
|
|
162
|
+
},
|
|
163
|
+
};
|
|
164
|
+
const freshDate = ymd(0);
|
|
165
|
+
const ctx = runHook(config, (home) => {
|
|
166
|
+
writeHomeFile(home, `journals/${freshDate}-journal.md`, lines(10, 'FRESH_JOURNAL_BODY'));
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
assert(/FRESH_JOURNAL_BODY line 1\b/.test(ctx), 'fresh journal body injected');
|
|
170
|
+
assert(!/stale:/.test(ctx), 'no stale marker for fresh journal');
|
|
171
|
+
assert(/Stale\/path-only: none\./.test(ctx), 'summary reports no stale steps');
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// ── Case 6: maxTotalLines stops the loop early ──
|
|
175
|
+
console.log('Case 6: maxTotalLines respected');
|
|
176
|
+
{
|
|
177
|
+
const config = {
|
|
178
|
+
agentId: 'test-agent',
|
|
179
|
+
timezone: 'America/Los_Angeles',
|
|
180
|
+
maxTotalLines: 5, // tiny: first big step blows past it
|
|
181
|
+
steps: {
|
|
182
|
+
sharedContext: { path: '~/shared.md', label: 'SHARED', stepNumber: 2, critical: true },
|
|
183
|
+
context: { path: '~/context.md', label: 'CONTEXT', stepNumber: 6, critical: true },
|
|
184
|
+
},
|
|
185
|
+
};
|
|
186
|
+
const ctx = runHook(config, (home) => {
|
|
187
|
+
writeHomeFile(home, 'shared.md', lines(40, 'FIRST_BODY'));
|
|
188
|
+
writeHomeFile(home, 'context.md', lines(40, 'SECOND_BODY'));
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
assert(/FIRST_BODY line 1\b/.test(ctx), 'first step loaded');
|
|
192
|
+
assert(!/SECOND_BODY/.test(ctx), 'second step skipped after maxTotalLines cap');
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
console.log('');
|
|
196
|
+
if (failed > 0) {
|
|
197
|
+
console.log(`${failed} test(s) failed.`);
|
|
198
|
+
process.exit(1);
|
|
199
|
+
}
|
|
200
|
+
console.log('All boot payload trim tests passed.');
|
|
@@ -12,6 +12,12 @@ function assertContains(source, needle, label) {
|
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
function assertNotContains(source, needle, label) {
|
|
16
|
+
if (source.includes(needle)) {
|
|
17
|
+
throw new Error(`${label} must not contain: ${needle}`);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
15
21
|
function assertBefore(source, first, second, label) {
|
|
16
22
|
const firstIndex = source.indexOf(first);
|
|
17
23
|
const secondIndex = source.indexOf(second);
|
|
@@ -20,15 +26,74 @@ function assertBefore(source, first, second, label) {
|
|
|
20
26
|
}
|
|
21
27
|
}
|
|
22
28
|
|
|
29
|
+
function extractServerNextSanitizer(source) {
|
|
30
|
+
const consts = [
|
|
31
|
+
source.match(/const PAIR_NEXT_REGEX = .+;/)?.[0],
|
|
32
|
+
source.match(/const REMOTE_CONTROL_NEXT_REGEX = .+;/)?.[0],
|
|
33
|
+
source.match(/const DEMO_NEXT_REGEX = .+;/)?.[0],
|
|
34
|
+
];
|
|
35
|
+
if (consts.some((line) => !line)) {
|
|
36
|
+
throw new Error("server sanitizer test could not extract next regex constants");
|
|
37
|
+
}
|
|
38
|
+
const start = source.indexOf("function sanitizeCrcPairNext(raw)");
|
|
39
|
+
const end = source.indexOf("// POST /api/qr-login", start);
|
|
40
|
+
if (start === -1 || end === -1) {
|
|
41
|
+
throw new Error("server sanitizer test could not extract sanitizeCrcPairNext");
|
|
42
|
+
}
|
|
43
|
+
return Function(`${consts.join("\n")}\n${source.slice(start, end)}\nreturn sanitizeCrcPairNext;`)();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function assertSanitizedNext(sanitize, value, expected) {
|
|
47
|
+
const actual = sanitize(value);
|
|
48
|
+
if (actual !== expected) {
|
|
49
|
+
throw new Error(`sanitizeCrcPairNext(${JSON.stringify(value)}) expected ${JSON.stringify(expected)}, got ${JSON.stringify(actual)}`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
23
53
|
assertContains(server, "const PAIR_NEXT_REGEX = /^\\/pair\\/[ABCDEFGHJKLMNPQRSTUVWXYZ23456789]{6}$/;", "server pair regex");
|
|
24
54
|
assertContains(server, "const REMOTE_CONTROL_NEXT_REGEX = /^\\/codex-remote-control\\/", "server remote-control regex");
|
|
55
|
+
assertContains(server, "const DEMO_NEXT_REGEX = /^\\/demo$/;", "server demo regex");
|
|
25
56
|
assertContains(server, "purpose, // \"pair\" | null", "server stores pair purpose");
|
|
26
|
-
assertContains(server, "next: next || null, // sanitized `/pair/<CODE
|
|
57
|
+
assertContains(server, "next: next || null, // sanitized `/pair/<CODE>`, `/codex-remote-control/<UUID>`, `/demo`, or null", "server stores sanitized next");
|
|
58
|
+
assertContains(server, "DEMO_NEXT_REGEX.test(decoded)", "server allows demo next");
|
|
27
59
|
assertContains(server, "json(res, 200, { status: \"approved\", agentId: entry.agentId });", "server strips desktop pair status");
|
|
28
60
|
assertContains(server, "json(res, 200, { ok: true, next: entry.next });", "server returns next to phone approve");
|
|
61
|
+
assertContains(server, "tenantId: entry.tenantId || null,", "server returns QR login tenant");
|
|
62
|
+
assertContains(server, "const verifiedIdentity = identityForApiKey(apiKey);", "server canonicalizes QR approval identity");
|
|
63
|
+
|
|
64
|
+
const sanitizeCrcPairNext = extractServerNextSanitizer(server);
|
|
65
|
+
assertSanitizedNext(sanitizeCrcPairNext, "/demo", "/demo");
|
|
66
|
+
assertSanitizedNext(sanitizeCrcPairNext, "/demo/", null);
|
|
67
|
+
assertSanitizedNext(sanitizeCrcPairNext, "/demo/../admin", null);
|
|
68
|
+
assertSanitizedNext(sanitizeCrcPairNext, "//evil.com", null);
|
|
69
|
+
assertSanitizedNext(sanitizeCrcPairNext, "https://evil", null);
|
|
70
|
+
assertSanitizedNext(sanitizeCrcPairNext, "/demoX", null);
|
|
29
71
|
|
|
30
72
|
for (const file of loginFiles) {
|
|
31
73
|
const html = readFileSync(file, "utf8");
|
|
74
|
+
assertContains(html, "var DEMO_NEXT_REGEX = /^\\/demo$/;", `${file} demo regex`);
|
|
75
|
+
assertContains(html, "function defaultLocalPasskeysOn()", `${file} has local passkey default helper`);
|
|
76
|
+
assertContains(html, "return isMobileDevice();", `${file} defaults local passkeys on for mobile`);
|
|
77
|
+
assertContains(html, "function getLocalPasskeysPreference()", `${file} has local passkey preference helper`);
|
|
78
|
+
assertContains(html, "if (stored === 'on' || stored === 'off') return stored;", `${file} respects stored local passkey preference`);
|
|
79
|
+
assertContains(html, "function needsCustomQR() {\n return !isLocalPasskeysOn();\n}", `${file} uses QR whenever local passkeys are off`);
|
|
80
|
+
assertNotContains(html, "return !isMobileDevice() && !isSafariDesktop() && !isLocalPasskeysOn();", `${file} must not gate QR by browser or mobile status`);
|
|
81
|
+
assertContains(html, "DEMO_NEXT_REGEX.test(raw)", `${file} allowlists demo next`);
|
|
82
|
+
assertContains(html, "function storeDemoHandoffIfNeeded(next, identity, isNewAccount)", `${file} demo handoff helper`);
|
|
83
|
+
assertContains(html, "sessionStorage.setItem('lesa-token', identity.apiKey);", `${file} stores demo token`);
|
|
84
|
+
assertContains(html, "sessionStorage.setItem('lesa-agent', identity.agentId);", `${file} stores demo agent`);
|
|
85
|
+
assertContains(html, "if (identity.tenantId) sessionStorage.setItem('lesa-tenant', identity.tenantId);", `${file} stores demo tenant`);
|
|
86
|
+
assertContains(html, "if (isNewAccount) sessionStorage.setItem('lesa-new-account', 'true');", `${file} stores demo new-account flag conditionally`);
|
|
87
|
+
assertContains(html, "tenantId: result.tenantId,", `${file} sends tenant to QR approval`);
|
|
88
|
+
assertContains(html, "storeDemoHandoffIfNeeded(data.next, data, qrLoginMode === 'register');", `${file} QR status stores demo handoff`);
|
|
89
|
+
assertContains(html, "storeDemoHandoffIfNeeded('/demo', data, qrLoginMode === 'register');", `${file} plain QR success keeps demo handoff`);
|
|
90
|
+
assertContains(html, "storeDemoHandoffIfNeeded('/demo', result, true);", `${file} plain create success keeps demo handoff`);
|
|
91
|
+
assertContains(html, "storeDemoHandoffIfNeeded('/demo', result, false);", `${file} plain sign-in success keeps demo handoff`);
|
|
92
|
+
if (html.includes('onclick="sessionStorage.clear();"')) {
|
|
93
|
+
throw new Error(`${file} Try the Demo button must not clear sessionStorage`);
|
|
94
|
+
}
|
|
95
|
+
assertContains(html, "followPairNextIfPresent(approveResponse, result, true)", `${file} create account marks new account`);
|
|
96
|
+
assertContains(html, "followPairNextIfPresent(approveResponse, result, false)", `${file} sign-in does not mark new account`);
|
|
32
97
|
assertContains(html, "function isPairNextOnDesktop()", `${file} desktop pair helper`);
|
|
33
98
|
assertContains(html, "} else if (isPairNextOnDesktop()) {", `${file} auto-start desktop pair QR`);
|
|
34
99
|
assertContains(html, "startQrLogin('', 'signin');", `${file} pair QR uses sign-in mode`);
|
|
@@ -37,4 +102,14 @@ for (const file of loginFiles) {
|
|
|
37
102
|
assertBefore(html, "if (isPairNextOnDesktop() && !qrSessionMode)", "if (needsCustomQR() && !qrSessionMode)", `${file} create button forces pair QR before normal QR fallback`);
|
|
38
103
|
}
|
|
39
104
|
|
|
105
|
+
const appLogin = readFileSync("src/hosted-mcp/app/kaleidoscope-login.html", "utf8");
|
|
106
|
+
assertContains(appLogin, "Local passkeys are on by default on mobile devices.", "app login mobile tooltip copy");
|
|
107
|
+
assertContains(appLogin, "This device's passkeys are used for login and device sync.", "app login mobile tooltip current-device copy");
|
|
108
|
+
assertContains(appLogin, "Turn this off to use or save passkeys on a different device.", "app login mobile tooltip off copy");
|
|
109
|
+
assertContains(appLogin, "Local passkeys are off by default on desktop.", "app login desktop tooltip copy");
|
|
110
|
+
assertContains(appLogin, "Your mobile device's passkeys are used for login and device sync.", "app login desktop tooltip mobile-device copy");
|
|
111
|
+
assertContains(appLogin, "Turn this on to use or save passkeys on this computer.", "app login desktop tooltip on copy");
|
|
112
|
+
assertNotContains(appLogin, "phone's passkeys", "app login tooltip must not say phone passkeys");
|
|
113
|
+
assertNotContains(appLogin, "mobile devices' passkeys", "app login tooltip must not use plural possessive");
|
|
114
|
+
|
|
40
115
|
console.log("crc pair login flow checks passed");
|