wicked-crew 0.18.22 → 0.18.23
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/dist/api/audit-view.d.ts.map +1 -1
- package/dist/api/audit-view.js +1 -0
- package/dist/api/audit-view.js.map +1 -1
- package/dist/api/desk-snoozes.d.ts +27 -4
- package/dist/api/desk-snoozes.d.ts.map +1 -1
- package/dist/api/desk-snoozes.js +49 -3
- package/dist/api/desk-snoozes.js.map +1 -1
- package/dist/api/domain-model.d.ts +56 -0
- package/dist/api/domain-model.d.ts.map +1 -0
- package/dist/api/domain-model.js +281 -0
- package/dist/api/domain-model.js.map +1 -0
- package/dist/api/domain-scope.d.ts +52 -0
- package/dist/api/domain-scope.d.ts.map +1 -0
- package/dist/api/domain-scope.js +156 -0
- package/dist/api/domain-scope.js.map +1 -0
- package/dist/api/eval-rule-store.d.ts +32 -0
- package/dist/api/eval-rule-store.d.ts.map +1 -0
- package/dist/api/eval-rule-store.js +77 -0
- package/dist/api/eval-rule-store.js.map +1 -0
- package/dist/api/mcp.d.ts +3 -0
- package/dist/api/mcp.d.ts.map +1 -1
- package/dist/api/mcp.js +52 -6
- package/dist/api/mcp.js.map +1 -1
- package/dist/api/requirements.d.ts +3 -1
- package/dist/api/requirements.d.ts.map +1 -1
- package/dist/api/requirements.js +3 -0
- package/dist/api/requirements.js.map +1 -1
- package/dist/api/routes.d.ts +7 -1
- package/dist/api/routes.d.ts.map +1 -1
- package/dist/api/routes.js +175 -13
- package/dist/api/routes.js.map +1 -1
- package/dist/api/server.d.ts.map +1 -1
- package/dist/api/server.js +1 -0
- package/dist/api/server.js.map +1 -1
- package/dist/api/system-snapshot.d.ts +3 -1
- package/dist/api/system-snapshot.d.ts.map +1 -1
- package/dist/api/system-snapshot.js +1 -0
- package/dist/api/system-snapshot.js.map +1 -1
- package/dist/api/testing.d.ts.map +1 -1
- package/dist/api/testing.js +11 -8
- package/dist/api/testing.js.map +1 -1
- package/dist/apps/actions/write-path.d.ts +6 -2
- package/dist/apps/actions/write-path.d.ts.map +1 -1
- package/dist/apps/actions/write-path.js +7 -3
- package/dist/apps/actions/write-path.js.map +1 -1
- package/dist/apps-server/server/lib/bundle/server.mjs +7 -3
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +11 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/mcp.d.ts +14 -0
- package/dist/cli/mcp.d.ts.map +1 -1
- package/dist/cli/mcp.js +27 -10
- package/dist/cli/mcp.js.map +1 -1
- package/dist/core/adapter.d.ts +14 -0
- package/dist/core/adapter.d.ts.map +1 -1
- package/dist/core/adapter.js +39 -0
- package/dist/core/adapter.js.map +1 -1
- package/dist/core/launch-posture.d.ts +3 -0
- package/dist/core/launch-posture.d.ts.map +1 -1
- package/dist/core/launch-posture.js +4 -0
- package/dist/core/launch-posture.js.map +1 -1
- package/dist/core/stand-in.d.ts +28 -6
- package/dist/core/stand-in.d.ts.map +1 -1
- package/dist/core/stand-in.js +49 -14
- package/dist/core/stand-in.js.map +1 -1
- package/dist/core/types.d.ts +5 -0
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core/types.js.map +1 -1
- package/dist/mcp/policies.d.ts +10 -1
- package/dist/mcp/policies.d.ts.map +1 -1
- package/dist/mcp/policies.js +18 -3
- package/dist/mcp/policies.js.map +1 -1
- package/dist/mcp/registry.d.ts +3 -0
- package/dist/mcp/registry.d.ts.map +1 -1
- package/dist/mcp/registry.js +13 -0
- package/dist/mcp/registry.js.map +1 -1
- package/dist/persona/routes.d.ts +1 -1
- package/dist/persona/store.d.ts +1 -1
- package/dist/schedules/routes.d.ts.map +1 -1
- package/dist/schedules/routes.js +6 -0
- package/dist/schedules/routes.js.map +1 -1
- package/dist/sources/routes.d.ts +2 -2
- package/dist/sources/routes.d.ts.map +1 -1
- package/dist/studio/apps-standalone/fixture.js +3 -3
- package/dist/studio/assets/{KnowledgeGraph-D6RRLDnV.js → KnowledgeGraph-BrHcKpFT.js} +1 -1
- package/dist/studio/assets/index-BCVvMebl.css +32 -0
- package/dist/studio/assets/{index-BLo9vFQI.js → index-BqB2Ydq-.js} +327 -315
- package/dist/studio/editors/wicked-apps/editor.json +1 -1
- package/dist/studio/editors/wicked-apps/index.html +1 -1
- package/dist/studio/editors/wicked-deck/editor.json +1 -1
- package/dist/studio/editors/wicked-deck/index.html +1 -1
- package/dist/studio/editors/wicked-doc/editor.json +1 -1
- package/dist/studio/editors/wicked-doc/index.html +1 -1
- package/dist/studio/editors/wicked-insights/editor.json +1 -1
- package/dist/studio/editors/wicked-insights/index.html +1 -1
- package/dist/studio/editors/wicked-page/editor.json +1 -1
- package/dist/studio/editors/wicked-page/index.html +1 -1
- package/dist/studio/editors/wicked-video/editor.json +1 -1
- package/dist/studio/editors/wicked-video/index.html +1 -1
- package/dist/studio/index.html +2 -2
- package/dist/studio/testid-inventory.json +347 -35
- package/endpoint-manifest.json +16 -1
- package/package.json +4 -4
- package/dist/studio/assets/index-xW21Gkam.css +0 -32
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* (J6 K1) The scope card of a `domain-extraction` launch preview: garden's `scripts/domain/scope.py` over the
|
|
3
|
+
* repository's checkout and its estate store (no model call), mapped to the {@link DomainScopeCard} the launch form
|
|
4
|
+
* shows. The run's own `domain-run` step re-derives the same scope from the same script and refuses when its hash no
|
|
5
|
+
* longer matches the one Start carried, so the card and the run never disagree silently.
|
|
6
|
+
*/
|
|
7
|
+
import { spawn } from 'node:child_process';
|
|
8
|
+
import { mkdtemp, readFile, rm, stat, writeFile } from 'node:fs/promises';
|
|
9
|
+
import { tmpdir } from 'node:os';
|
|
10
|
+
import { join } from 'node:path';
|
|
11
|
+
import { childEnvWithBootEstateDb } from '../core/governance-store.js';
|
|
12
|
+
import { gardenLauncher, unmarkedEnv } from '../learn/scheduler.js';
|
|
13
|
+
const STDERR_CAP = 64 * 1024;
|
|
14
|
+
/**
|
|
15
|
+
* Runs the launcher in its own process group, so the time limit ends the whole tree (the launcher runs Python, maybe
|
|
16
|
+
* through uv, as children of its own); resolves once every process holding its output has closed.
|
|
17
|
+
*/
|
|
18
|
+
export const execScope = (cmd, args, opts) => new Promise((resolve) => {
|
|
19
|
+
const group = process.platform !== 'win32';
|
|
20
|
+
let stderr = '';
|
|
21
|
+
let timedOut = false;
|
|
22
|
+
let settled = false;
|
|
23
|
+
const done = (r) => {
|
|
24
|
+
if (settled)
|
|
25
|
+
return;
|
|
26
|
+
settled = true;
|
|
27
|
+
clearTimeout(timer);
|
|
28
|
+
resolve(r);
|
|
29
|
+
};
|
|
30
|
+
// childEnvWithBootEstateDb: no daemon governance store and no raw credential reach garden (crew#495, crew#1843).
|
|
31
|
+
const child = spawn(cmd, args, { env: childEnvWithBootEstateDb(opts.env), stdio: ['ignore', 'ignore', 'pipe'], detached: group });
|
|
32
|
+
const timer = setTimeout(() => {
|
|
33
|
+
timedOut = true;
|
|
34
|
+
try {
|
|
35
|
+
if (group && child.pid !== undefined)
|
|
36
|
+
process.kill(-child.pid, 'SIGKILL');
|
|
37
|
+
else if (child.pid !== undefined) {
|
|
38
|
+
// Windows has no process groups: taskkill ends the tree, and the limit answers when it is done, whether or
|
|
39
|
+
// not a descendant still holds stderr.
|
|
40
|
+
spawn('taskkill', ['/pid', String(child.pid), '/T', '/F'], { env: childEnvWithBootEstateDb(process.env), stdio: 'ignore' }).on('close', () => done({ outcome: 'timeout', stderr }));
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
// already gone
|
|
45
|
+
}
|
|
46
|
+
}, opts.timeoutMs);
|
|
47
|
+
// The last 64 KiB: the failure line a script prints last is the one the preview shows.
|
|
48
|
+
child.stderr?.on('data', (b) => {
|
|
49
|
+
stderr += b.toString('utf8');
|
|
50
|
+
if (stderr.length > STDERR_CAP)
|
|
51
|
+
stderr = stderr.slice(-STDERR_CAP);
|
|
52
|
+
});
|
|
53
|
+
child.on('error', (err) => done({ outcome: 'spawn', error: err.message }));
|
|
54
|
+
child.on('close', (code) => done(timedOut ? { outcome: 'timeout', stderr } : { outcome: 'exit', code: code ?? 1, stderr }));
|
|
55
|
+
});
|
|
56
|
+
/** CardDemo's card takes under 5 s and crew's about 31 s (DES-j6-build S2); past this the preview says so. */
|
|
57
|
+
export const SCOPE_TIMEOUT_MS = 75_000;
|
|
58
|
+
const isObj = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
59
|
+
const strs = (v) => (Array.isArray(v) ? v.filter((x) => typeof x === 'string') : []);
|
|
60
|
+
/** What a phrase matched: the code names (TS defs, or the COBOL program), else its files. */
|
|
61
|
+
function matchedOf(v) {
|
|
62
|
+
if (Array.isArray(v))
|
|
63
|
+
return strs(v);
|
|
64
|
+
if (!isObj(v))
|
|
65
|
+
return [];
|
|
66
|
+
const defs = strs(v['defs']);
|
|
67
|
+
return defs.length > 0 ? defs : strs(v['files']);
|
|
68
|
+
}
|
|
69
|
+
/** scope.py's output (`build_scope`) as the card, or `null` when it is not one (no 64-hex `scope_hash`). */
|
|
70
|
+
export function scopeCardOf(raw) {
|
|
71
|
+
if (!isObj(raw))
|
|
72
|
+
return null;
|
|
73
|
+
const scopeHash = raw['scope_hash'];
|
|
74
|
+
if (typeof scopeHash !== 'string' || !/^[0-9a-f]{64}$/u.test(scopeHash))
|
|
75
|
+
return null;
|
|
76
|
+
// Object.fromEntries defines each phrase as an own key (a phrase "__proto__" included).
|
|
77
|
+
const phrases = Object.fromEntries(isObj(raw['phrases']) ? Object.entries(raw['phrases']).map(([p, v]) => [p, matchedOf(v)]) : []);
|
|
78
|
+
const n = raw['n_targets'];
|
|
79
|
+
const more = raw['reached_more'];
|
|
80
|
+
return {
|
|
81
|
+
scopeHash,
|
|
82
|
+
phrases,
|
|
83
|
+
unmatchedPhrases: strs(raw['unmatched_phrases']),
|
|
84
|
+
files: strs(raw['target_files']),
|
|
85
|
+
targets: typeof n === 'number' && Number.isSafeInteger(n) ? n : 0,
|
|
86
|
+
reachedFrom: strs(raw['reached_shown']),
|
|
87
|
+
reachedMore: typeof more === 'number' && Number.isSafeInteger(more) ? more : 0,
|
|
88
|
+
questions: strs(raw['questions']),
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
/** The tail of a script's stderr worth showing a person: its last non-empty line, bounded. */
|
|
92
|
+
function lastLine(stderr) {
|
|
93
|
+
const lines = stderr.split('\n').map((l) => l.trim()).filter((l) => l !== '');
|
|
94
|
+
const last = lines[lines.length - 1] ?? '';
|
|
95
|
+
return last.length > 300 ? `${last.slice(0, 300)}…` : last;
|
|
96
|
+
}
|
|
97
|
+
/** The largest scope file the preview reads (it holds every target; the card needs a summary). */
|
|
98
|
+
export const SCOPE_FILE_MAX_BYTES = 16 * 1024 * 1024;
|
|
99
|
+
/**
|
|
100
|
+
* The card for `scope` over the checkout at `root` and the estate store `db`, or why there is none: never throws.
|
|
101
|
+
* Runs garden through its launcher under `gardenRoot` (`$WICKED_GARDEN_ROOT`, else the live plugin), in a scratch
|
|
102
|
+
* directory it removes after the whole process tree has ended.
|
|
103
|
+
*/
|
|
104
|
+
export async function scopeCardFor(opts) {
|
|
105
|
+
let dir;
|
|
106
|
+
try {
|
|
107
|
+
dir = await mkdtemp(join(tmpdir(), 'wicked-domain-scope-'));
|
|
108
|
+
}
|
|
109
|
+
catch (err) {
|
|
110
|
+
return { error: `the scope could not start: ${err.message}` };
|
|
111
|
+
}
|
|
112
|
+
try {
|
|
113
|
+
return await runScope(dir, opts);
|
|
114
|
+
}
|
|
115
|
+
catch (err) {
|
|
116
|
+
return { error: `the scope could not be read: ${err.message}` };
|
|
117
|
+
}
|
|
118
|
+
finally {
|
|
119
|
+
// A scratch directory left behind does not unmake the card the person asked for; the OS temp dir clears it.
|
|
120
|
+
await rm(dir, { recursive: true, force: true }).catch(() => undefined);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
async function runScope(dir, opts) {
|
|
124
|
+
const input = join(dir, 'scope-in.json');
|
|
125
|
+
const out = join(dir, 'scope.json');
|
|
126
|
+
await writeFile(input, JSON.stringify({ intent: opts.scope.intent, ...(opts.scope.phrases !== undefined ? { phrases: opts.scope.phrases } : {}) }));
|
|
127
|
+
const timeoutMs = opts.timeoutMs ?? SCOPE_TIMEOUT_MS;
|
|
128
|
+
const r = await (opts.exec ?? execScope)(gardenLauncher(opts.gardenRoot), ['run', 'scripts/domain/scope.py', '--root', opts.root, '--db', opts.db, '--scope', input, '--out', out], { env: unmarkedEnv(opts.env ?? process.env, opts.gardenRoot), timeoutMs });
|
|
129
|
+
if (r.outcome === 'spawn')
|
|
130
|
+
return { error: `the scope could not start garden: ${r.error}` };
|
|
131
|
+
const why = lastLine(r.stderr);
|
|
132
|
+
if (r.outcome === 'timeout')
|
|
133
|
+
return { error: `the scope did not finish in ${Math.round(timeoutMs / 1000)} s${why !== '' ? ` (${why})` : ''}` };
|
|
134
|
+
if (r.code !== 0)
|
|
135
|
+
return { error: `the scope failed${why !== '' ? `: ${why}` : ''}` };
|
|
136
|
+
let size;
|
|
137
|
+
try {
|
|
138
|
+
size = (await stat(out)).size;
|
|
139
|
+
}
|
|
140
|
+
catch {
|
|
141
|
+
return { error: 'the scope wrote no card' };
|
|
142
|
+
}
|
|
143
|
+
if (size > (opts.maxCardBytes ?? SCOPE_FILE_MAX_BYTES)) {
|
|
144
|
+
return { error: `the scope is too large to show (${Math.round(size / 2 ** 20)} MB); narrow it to fewer files or phrases` };
|
|
145
|
+
}
|
|
146
|
+
let raw;
|
|
147
|
+
try {
|
|
148
|
+
raw = JSON.parse(await readFile(out, 'utf8'));
|
|
149
|
+
}
|
|
150
|
+
catch {
|
|
151
|
+
return { error: 'the scope wrote a card that is not JSON' };
|
|
152
|
+
}
|
|
153
|
+
const card = scopeCardOf(raw);
|
|
154
|
+
return card !== null ? { card } : { error: 'the scope wrote a card this daemon cannot read' };
|
|
155
|
+
}
|
|
156
|
+
//# sourceMappingURL=domain-scope.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"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CAAC,EAAE,KAAK,EAAE,gDAAgD,EAAE,CAAC;AAChG,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How a recorded eval run's `rule_store` reads on the wire (crew#1934).
|
|
3
|
+
*
|
|
4
|
+
* Studio decides "was this run judged against THIS daemon's rules?" by comparing a run's `rule_store`
|
|
5
|
+
* (GET /testing/evals[/:id]) with the `core.db` path GET /diagnostics lists. Diagnostics shows paths
|
|
6
|
+
* home-masked (`~/…`, the ui-text backstop), while the run route records the absolute `--db`; compared
|
|
7
|
+
* as plain strings, every run on a daemon whose store lives under the home directory read as "another
|
|
8
|
+
* rule store", and Steering dropped its per-rule eval marks.
|
|
9
|
+
*
|
|
10
|
+
* The rule here: COMPARE canonical paths, MASK only for display. The daemon compares the run's store
|
|
11
|
+
* with its own, both sides canonical (`~` expanded, resolved, symlinks followed); a run on this
|
|
12
|
+
* daemon's store then renders exactly as diagnostics renders `core.db`, and any other store renders
|
|
13
|
+
* through the same home scrub. Studio's string equality relays this answer, and history rows recorded
|
|
14
|
+
* before the fix (absolute, or under another spelling of the same file) read correctly too.
|
|
15
|
+
*
|
|
16
|
+
* A DIFFERENT store whose masked spelling equals this daemon's (another user's home at the same
|
|
17
|
+
* relative path, say a copied history) gets {@link OTHER_STORE_SUFFIX}, so the strings never match
|
|
18
|
+
* when the stores don't.
|
|
19
|
+
*/
|
|
20
|
+
/** One store path in canonical form: `~` expanded, absolute, symlinks followed (the file's parent when
|
|
21
|
+
* the file itself is gone, so a deleted store still compares by its real directory). */
|
|
22
|
+
export declare function canonicalStorePath(path: string, home?: string): string;
|
|
23
|
+
/** Appended to another store's masked spelling when it would otherwise read as this daemon's. */
|
|
24
|
+
export declare const OTHER_STORE_SUFFIX = " (a different store)";
|
|
25
|
+
/**
|
|
26
|
+
* A reader for recorded runs' `rule_store`, bound to this daemon's `--db`: same store (canonically)
|
|
27
|
+
* → the exact string diagnostics shows for `core.db`; any other store → its own path, home-masked.
|
|
28
|
+
* Canonical forms are memoised per distinct stored string, so a long history costs one realpath per
|
|
29
|
+
* store, not per row.
|
|
30
|
+
*/
|
|
31
|
+
export declare function ruleStoreReader(dbPath: unknown, home?: string): (stored: unknown) => unknown;
|
|
32
|
+
//# sourceMappingURL=eval-rule-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eval-rule-store.d.ts","sourceRoot":"","sources":["../../src/api/eval-rule-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAOH;yFACyF;AACzF,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE,MAAkB,GAAG,MAAM,CAYjF;AAED,iGAAiG;AACjG,eAAO,MAAM,kBAAkB,yBAAyB,CAAC;AAOzD;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,GAAE,MAAkB,GAAG,CAAC,MAAM,EAAE,OAAO,KAAK,OAAO,CAqBvG"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How a recorded eval run's `rule_store` reads on the wire (crew#1934).
|
|
3
|
+
*
|
|
4
|
+
* Studio decides "was this run judged against THIS daemon's rules?" by comparing a run's `rule_store`
|
|
5
|
+
* (GET /testing/evals[/:id]) with the `core.db` path GET /diagnostics lists. Diagnostics shows paths
|
|
6
|
+
* home-masked (`~/…`, the ui-text backstop), while the run route records the absolute `--db`; compared
|
|
7
|
+
* as plain strings, every run on a daemon whose store lives under the home directory read as "another
|
|
8
|
+
* rule store", and Steering dropped its per-rule eval marks.
|
|
9
|
+
*
|
|
10
|
+
* The rule here: COMPARE canonical paths, MASK only for display. The daemon compares the run's store
|
|
11
|
+
* with its own, both sides canonical (`~` expanded, resolved, symlinks followed); a run on this
|
|
12
|
+
* daemon's store then renders exactly as diagnostics renders `core.db`, and any other store renders
|
|
13
|
+
* through the same home scrub. Studio's string equality relays this answer, and history rows recorded
|
|
14
|
+
* before the fix (absolute, or under another spelling of the same file) read correctly too.
|
|
15
|
+
*
|
|
16
|
+
* A DIFFERENT store whose masked spelling equals this daemon's (another user's home at the same
|
|
17
|
+
* relative path, say a copied history) gets {@link OTHER_STORE_SUFFIX}, so the strings never match
|
|
18
|
+
* when the stores don't.
|
|
19
|
+
*/
|
|
20
|
+
import { realpathSync } from 'node:fs';
|
|
21
|
+
import { homedir } from 'node:os';
|
|
22
|
+
import { basename, dirname, join, resolve } from 'node:path';
|
|
23
|
+
import { scrubHomePaths } from './ui-text.js';
|
|
24
|
+
/** One store path in canonical form: `~` expanded, absolute, symlinks followed (the file's parent when
|
|
25
|
+
* the file itself is gone, so a deleted store still compares by its real directory). */
|
|
26
|
+
export function canonicalStorePath(path, home = homedir()) {
|
|
27
|
+
const expanded = path === '~' ? home : /^~[\\/]/.test(path) ? join(home, path.slice(2)) : path;
|
|
28
|
+
const abs = resolve(expanded);
|
|
29
|
+
try {
|
|
30
|
+
return realpathSync.native(abs);
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
try {
|
|
34
|
+
return join(realpathSync.native(dirname(abs)), basename(abs));
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return abs;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/** Appended to another store's masked spelling when it would otherwise read as this daemon's. */
|
|
42
|
+
export const OTHER_STORE_SUFFIX = ' (a different store)';
|
|
43
|
+
/** The usable `--db` of this daemon, or null (a stub route set, an in-memory store). */
|
|
44
|
+
function daemonDb(dbPath) {
|
|
45
|
+
return typeof dbPath === 'string' && dbPath !== '' && dbPath !== ':memory:' ? dbPath : null;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* A reader for recorded runs' `rule_store`, bound to this daemon's `--db`: same store (canonically)
|
|
49
|
+
* → the exact string diagnostics shows for `core.db`; any other store → its own path, home-masked.
|
|
50
|
+
* Canonical forms are memoised per distinct stored string, so a long history costs one realpath per
|
|
51
|
+
* store, not per row.
|
|
52
|
+
*/
|
|
53
|
+
export function ruleStoreReader(dbPath, home = homedir()) {
|
|
54
|
+
const db = daemonDb(dbPath);
|
|
55
|
+
const own = db === null ? null : canonicalStorePath(db, home);
|
|
56
|
+
// Diagnostics lists core.db as the file under the db's resolved parent (listStoreFiles), i.e.
|
|
57
|
+
// `resolve(db)`, and its backstop scrubs that. (No literal join-under-state-home here: the
|
|
58
|
+
// state-home-subtrees audit greps src/ text, comments included.)
|
|
59
|
+
const ownDisplay = db === null ? null : scrubHomePaths(resolve(db), home);
|
|
60
|
+
const seen = new Map();
|
|
61
|
+
return (stored) => {
|
|
62
|
+
if (typeof stored !== 'string' || stored === '')
|
|
63
|
+
return stored;
|
|
64
|
+
let shown = seen.get(stored);
|
|
65
|
+
if (shown === undefined) {
|
|
66
|
+
if (own !== null && ownDisplay !== null && canonicalStorePath(stored, home) === own)
|
|
67
|
+
shown = ownDisplay;
|
|
68
|
+
else {
|
|
69
|
+
const masked = scrubHomePaths(stored, home);
|
|
70
|
+
shown = masked === ownDisplay ? `${masked}${OTHER_STORE_SUFFIX}` : masked;
|
|
71
|
+
}
|
|
72
|
+
seen.set(stored, shown);
|
|
73
|
+
}
|
|
74
|
+
return shown;
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=eval-rule-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eval-rule-store.js","sourceRoot":"","sources":["../../src/api/eval-rule-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C;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C9F,2FAA2F;IAC3F,iEAAiE;IACjE,MAAM,UAAU,GAAG,EAAE,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,cAAc,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC;IAC1E,MAAM,IAAI,GAAG,IAAI,GAAG,EAAkB,CAAC;IACvC,OAAO,CAAC,MAAM,EAAE,EAAE;QAChB,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,EAAE;YAAE,OAAO,MAAM,CAAC;QAC/D,IAAI,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAC7B,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,IAAI,GAAG,KAAK,IAAI,IAAI,UAAU,KAAK,IAAI,IAAI,kBAAkB,CAAC,MAAM,EAAE,IAAI,CAAC,KAAK,GAAG;gBAAE,KAAK,GAAG,UAAU,CAAC;iBACnG,CAAC;gBACJ,MAAM,MAAM,GAAG,cAAc,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;gBAC5C,KAAK,GAAG,MAAM,KAAK,UAAU,CAAC,CAAC,CAAC,GAAG,MAAM,GAAG,kBAAkB,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC;YAC5E,CAAC;YACD,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QAC1B,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/api/mcp.d.ts
CHANGED
|
@@ -84,6 +84,7 @@ import type { FastifyInstance, FastifyRequest } from 'fastify';
|
|
|
84
84
|
import { z } from '../zod.js';
|
|
85
85
|
import type { Actor, McpServer } from '../core/types.js';
|
|
86
86
|
import type { McpBroker } from '../mcp/broker.js';
|
|
87
|
+
import type { RowWriteGrants } from '../sources/routes.js';
|
|
87
88
|
import type { AskServer } from '../mcp/ask-server.js';
|
|
88
89
|
import type { McpPolicies } from '../mcp/policies.js';
|
|
89
90
|
import { type McpRegistry } from '../mcp/registry.js';
|
|
@@ -283,6 +284,8 @@ export interface McpRouteDeps {
|
|
|
283
284
|
slug: string;
|
|
284
285
|
name: string;
|
|
285
286
|
}>>;
|
|
287
|
+
/** (crew#1906) A rename withdraws the old name's row-write grants (K2b's store). Absent = no apps store. */
|
|
288
|
+
rowWriteGrants?: RowWriteGrants;
|
|
286
289
|
}
|
|
287
290
|
/**
|
|
288
291
|
* (DES-KNOWLEDGE-DATA-001 §5.5) The approval tokens a restore withdraws: an approval covers a tool's SAVED schema,
|
package/dist/api/mcp.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp.d.ts","sourceRoot":"","sources":["../../src/api/mcp.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiFG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAgB,cAAc,EAAE,MAAM,SAAS,CAAC;AAC7E,OAAO,EAAU,CAAC,EAAE,MAAM,WAAW,CAAC;AAEtC,OAAO,KAAK,EAAE,KAAK,EAAwF,SAAS,EAA2F,MAAM,kBAAkB,CAAC;AAExO,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAGtD,OAAO,EAAiF,KAAK,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAGrI,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACjE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAA2B,KAAK,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAEzF,OAAO,KAAK,EAA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@ export async function restoreWithdrawals(p, current, restored) {
|
|
|
513
513
|
return [...out].sort();
|
|
514
514
|
}
|
|
515
515
|
export function registerMcpRoutes(app, deps) {
|
|
516
|
+
/**
|
|
517
|
+
* (crew#1906) Once a rename has landed: the old name's row-write grants go (an app naming it needs a new grant). A
|
|
518
|
+
* failure is audited; the grants it leaves name no source, and they go before any source takes that name again.
|
|
519
|
+
*/
|
|
520
|
+
const withdrawRenamedGrants = async (from) => {
|
|
521
|
+
if (deps.rowWriteGrants === undefined)
|
|
522
|
+
return {};
|
|
523
|
+
try {
|
|
524
|
+
return { withdrawnGrants: await deps.rowWriteGrants.withdrawForSource(from, 'source_renamed') };
|
|
525
|
+
}
|
|
526
|
+
catch {
|
|
527
|
+
return { withdrawFailed: true };
|
|
528
|
+
}
|
|
529
|
+
};
|
|
530
|
+
/**
|
|
531
|
+
* (crew#1906 r1) Row-write grants an earlier holder of `name` left (a withdrawal that failed after its own rename, or a
|
|
532
|
+
* removed source) go before a rename gives a source that name, as Allow writes does before it turns on: a name never
|
|
533
|
+
* hands a source grants nobody gave it. Only a rename its checks and rules allow gets here, so a refusal changes no
|
|
534
|
+
* grant. No grant can be made on `name` meanwhile: a grant resolves its source, and no source has that name.
|
|
535
|
+
*/
|
|
536
|
+
const clearName = async (name) => {
|
|
537
|
+
if (deps.rowWriteGrants === undefined)
|
|
538
|
+
return;
|
|
539
|
+
try {
|
|
540
|
+
await deps.rowWriteGrants.withdrawForSource(name, 'name_reused');
|
|
541
|
+
}
|
|
542
|
+
catch (e) {
|
|
543
|
+
throw new McpRegistryError(500, 'withdraw_failed', `nothing was renamed: row-write grants left on the name ${name} from before could not be withdrawn (${e instanceof Error ? e.message : String(e)}); try again`);
|
|
544
|
+
}
|
|
545
|
+
};
|
|
516
546
|
// The MCP ask tool (streamable HTTP, stateless): worker-facing, the unit token in Authorization.
|
|
517
547
|
app.post(`${V}/mcp/ask`, { config: { manifest: { statusCodes: [200, 401, 503] } } }, async (req, reply) => {
|
|
518
548
|
if (deps.askServer === undefined)
|
|
@@ -773,8 +803,10 @@ export function registerMcpRoutes(app, deps) {
|
|
|
773
803
|
if (using.length !== listed.size || using.some((a) => !listed.has(a.slug))) {
|
|
774
804
|
throw new McpRegistryError(409, 'apps_bound', `${using.length} app${using.length === 1 ? ' uses' : 's use'} ${from}: confirm the rename with exactly that list`, undefined, { apps: using });
|
|
775
805
|
}
|
|
776
|
-
if (p === undefined)
|
|
806
|
+
if (p === undefined) {
|
|
807
|
+
await clearName(to);
|
|
777
808
|
return { server: await renamed(), rules: [], apps: using };
|
|
809
|
+
}
|
|
778
810
|
// Every rule naming the source is copied to the new name first (one edit: restrictions and exemptions), then
|
|
779
811
|
// the rules are judged as they will stand; a refusal or a failed write puts them back.
|
|
780
812
|
const originals = await p.copyRules(from, to).catch((e) => { auditPartial(deps, req, e, [`mcp:${to}`]); throw e; });
|
|
@@ -798,8 +830,11 @@ export function registerMcpRoutes(app, deps) {
|
|
|
798
830
|
// offered only when nothing blocks the current one; when something does, the next step is that rule.
|
|
799
831
|
const said = judged.rules.map((id) => `${id} (${judged.unjudged.has(id) ? 'crew cannot judge its trigger, so it counts for both names' : (judged.names.get(id) ?? []).map((n) => `${n}, the ${n === from ? 'current' : 'new'} name`).join('; ')})`);
|
|
800
832
|
const blocking = judged.rules.filter((id) => (judged.names.get(id) ?? [from]).includes(from));
|
|
833
|
+
// (crew#1906) A rule that ships with crew is never the one to edit: the source keeps its name instead.
|
|
834
|
+
const own = blocking.filter((id) => !judged.shipped.has(id));
|
|
835
|
+
const shipped = blocking.filter((id) => judged.shipped.has(id));
|
|
801
836
|
const next = blocking.length > 0
|
|
802
|
-
? `. To rename it, first change or retire ${
|
|
837
|
+
? `${own.length > 0 ? `. To rename it, first change or retire ${own.join(', ')}` : ''}${shipped.length > 0 ? `. ${shipped.join(', ')} ship${shipped.length === 1 ? 's' : ''} with crew, so a source ${shipped.length === 1 ? 'its trigger' : 'their triggers'} can match keeps its name` : ''}`
|
|
803
838
|
: judged.subjects.length === 0 ? `. A new name no rule's trigger can match avoids this` : '';
|
|
804
839
|
throw new McpRegistryError(409, 'rules_differ', `the trigger of rule${judged.rules.length === 1 ? '' : 's'} ${said.join(', ')} can match the source's name in a call or its result, and crew cannot carry a trigger to a new name, so nothing was renamed${next}`, undefined, { rules: judged.rules, subjects: judged.subjects });
|
|
805
840
|
}
|
|
@@ -811,6 +846,13 @@ export function registerMcpRoutes(app, deps) {
|
|
|
811
846
|
await back();
|
|
812
847
|
throw e;
|
|
813
848
|
}
|
|
849
|
+
try {
|
|
850
|
+
await clearName(to);
|
|
851
|
+
}
|
|
852
|
+
catch (e) {
|
|
853
|
+
await back();
|
|
854
|
+
throw e;
|
|
855
|
+
}
|
|
814
856
|
try {
|
|
815
857
|
server = await renamed();
|
|
816
858
|
}
|
|
@@ -822,7 +864,8 @@ export function registerMcpRoutes(app, deps) {
|
|
|
822
864
|
}
|
|
823
865
|
return { server, rules: originals.map((o) => o.id), apps: using };
|
|
824
866
|
});
|
|
825
|
-
|
|
867
|
+
const grants = await withdrawRenamedGrants(from);
|
|
868
|
+
deps.audit.record('mcp.server.renamed', actor, { detail: { id: outcome.server.id, from, to, apps: outcome.apps.map((a) => a.slug), rules: outcome.rules, ...grants } });
|
|
826
869
|
for (const id of outcome.rules)
|
|
827
870
|
deps.audit.record('governance.rule.upserted', actor, { detail: { id, source: 'mcp-rename' } });
|
|
828
871
|
return serverFor(actor, outcome.server);
|
|
@@ -830,7 +873,8 @@ export function registerMcpRoutes(app, deps) {
|
|
|
830
873
|
catch (err) {
|
|
831
874
|
if (err instanceof McpRenameCommitted) {
|
|
832
875
|
// It landed (rules and all); only its answer is missing. Audited as what it is, and said so.
|
|
833
|
-
|
|
876
|
+
const grants = await withdrawRenamedGrants(from);
|
|
877
|
+
deps.audit.record('mcp.server.renamed', actor, { detail: { from, to, unread: true, rules: moved, ...grants } });
|
|
834
878
|
for (const id of moved)
|
|
835
879
|
deps.audit.record('governance.rule.upserted', actor, { detail: { id, source: 'mcp-rename' } });
|
|
836
880
|
return reply.code(502).send({ error: `${err.message}; read the source list again`, code: 'renamed_unread' });
|
|
@@ -849,12 +893,14 @@ export function registerMcpRoutes(app, deps) {
|
|
|
849
893
|
await exclusive(req.params.name, async () => {
|
|
850
894
|
// (DES-PM-001 §3.2, Q-PM5) Removing a PM source drops its links, and the last GitHub one would hand `#N` back
|
|
851
895
|
// to the daemon's own `gh`: a person's only. Judged on the record being removed, inside the server's lock.
|
|
852
|
-
|
|
896
|
+
const entry = await r.get(req.params.name);
|
|
897
|
+
if (entry.pm !== undefined && !mayGrantWrite(deps.actorOf(req))) {
|
|
853
898
|
refused = true;
|
|
854
899
|
return;
|
|
855
900
|
}
|
|
856
901
|
if (deps.policies !== undefined) {
|
|
857
|
-
|
|
902
|
+
// (crew#1906) The tokens of every name it had: a rename keeps the old name's, and nothing else can take them.
|
|
903
|
+
const tokens = [...new Set((await Promise.all([req.params.name, ...(entry.formerNames ?? [])].map((n) => deps.policies.tokensOf(n)))).flat())];
|
|
858
904
|
if (tokens.length > 0) {
|
|
859
905
|
const rules = await deps.policies.withdraw(tokens).catch((e) => { auditPartial(deps, req, e, tokens); throw e; });
|
|
860
906
|
deps.audit.record('mcp.approval.withdrawn', deps.actorOf(req), { detail: { subjects: tokens, rules, why: 'server_removed' } });
|