@north-light/crouter 0.3.222 → 0.3.223
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/builtin-memory/internal/memory-loading.md +4 -4
- package/dist/clients/attach/viewer.js +391 -391
- package/dist/clients/inbox/page-adapter.js +2 -1
- package/dist/clients/inbox/tui/panel.js +23 -4
- package/dist/clients/inbox/tui/render.js +6 -0
- package/dist/clients/inbox/tui/types.d.ts +8 -0
- package/dist/commands/memory/shared.d.ts +2 -2
- package/dist/commands/memory/shared.js +11 -6
- package/dist/commands/pkg/browse/doc-view.js +2 -0
- package/dist/core/__tests__/profile-project-memory-delivery.test.js +69 -2
- package/dist/core/substrate/frontmatter-validation.d.ts +2 -5
- package/dist/core/substrate/frontmatter-validation.js +8 -4
- package/dist/core/substrate/gate.d.ts +4 -1
- package/dist/core/substrate/gate.js +5 -0
- package/dist/core/substrate/on-read.js +4 -4
- package/dist/core/substrate/render.js +13 -18
- package/dist/core/substrate/schema.d.ts +12 -7
- package/dist/core/substrate/schema.js +10 -6
- package/dist/core/substrate/surface-match.d.ts +8 -7
- package/dist/core/substrate/surface-match.js +15 -14
- package/package.json +1 -1
- package/runtime.lock.json +2 -2
|
@@ -12,6 +12,7 @@ export class PageAdapter {
|
|
|
12
12
|
this.manifest = opts.ticket.manifest;
|
|
13
13
|
this.panel = mountPanel({
|
|
14
14
|
manifest: opts.ticket.manifest,
|
|
15
|
+
document: opts.ticket.document,
|
|
15
16
|
productKinds: opts.productKinds,
|
|
16
17
|
initialResponses: opts.ticket.progress,
|
|
17
18
|
cols: opts.cols,
|
|
@@ -46,7 +47,7 @@ export class PageAdapter {
|
|
|
46
47
|
}
|
|
47
48
|
reload(ticket) {
|
|
48
49
|
this.manifest = ticket.manifest;
|
|
49
|
-
this.panel.loadPage(ticket.manifest, { initialResponses: ticket.progress, productKinds: this.opts.productKinds });
|
|
50
|
+
this.panel.loadPage(ticket.manifest, { document: ticket.document, initialResponses: ticket.progress, productKinds: this.opts.productKinds });
|
|
50
51
|
this.opts.onDirty();
|
|
51
52
|
}
|
|
52
53
|
close() { this.panel.unmount(); }
|
|
@@ -1,13 +1,32 @@
|
|
|
1
|
+
import { projectPageDisplayMarkdown } from '../../../core/human/page-markdown.js';
|
|
1
2
|
import { handleKeypress } from './input.js';
|
|
2
3
|
import { clampItemReviewScroll, renderFinal, renderItemReview, renderOverview } from './render.js';
|
|
3
4
|
import { pageComplete, slotAnswered } from './slots.js';
|
|
4
|
-
|
|
5
|
+
/** Same projection the inline chat block reads (page-block.ts) — the authored
|
|
6
|
+
* prose outside slot tags. A malformed or unreadable document just yields no
|
|
7
|
+
* display content here, same as the inline block's own reload() fallback. */
|
|
8
|
+
function displayMarkdownOf(manifest, document) {
|
|
9
|
+
if (manifest.dialect !== 'jsx' || document === undefined)
|
|
10
|
+
return '';
|
|
11
|
+
try {
|
|
12
|
+
return projectPageDisplayMarkdown(document, manifest);
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
return '';
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function buildInitialState(manifest, document, initialResponses, productKinds, editorAvailable, wrapWidth) {
|
|
5
19
|
const responses = new Map();
|
|
6
20
|
const validIds = new Set(manifest.slots.flatMap((slot) => slot.id === undefined ? [] : [slot.id]));
|
|
7
21
|
for (const [id, response] of Object.entries(initialResponses ?? {}))
|
|
8
22
|
if (validIds.has(id))
|
|
9
23
|
responses.set(id, response);
|
|
10
|
-
const
|
|
24
|
+
const displayMarkdown = displayMarkdownOf(manifest, document);
|
|
25
|
+
// Single-slot pages skip straight to item-review to save a step — but only
|
|
26
|
+
// when there is no display prose to show first; otherwise that prose would
|
|
27
|
+
// never be seen.
|
|
28
|
+
const phase = manifest.slots.length === 1 && displayMarkdown === '' ? 'item-review' : 'overview';
|
|
29
|
+
const state = { phase, currentIndex: 0, manifest, displayMarkdown, slots: manifest.slots, responses, productKinds, inputMode: null, selectedAction: 0, bodyMode: 'question', scrollOffset: 0, bodyScrollOffsets: { question: 0 }, hscrollOffset: 0, hscrollMax: 0, wrapWidth, editorAvailable };
|
|
11
30
|
const first = manifest.slots.findIndex((slot) => slot.id !== undefined && !slotAnswered(state, slot));
|
|
12
31
|
if (first >= 0)
|
|
13
32
|
state.currentIndex = first;
|
|
@@ -16,7 +35,7 @@ function buildInitialState(manifest, initialResponses, productKinds, editorAvail
|
|
|
16
35
|
export function collectResponses(state) { return Object.fromEntries(state.responses); }
|
|
17
36
|
function rebindPersist(internals) { internals.state.persist = () => internals.callbacks.onProgress?.(collectResponses(internals.state)); }
|
|
18
37
|
export function mountPanel(opts) {
|
|
19
|
-
const internals = { state: buildInitialState(opts.manifest, opts.initialResponses, opts.productKinds ?? [], opts.onEditorRequest !== undefined, opts.cols), cols: opts.cols, rows: opts.rows, mounted: true, callbacks: { onProgress: opts.onProgress, onComplete: opts.onComplete, onExit: opts.onExit, onDirty: opts.onDirty, onEditorRequest: opts.onEditorRequest } };
|
|
38
|
+
const internals = { state: buildInitialState(opts.manifest, opts.document, opts.initialResponses, opts.productKinds ?? [], opts.onEditorRequest !== undefined, opts.cols), cols: opts.cols, rows: opts.rows, mounted: true, callbacks: { onProgress: opts.onProgress, onComplete: opts.onComplete, onExit: opts.onExit, onDirty: opts.onDirty, onEditorRequest: opts.onEditorRequest } };
|
|
20
39
|
rebindPersist(internals);
|
|
21
40
|
const renderLines = () => {
|
|
22
41
|
if (internals.state.phase === 'overview')
|
|
@@ -51,7 +70,7 @@ export function mountPanel(opts) {
|
|
|
51
70
|
return;
|
|
52
71
|
const prior = collectResponses(internals.state);
|
|
53
72
|
const merged = { ...(loadOpts?.initialResponses ?? {}), ...prior };
|
|
54
|
-
internals.state = buildInitialState(manifest, merged, loadOpts?.productKinds ?? internals.state.productKinds, internals.callbacks.onEditorRequest !== undefined, internals.cols);
|
|
73
|
+
internals.state = buildInitialState(manifest, loadOpts?.document, merged, loadOpts?.productKinds ?? internals.state.productKinds, internals.callbacks.onEditorRequest !== undefined, internals.cols);
|
|
55
74
|
rebindPersist(internals);
|
|
56
75
|
},
|
|
57
76
|
canAcceptHostKeys: () => internals.mounted && internals.state.inputMode === null,
|
|
@@ -29,10 +29,16 @@ function commentLabel(slot, anchor) {
|
|
|
29
29
|
}
|
|
30
30
|
export function renderOverview(state, cols, rows) {
|
|
31
31
|
const maxW = Math.min(Math.max(20, cols - 4), 120);
|
|
32
|
+
const paneW = Math.max(20, cols - 4);
|
|
32
33
|
const lines = ['', ` ${BOLD}${CYAN}${sanitize(state.manifest.title)}${RESET}`];
|
|
33
34
|
if (state.manifest.subtitle)
|
|
34
35
|
for (const line of wrap(sanitize(state.manifest.subtitle), maxW))
|
|
35
36
|
lines.push(` ${DIM}${line}${RESET}`);
|
|
37
|
+
if (state.displayMarkdown !== '') {
|
|
38
|
+
lines.push('');
|
|
39
|
+
for (const line of mdLines(state.displayMarkdown, maxW, paneW))
|
|
40
|
+
lines.push(` ${line}`);
|
|
41
|
+
}
|
|
36
42
|
const hasBody = state.slots.length > 0;
|
|
37
43
|
if (hasBody)
|
|
38
44
|
lines.push(` ${DIM}${hline(maxW)}${RESET}`, '');
|
|
@@ -20,6 +20,10 @@ export interface TuiState {
|
|
|
20
20
|
phase: Phase;
|
|
21
21
|
currentIndex: number;
|
|
22
22
|
manifest: PageManifest;
|
|
23
|
+
/** The authored display JSX (headings, paragraphs, prose outside slots),
|
|
24
|
+
* projected to markdown — same projection the inline chat block uses.
|
|
25
|
+
* Empty when the page has none, or its document was unavailable. */
|
|
26
|
+
displayMarkdown: string;
|
|
23
27
|
slots: PageSlot[];
|
|
24
28
|
responses: Map<string, SlotResponse>;
|
|
25
29
|
productKinds: ProductPageComponents;
|
|
@@ -39,6 +43,9 @@ export interface TuiState {
|
|
|
39
43
|
}
|
|
40
44
|
export interface MountedPanelOpts {
|
|
41
45
|
manifest: PageManifest;
|
|
46
|
+
/** The raw page document — needed only to project display markdown; a jsx
|
|
47
|
+
* page without one just shows no display content, same as a read failure. */
|
|
48
|
+
document?: string;
|
|
42
49
|
productKinds?: ProductPageComponents;
|
|
43
50
|
initialResponses?: PageResponses | null;
|
|
44
51
|
cols: number;
|
|
@@ -55,6 +62,7 @@ export interface MountedPanel {
|
|
|
55
62
|
handleResize(cols: number, rows: number): string[];
|
|
56
63
|
unmount(): void;
|
|
57
64
|
loadPage(manifest: PageManifest, opts?: {
|
|
65
|
+
document?: string;
|
|
58
66
|
initialResponses?: PageResponses | null;
|
|
59
67
|
productKinds?: ProductPageComponents;
|
|
60
68
|
}): void;
|
|
@@ -105,8 +105,8 @@ export declare function overlayParam(name: string, overrides?: Partial<FlagParam
|
|
|
105
105
|
* `--doc-rationale`, because `--rationale` there means why THIS REVISION is
|
|
106
106
|
* happening. Same field, same prose, two flag names that cannot be confused. */
|
|
107
107
|
export declare const DOC_RATIONALE_CONSTRAINT = "Frontmatter rationale \u2014 the observed agent failure that made this doc necessary. Maintainer-facing only: never ships in any delivered surface (boot render, on-read injection, `memory read` content), visible only via `memory read --frontmatter`. Omitting the flag preserves an existing rationale unchanged.";
|
|
108
|
-
export declare const GUIDE_SURFACES = "Every doc appears in its directory\u2019s listing by default (suppress with --unlisted); everything beyond the listing is explicit `surfaces` routing \u2014 entries declaring WHEN the doc delivers and how much. Events: `boot` delivers in the boot catalog every agent sees; `workspace-open` delivers in first-message context when cwd/profile mounts the doc\u2019s project store (project stores only); `read` fires when the agent reads a matching file (globs vs the file\u2019s absolute path and basename, `./`-anchored globs vs its path relative to the store\u2019s owning repo dir, `match-frontmatter` predicates over the read file\u2019s own YAML frontmatter); `memory-read` fires when another memory doc is read (globs vs that doc\u2019s canonical name, `./` anchored to this doc\u2019s own name directory); `command` fires when a matching shell command runs (globs vs the whole command string, `*` crossing `/`). `at` sets how much delivers: `name` the bare tag, `preview` the routing line, `content` the whole body. Each entry is paid by every future agent it fires on, so default down: no surfaces at all is correct for reference depth reached through listings and [[links]], and when a doc fits in a single sentence, deliver `content` directly \u2014 a `preview` routing line would run longer than the doc itself. Sentence-length `content` docs are correct; never pad a memory to be more verbose than the rule or fact it carries.";
|
|
108
|
+
export declare const GUIDE_SURFACES = "Every doc appears in its directory\u2019s listing by default (suppress with --unlisted); everything beyond the listing is explicit `surfaces` routing \u2014 entries declaring WHEN the doc delivers and how much. Events: `boot` delivers in the boot catalog every agent sees; `workspace-open` delivers in first-message context when cwd/profile mounts the doc\u2019s project store (project stores only); `read` fires when the agent reads a matching file (globs vs the file\u2019s absolute path and basename, `./`-anchored globs vs its path relative to the store\u2019s owning repo dir, `match-frontmatter` predicates over the read file\u2019s own YAML frontmatter); `memory-read` fires when another memory doc is read (globs vs that doc\u2019s canonical name, `./` anchored to this doc\u2019s own name directory); `command` fires when a matching shell command runs (globs vs the whole command string, `*` crossing `/`). An entry may also carry `gate`, a node-config predicate using the same vocabulary as the document-level `gate`: event constraints and entry gate both must match, then all participating entries fold to the highest `at` (`content` > `preview` > `name`), with no cross-entry deny precedence. The document-level `gate` remains the hard eligibility check: when it fails, no automatic surface can deliver the document. `at` sets how much delivers: `name` the bare tag, `preview` the routing line, `content` the whole body. Explicit `memory read` and listings remain deliberate access and ignore gates/rungs; only companion docs routed by their `memory-read` entries use entry gates. Each entry is paid by every future agent it fires on, so default down: no surfaces at all is correct for reference depth reached through listings and [[links]], and when a doc fits in a single sentence, deliver `content` directly \u2014 a `preview` routing line would run longer than the doc itself. Sentence-length `content` docs are correct; never pad a memory to be more verbose than the rule or fact it carries.";
|
|
109
109
|
export declare const GUIDE_ROUTING_LINE = "The routing line (--when-and-why-to-read) is the only text an agent reads before deciding to load the doc. The test for its when-clause: it names an observable circumstance in the reader\u2019s current work, not the doc\u2019s topic reworded as an activity. If the WHEN can be inferred from the title alone, it is not a real trigger. Bad on a todo list: \"When planning or prioritizing work across this profile.\" Good: \"When the user mentions something from their todos, or asks what is still outstanding across this profile.\" The test for its because-clause: if it can be derived by paraphrasing the doc\u2019s advice, it is a restatement, not a payoff \u2014 a real payoff names a consequence in the reader\u2019s world that the document itself never asserts. Bad: \"because only genuine first principles belong in taste memory.\" Bad: \"because keeping the test loop fast and free of speculative tests protects the development pace\" \u2014 the doc\u2019s rule as an outcome, derivable straight from its advice. Good: \"because identifying throughlines in user taste lets future decisions be made faster and with less re-litigation.\" Someone mid-task who has not read the doc must be able to decide from this line alone whether the read is worth it. If you cannot name the concrete situation that triggers it, you do not yet understand the memory \u2014 ask the user one sharp question instead of improvising.";
|
|
110
|
-
export declare const GUIDE_PREDICATE_VOCABULARY = "
|
|
110
|
+
export declare const GUIDE_PREDICATE_VOCABULARY = "Document gates, surface-entry gates, and match-frontmatter share the same predicate language: a field map is AND-ed across fields; dotted fields resolve nested values; field matchers may be scalar, array, or object. Scalar matchers do exact equality, with arrays matching any element. Array matchers do membership or intersection. Object matchers accept `eq`, `ne`, `in`, `nin`, `exists`, `contains`, `containsAll`, `containsAny`, `matches`, `imatches`, `gt`, `gte`, `lt`, and `lte`. Combinators are `all`, `any`, and `not`; sibling field matchers next to them are AND-ed in. An empty condition is inert. An unknown op never matches.";
|
|
111
111
|
export declare const GUIDE_DOC_LINKS = "Link related docs with `[[canonical/name]]`. A doc link in any body is a first-class cross-reference to another memory document by its exact canonical name \u2014 the same identifier `crtr memory read` takes. A bare directory name is a valid link too: following it returns that directory\u2019s listing, a browse entrance rather than a doc. Links are pointers, never transclusion: the linked body is loaded only when a reader follows it, so a link costs nothing until needed. `crtr memory lint` fails on a link that resolves to no document or directory, and `crtr memory read` lists a doc\u2019s resolvable links alongside its body. There is no alias or label form.";
|
|
112
112
|
export {};
|
|
@@ -164,7 +164,7 @@ export function coerceGate(raw) {
|
|
|
164
164
|
return result;
|
|
165
165
|
}
|
|
166
166
|
// The frontmatter keys one `surfaces` entry may carry.
|
|
167
|
-
const SURFACE_ENTRY_KEYS = new Set(['on', 'match', 'match-frontmatter', 'at']);
|
|
167
|
+
const SURFACE_ENTRY_KEYS = new Set(['on', 'match', 'match-frontmatter', 'gate', 'at']);
|
|
168
168
|
/** Coerce one `--surface` value into a validated surfaces entry. Strict where
|
|
169
169
|
* the runtime parser is tolerant: a flag that would be silently dropped or
|
|
170
170
|
* trimmed at render time is an authoring mistake and fails HERE. The entry is
|
|
@@ -173,13 +173,13 @@ const SURFACE_ENTRY_KEYS = new Set(['on', 'match', 'match-frontmatter', 'at']);
|
|
|
173
173
|
export function coerceSurface(raw) {
|
|
174
174
|
const parsed = yamlParse(raw);
|
|
175
175
|
if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
176
|
-
throw usage(`--surface must be a YAML/JSON object entry {on, at, match?, match-frontmatter?}, got ${JSON.stringify(parsed)}. ` +
|
|
176
|
+
throw usage(`--surface must be a YAML/JSON object entry {on, at, match?, match-frontmatter?, gate?}, got ${JSON.stringify(parsed)}. ` +
|
|
177
177
|
`Example: --surface '{on: read, match: "src/**", at: content}'`);
|
|
178
178
|
}
|
|
179
179
|
const rec = parsed;
|
|
180
180
|
for (const key of Object.keys(rec)) {
|
|
181
181
|
if (!SURFACE_ENTRY_KEYS.has(key)) {
|
|
182
|
-
throw usage(`--surface: unknown key \`${key}\` (an entry carries only on, match, match-frontmatter, at)`);
|
|
182
|
+
throw usage(`--surface: unknown key \`${key}\` (an entry carries only on, match, match-frontmatter, gate, at)`);
|
|
183
183
|
}
|
|
184
184
|
}
|
|
185
185
|
const on = rec['on'];
|
|
@@ -223,10 +223,15 @@ export function coerceSurface(raw) {
|
|
|
223
223
|
if ((on === 'read' || on === 'memory-read' || on === 'command') && match === undefined && matchFrontmatter === undefined) {
|
|
224
224
|
throw usage(`--surface: a \`${on}\` entry requires \`match\`${on === 'read' ? ' or `match-frontmatter`' : ''}`);
|
|
225
225
|
}
|
|
226
|
+
const gate = rec['gate'];
|
|
227
|
+
if (gate !== undefined && (gate === null || typeof gate !== 'object' || Array.isArray(gate))) {
|
|
228
|
+
throw usage(`--surface: invalid \`gate\`: ${JSON.stringify(gate)} (expected a field→matcher object)`);
|
|
229
|
+
}
|
|
226
230
|
return {
|
|
227
231
|
on,
|
|
228
232
|
...(match !== undefined ? { match } : {}),
|
|
229
233
|
...(matchFrontmatter !== undefined ? { 'match-frontmatter': matchFrontmatter } : {}),
|
|
234
|
+
...(gate !== undefined ? { gate } : {}),
|
|
230
235
|
at,
|
|
231
236
|
};
|
|
232
237
|
}
|
|
@@ -503,7 +508,7 @@ export const FRONTMATTER_OVERLAY_PARAMS = {
|
|
|
503
508
|
'when-and-why-to-read': { kind: 'flag', name: 'when-and-why-to-read', type: 'string', required: false, constraint: 'ONE routing sentence: "When <circumstance>, this <kind> should be read because <broader downstream payoff>." WHY is the reader\u2019s payoff \u2014 the consequence they secure for their task by reading \u2014 NEVER the doc summary, its rule, or that rule reworded as an outcome (a benefit-shaped restatement still fails). Rendered verbatim as the preview.' },
|
|
504
509
|
'short-form': { kind: 'flag', name: 'short-form', type: 'string', required: false, constraint: 'Frontmatter short-form \u2014 a very abbreviated version of the content, the hook shown in `crtr memory list`.' },
|
|
505
510
|
'unlisted': { kind: 'flag', name: 'unlisted', type: 'bool', required: false, default: false, constraint: 'Suppress this doc from directory listings. Suppression only — explicit reads, [[links]], and surfaces entries still work.' },
|
|
506
|
-
'surface': { kind: 'flag', name: 'surface', type: 'string', required: false, repeatable: true, constraint: 'One routing entry per occurrence, as a YAML/JSON object `{on, at, match?, match-frontmatter?}`; the flag set replaces the document’s whole surfaces list. `on` is boot|workspace-open|read|memory-read|command; `at` is name|preview|content. `match` holds the event’s globs — required on read/memory-read/command (a read entry may carry `match-frontmatter`, a predicate over the read file’s own frontmatter, instead), meaningless on boot/workspace-open. A `./`-anchored glob is relative: for `read` to the store’s owning repo dir, for `memory-read` to the doc’s own name directory.
|
|
511
|
+
'surface': { kind: 'flag', name: 'surface', type: 'string', required: false, repeatable: true, constraint: 'One routing entry per occurrence, as a YAML/JSON object `{on, at, match?, match-frontmatter?, gate?}`; the flag set replaces the document’s whole surfaces list. `on` is boot|workspace-open|read|memory-read|command; `at` is name|preview|content. `match` holds the event’s globs — required on read/memory-read/command (a read entry may carry `match-frontmatter`, a predicate over the read file’s own frontmatter, instead), meaningless on boot/workspace-open. Optional entry `gate` is a node-config predicate using the same vocabulary as the document gate; its event constraints and gate both match before it participates. A `./`-anchored glob is relative: for `read` to the store’s owning repo dir, for `memory-read` to the doc’s own name directory. Participating entries fold to their highest `at`; there is no cross-entry deny precedence.' },
|
|
507
512
|
'gate': { kind: 'flag', name: 'gate', type: 'string', required: false, constraint: 'Frontmatter gate \u2014 YAML/JSON object predicate over node config using the same field/matcher vocabulary described in the guide.' },
|
|
508
513
|
'slash': { kind: 'flag', name: 'slash', type: 'bool', required: false, default: false, constraint: 'Presence flags this doc invocable as a pi slash command (`/<name>`, `/` in a nested name rendered as `:`) \u2014 the doc body becomes the command\u2019s injected prompt. Default false: most docs are consulted, not invoked.' },
|
|
509
514
|
};
|
|
@@ -521,7 +526,7 @@ export function overlayParam(name, overrides = {}, extraConstraint) {
|
|
|
521
526
|
* `--doc-rationale`, because `--rationale` there means why THIS REVISION is
|
|
522
527
|
* happening. Same field, same prose, two flag names that cannot be confused. */
|
|
523
528
|
export const DOC_RATIONALE_CONSTRAINT = 'Frontmatter rationale \u2014 the observed agent failure that made this doc necessary. Maintainer-facing only: never ships in any delivered surface (boot render, on-read injection, `memory read` content), visible only via `memory read --frontmatter`. Omitting the flag preserves an existing rationale unchanged.';
|
|
524
|
-
export const GUIDE_SURFACES = 'Every doc appears in its directory’s listing by default (suppress with --unlisted); everything beyond the listing is explicit `surfaces` routing — entries declaring WHEN the doc delivers and how much. Events: `boot` delivers in the boot catalog every agent sees; `workspace-open` delivers in first-message context when cwd/profile mounts the doc’s project store (project stores only); `read` fires when the agent reads a matching file (globs vs the file’s absolute path and basename, `./`-anchored globs vs its path relative to the store’s owning repo dir, `match-frontmatter` predicates over the read file’s own YAML frontmatter); `memory-read` fires when another memory doc is read (globs vs that doc’s canonical name, `./` anchored to this doc’s own name directory); `command` fires when a matching shell command runs (globs vs the whole command string, `*` crossing `/`). `at` sets how much delivers: `name` the bare tag, `preview` the routing line, `content` the whole body. Each entry is paid by every future agent it fires on, so default down: no surfaces at all is correct for reference depth reached through listings and [[links]], and when a doc fits in a single sentence, deliver `content` directly — a `preview` routing line would run longer than the doc itself. Sentence-length `content` docs are correct; never pad a memory to be more verbose than the rule or fact it carries.';
|
|
529
|
+
export const GUIDE_SURFACES = 'Every doc appears in its directory’s listing by default (suppress with --unlisted); everything beyond the listing is explicit `surfaces` routing — entries declaring WHEN the doc delivers and how much. Events: `boot` delivers in the boot catalog every agent sees; `workspace-open` delivers in first-message context when cwd/profile mounts the doc’s project store (project stores only); `read` fires when the agent reads a matching file (globs vs the file’s absolute path and basename, `./`-anchored globs vs its path relative to the store’s owning repo dir, `match-frontmatter` predicates over the read file’s own YAML frontmatter); `memory-read` fires when another memory doc is read (globs vs that doc’s canonical name, `./` anchored to this doc’s own name directory); `command` fires when a matching shell command runs (globs vs the whole command string, `*` crossing `/`). An entry may also carry `gate`, a node-config predicate using the same vocabulary as the document-level `gate`: event constraints and entry gate both must match, then all participating entries fold to the highest `at` (`content` > `preview` > `name`), with no cross-entry deny precedence. The document-level `gate` remains the hard eligibility check: when it fails, no automatic surface can deliver the document. `at` sets how much delivers: `name` the bare tag, `preview` the routing line, `content` the whole body. Explicit `memory read` and listings remain deliberate access and ignore gates/rungs; only companion docs routed by their `memory-read` entries use entry gates. Each entry is paid by every future agent it fires on, so default down: no surfaces at all is correct for reference depth reached through listings and [[links]], and when a doc fits in a single sentence, deliver `content` directly — a `preview` routing line would run longer than the doc itself. Sentence-length `content` docs are correct; never pad a memory to be more verbose than the rule or fact it carries.';
|
|
525
530
|
export const GUIDE_ROUTING_LINE = 'The routing line (--when-and-why-to-read) is the only text an agent reads before deciding to load the doc. The test for its when-clause: it names an observable circumstance in the reader\u2019s current work, not the doc\u2019s topic reworded as an activity. If the WHEN can be inferred from the title alone, it is not a real trigger. Bad on a todo list: "When planning or prioritizing work across this profile." Good: "When the user mentions something from their todos, or asks what is still outstanding across this profile." The test for its because-clause: if it can be derived by paraphrasing the doc\u2019s advice, it is a restatement, not a payoff \u2014 a real payoff names a consequence in the reader\u2019s world that the document itself never asserts. Bad: "because only genuine first principles belong in taste memory." Bad: "because keeping the test loop fast and free of speculative tests protects the development pace" \u2014 the doc\u2019s rule as an outcome, derivable straight from its advice. Good: "because identifying throughlines in user taste lets future decisions be made faster and with less re-litigation." Someone mid-task who has not read the doc must be able to decide from this line alone whether the read is worth it. If you cannot name the concrete situation that triggers it, you do not yet understand the memory \u2014 ask the user one sharp question instead of improvising.';
|
|
526
|
-
export const GUIDE_PREDICATE_VOCABULARY = '
|
|
531
|
+
export const GUIDE_PREDICATE_VOCABULARY = 'Document gates, surface-entry gates, and match-frontmatter share the same predicate language: a field map is AND-ed across fields; dotted fields resolve nested values; field matchers may be scalar, array, or object. Scalar matchers do exact equality, with arrays matching any element. Array matchers do membership or intersection. Object matchers accept `eq`, `ne`, `in`, `nin`, `exists`, `contains`, `containsAll`, `containsAny`, `matches`, `imatches`, `gt`, `gte`, `lt`, and `lte`. Combinators are `all`, `any`, and `not`; sibling field matchers next to them are AND-ed in. An empty condition is inert. An unknown op never matches.';
|
|
527
532
|
export const GUIDE_DOC_LINKS = 'Link related docs with `[[canonical/name]]`. A doc link in any body is a first-class cross-reference to another memory document by its exact canonical name \u2014 the same identifier `crtr memory read` takes. A bare directory name is a valid link too: following it returns that directory\u2019s listing, a browse entrance rather than a doc. Links are pointers, never transclusion: the linked body is loaded only when a reader follows it, so a link costs nothing until needed. `crtr memory lint` fails on a link that resolves to no document or directory, and `crtr memory read` lists a doc\u2019s resolvable links alongside its body. There is no alias or label form.';
|
|
@@ -32,6 +32,8 @@ export function renderDocView(doc, width) {
|
|
|
32
32
|
parts.push(entry.match.join(", "));
|
|
33
33
|
if (entry.matchFrontmatter !== undefined)
|
|
34
34
|
parts.push(JSON.stringify(entry.matchFrontmatter));
|
|
35
|
+
if (entry.gate !== undefined)
|
|
36
|
+
parts.push(JSON.stringify(entry.gate));
|
|
35
37
|
out.push(...field(entry.on, parts.join(" "), viewWidth));
|
|
36
38
|
}
|
|
37
39
|
if (doc.unlisted)
|
|
@@ -21,6 +21,7 @@ import { closeDb } from '../canvas/db.js';
|
|
|
21
21
|
import { resetScopeCache } from '../scope.js';
|
|
22
22
|
import { createProfile } from '../profiles/manifest.js';
|
|
23
23
|
import { spawnNode } from '../runtime/nodes.js';
|
|
24
|
+
import { memoryDir } from '../runtime/memory.js';
|
|
24
25
|
import { clearSessionCache } from '../substrate/session-cache.js';
|
|
25
26
|
import { renderKnowledgeBlock } from '../substrate/render-node.js';
|
|
26
27
|
import { renderWorkspaceOpenDocs } from '../substrate/on-read-node.js';
|
|
@@ -37,6 +38,8 @@ const B = {
|
|
|
37
38
|
nameFromPcontent: 'BODY-T9-NAMEDUP-FROM-PCONTENT',
|
|
38
39
|
userDupFromPnone: 'BODY-T9-USERDUP-FROM-PNONE',
|
|
39
40
|
userDupFromUser: 'BODY-T9-USERDUP-FROM-USER',
|
|
41
|
+
kindSplit: 'BODY-T9-KIND-SPLIT',
|
|
42
|
+
documentGateWins: 'BODY-T9-DOCUMENT-GATE-WINS',
|
|
40
43
|
};
|
|
41
44
|
let home;
|
|
42
45
|
let canvasHome;
|
|
@@ -115,6 +118,30 @@ before(() => {
|
|
|
115
118
|
// would otherwise beat.
|
|
116
119
|
writeDoc(pnone, 't9-userdup-doc', autoDoc('When the user duplicate resolves', B.userDupFromPnone));
|
|
117
120
|
writeDoc(user, 't9-userdup-doc', autoDoc('When the user duplicate resolves', B.userDupFromUser));
|
|
121
|
+
writeDoc(user, 't9-kind-split', [
|
|
122
|
+
'---',
|
|
123
|
+
'kind: knowledge',
|
|
124
|
+
'when-and-why-to-read: "When the node needs this kind-specific guide"',
|
|
125
|
+
'surfaces:',
|
|
126
|
+
' - {on: boot, gate: {kind: {in: [design, spec, plan, developer]}}, at: content}',
|
|
127
|
+
' - {on: boot, gate: {kind: {in: [general, review, advisor]}}, at: preview}',
|
|
128
|
+
'---',
|
|
129
|
+
'',
|
|
130
|
+
B.kindSplit,
|
|
131
|
+
'',
|
|
132
|
+
].join('\n'));
|
|
133
|
+
writeDoc(user, 't9-document-gate-wins', [
|
|
134
|
+
'---',
|
|
135
|
+
'kind: knowledge',
|
|
136
|
+
'when-and-why-to-read: "When document eligibility is tested"',
|
|
137
|
+
'gate: {kind: {ne: developer}}',
|
|
138
|
+
'surfaces:',
|
|
139
|
+
' - {on: boot, gate: {kind: developer}, at: content}',
|
|
140
|
+
'---',
|
|
141
|
+
'',
|
|
142
|
+
B.documentGateWins,
|
|
143
|
+
'',
|
|
144
|
+
].join('\n'));
|
|
118
145
|
// Hidden-count pair: a top-level dir always renders, so a dir holding only a
|
|
119
146
|
// bootless doc shows as `<dir>/` + `[+1 more]` — unless its project is `none`.
|
|
120
147
|
writeDoc(pnone, join('t9-none-hidden', 'probe'), bootlessDoc('When counted', 'HIDDEN-NONE'));
|
|
@@ -152,8 +179,8 @@ after(() => {
|
|
|
152
179
|
restore('CRTR_PROFILE_ID', prevProfile);
|
|
153
180
|
restore('CRTR_NODE_ID', prevNode);
|
|
154
181
|
});
|
|
155
|
-
function newNode() {
|
|
156
|
-
return spawnNode({ kind
|
|
182
|
+
function newNode(kind = 'general') {
|
|
183
|
+
return spawnNode({ kind, cwd: cwdProject, parent: null, profile_id: profileId }).node_id;
|
|
157
184
|
}
|
|
158
185
|
test('boot delivery caps every profile project at its relationship, including the one used as cwd', () => {
|
|
159
186
|
const boot = renderKnowledgeBlock(newNode(), new Map());
|
|
@@ -168,6 +195,46 @@ test('boot delivery caps every profile project at its relationship, including th
|
|
|
168
195
|
assert.match(boot, /[├└]─ t9-pname-doc$/m, `the name-capped doc discloses as a bare name; got:\n${boot}`);
|
|
169
196
|
assert.ok(!boot.includes('When the name project delivers'), 'a name-capped doc discloses no preview line');
|
|
170
197
|
});
|
|
198
|
+
test('surface-entry gates select the rung by node kind while the document gate remains absolute', () => {
|
|
199
|
+
for (const kind of ['design', 'spec', 'plan', 'developer']) {
|
|
200
|
+
const boot = renderKnowledgeBlock(newNode(kind), new Map());
|
|
201
|
+
assert.ok(boot.includes(B.kindSplit), `${kind} receives the content rung; got:\n${boot}`);
|
|
202
|
+
}
|
|
203
|
+
for (const kind of ['general', 'review', 'advisor']) {
|
|
204
|
+
const boot = renderKnowledgeBlock(newNode(kind), new Map());
|
|
205
|
+
assert.match(boot, /t9-kind-split {2}# read when: When the node needs this kind-specific guide\./, `${kind} receives the preview rung; got:\n${boot}`);
|
|
206
|
+
assert.ok(!boot.includes(B.kindSplit), `${kind} does not receive the body`);
|
|
207
|
+
}
|
|
208
|
+
for (const kind of ['explore', 'personal-assistant']) {
|
|
209
|
+
const boot = renderKnowledgeBlock(newNode(kind), new Map());
|
|
210
|
+
assert.ok(!boot.includes('t9-kind-split'), `${kind} receives no kind-split entry; got:\n${boot}`);
|
|
211
|
+
assert.ok(!boot.includes(B.kindSplit), `${kind} receives no kind-split body`);
|
|
212
|
+
}
|
|
213
|
+
const developer = renderKnowledgeBlock(newNode('developer'), new Map());
|
|
214
|
+
assert.ok(!developer.includes('t9-document-gate-wins'), `a failing document gate excludes every entry; got:\n${developer}`);
|
|
215
|
+
assert.ok(!developer.includes(B.documentGateWins), 'a failing document gate excludes its content');
|
|
216
|
+
});
|
|
217
|
+
test('a node-local doc floors to name only without boot entries', () => {
|
|
218
|
+
const node = newNode('explore');
|
|
219
|
+
writeDoc(memoryDir(node), 't9-node-local-bootless', bootlessDoc('When the node-local fallback applies', 'BODY-T9-NODE-LOCAL-BOOTLESS'));
|
|
220
|
+
writeDoc(memoryDir(node), 't9-node-local-entry-gated', [
|
|
221
|
+
'---',
|
|
222
|
+
'kind: knowledge',
|
|
223
|
+
'when-and-why-to-read: "When the node-local entry gates are tested"',
|
|
224
|
+
'surfaces:',
|
|
225
|
+
' - {on: boot, gate: {kind: developer}, at: content}',
|
|
226
|
+
' - {on: boot, gate: {kind: review}, at: preview}',
|
|
227
|
+
'---',
|
|
228
|
+
'',
|
|
229
|
+
'BODY-T9-NODE-LOCAL-ENTRY-GATED',
|
|
230
|
+
'',
|
|
231
|
+
].join('\n'));
|
|
232
|
+
const boot = renderKnowledgeBlock(node, new Map());
|
|
233
|
+
assert.match(boot, /[├└]─ t9-node-local-bootless$/m, `a bootless node-local doc falls to name; got:\n${boot}`);
|
|
234
|
+
assert.ok(!boot.includes('BODY-T9-NODE-LOCAL-BOOTLESS'), 'the fallback discloses no body');
|
|
235
|
+
assert.ok(!boot.includes('t9-node-local-entry-gated'), `ineligible boot entries keep a node-local doc absent; got:\n${boot}`);
|
|
236
|
+
assert.ok(!boot.includes('BODY-T9-NODE-LOCAL-ENTRY-GATED'), 'ineligible boot entries disclose no body');
|
|
237
|
+
});
|
|
171
238
|
test('a `none` project contributes nothing to boot — no body, no name, no hidden count, no shadow', () => {
|
|
172
239
|
const boot = renderKnowledgeBlock(newNode(), new Map());
|
|
173
240
|
assert.ok(!boot.includes(B.pnone), 'a none-capped body must not render');
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type SurfaceEntry } from './schema.js';
|
|
1
2
|
/** Strict validation of one raw routing entry. Runtime parsing deliberately
|
|
2
3
|
* tolerates malformed docs; this authoring/preflight contract does not. */
|
|
3
4
|
export declare function lintSubstrateSurfaces(value: unknown): string | null;
|
|
@@ -6,8 +7,4 @@ export declare function lintSubstrateFrontmatter(fm: Record<string, unknown> | n
|
|
|
6
7
|
/** Compatibility name for consumers that adopted lint's former export. */
|
|
7
8
|
export declare const lintSubstrateSchema: typeof lintSubstrateFrontmatter;
|
|
8
9
|
/** Parsed routing entries for checks that run after strict validation. */
|
|
9
|
-
export declare function parsedSubstrateSurfaces(fm: Record<string, unknown>):
|
|
10
|
-
on: string;
|
|
11
|
-
at: string;
|
|
12
|
-
match?: string[];
|
|
13
|
-
}[];
|
|
10
|
+
export declare function parsedSubstrateSurfaces(fm: Record<string, unknown>): SurfaceEntry[];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isDocKind, parseSubstrateFrontmatter, SURFACE_EVENTS, SURFACE_RUNGS } from './schema.js';
|
|
2
2
|
const RETIRED_FIELDS = ['system-prompt-visibility', 'file-read-visibility', 'applies-to', 'read-when'];
|
|
3
|
-
const SURFACE_ENTRY_KEYS = ['on', 'match', 'match-frontmatter', 'at'];
|
|
3
|
+
const SURFACE_ENTRY_KEYS = ['on', 'match', 'match-frontmatter', 'gate', 'at'];
|
|
4
4
|
const SUPPRESSIBLE_RULES = ['length', 'broad-memory-read'];
|
|
5
5
|
/** Strict validation of one raw routing entry. Runtime parsing deliberately
|
|
6
6
|
* tolerates malformed docs; this authoring/preflight contract does not. */
|
|
@@ -8,15 +8,15 @@ export function lintSubstrateSurfaces(value) {
|
|
|
8
8
|
if (value === undefined)
|
|
9
9
|
return null;
|
|
10
10
|
if (!Array.isArray(value))
|
|
11
|
-
return `invalid surfaces: ${JSON.stringify(value)} (expected a list of {on, at, match?, match-frontmatter?} entries)`;
|
|
11
|
+
return `invalid surfaces: ${JSON.stringify(value)} (expected a list of {on, at, match?, match-frontmatter?, gate?} entries)`;
|
|
12
12
|
for (const raw of value) {
|
|
13
13
|
if (raw === null || typeof raw !== 'object' || Array.isArray(raw)) {
|
|
14
|
-
return `invalid surfaces entry: ${JSON.stringify(raw)} (expected an {on, at, match?, match-frontmatter?} object)`;
|
|
14
|
+
return `invalid surfaces entry: ${JSON.stringify(raw)} (expected an {on, at, match?, match-frontmatter?, gate?} object)`;
|
|
15
15
|
}
|
|
16
16
|
const entry = raw;
|
|
17
17
|
for (const key of Object.keys(entry)) {
|
|
18
18
|
if (!SURFACE_ENTRY_KEYS.includes(key)) {
|
|
19
|
-
return `invalid surfaces entry: unknown key \`${key}\` (an entry carries only on, match, match-frontmatter, at)`;
|
|
19
|
+
return `invalid surfaces entry: unknown key \`${key}\` (an entry carries only on, match, match-frontmatter, gate, at)`;
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
const on = entry['on'];
|
|
@@ -50,6 +50,10 @@ export function lintSubstrateSurfaces(value) {
|
|
|
50
50
|
if ((on === 'read' || on === 'memory-read' || on === 'command') && !hasMatch && matchFrontmatter === undefined) {
|
|
51
51
|
return `invalid surfaces entry: a \`${on}\` entry requires \`match\`${on === 'read' ? ' or `match-frontmatter`' : ''}`;
|
|
52
52
|
}
|
|
53
|
+
const gate = entry['gate'];
|
|
54
|
+
if (gate !== undefined && (gate === null || typeof gate !== 'object' || Array.isArray(gate))) {
|
|
55
|
+
return `invalid surfaces entry \`gate\`: ${JSON.stringify(gate)} (expected a field→matcher object)`;
|
|
56
|
+
}
|
|
53
57
|
}
|
|
54
58
|
return null;
|
|
55
59
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { SubstrateDoc } from './schema.js';
|
|
1
|
+
import type { SubstrateDoc, SurfaceEntry } from './schema.js';
|
|
2
2
|
import type { NodeConfigSubject } from './subject-fields.js';
|
|
3
3
|
/** Does `doc` pass its gate for `subject`?
|
|
4
4
|
*
|
|
@@ -11,3 +11,6 @@ import type { NodeConfigSubject } from './subject-fields.js';
|
|
|
11
11
|
* for this node; it remains findable by `crtr memory find` (search ignores
|
|
12
12
|
* gate + rung). */
|
|
13
13
|
export declare function gatePasses(doc: SubstrateDoc, subject: NodeConfigSubject): boolean;
|
|
14
|
+
/** Does a surface entry participate for `subject`? A missing subject cannot
|
|
15
|
+
* satisfy an entry gate; entries without one remain eligible. */
|
|
16
|
+
export declare function surfaceEntryGatePasses(entry: Pick<SurfaceEntry, 'gate'>, subject: NodeConfigSubject | null): boolean;
|
|
@@ -19,3 +19,8 @@ export function gatePasses(doc, subject) {
|
|
|
19
19
|
return true;
|
|
20
20
|
return evalCondition(doc.gate, subject);
|
|
21
21
|
}
|
|
22
|
+
/** Does a surface entry participate for `subject`? A missing subject cannot
|
|
23
|
+
* satisfy an entry gate; entries without one remain eligible. */
|
|
24
|
+
export function surfaceEntryGatePasses(entry, subject) {
|
|
25
|
+
return entry.gate === undefined || (subject !== null && evalCondition(entry.gate, subject));
|
|
26
|
+
}
|
|
@@ -229,7 +229,7 @@ export function renderOnReadDocsForSubject(subject, readFilePath, seen = new Map
|
|
|
229
229
|
const readFrontmatter = readFileFrontmatter(absReadFile);
|
|
230
230
|
const candidates = dedupeByPhysicalPath([...enclosingProjectDocs(absReadFile), ...resolvedDocs()])
|
|
231
231
|
.filter((doc) => realpathOrSelf(doc.path) !== absReadFile)
|
|
232
|
-
.map((doc) => ({ doc, rung: readDeliveryRung(doc, absReadFile, readFrontmatter) }))
|
|
232
|
+
.map((doc) => ({ doc, rung: readDeliveryRung(doc, subject, absReadFile, readFrontmatter) }))
|
|
233
233
|
.filter(({ rung }) => rung !== 'none');
|
|
234
234
|
return renderCandidates(subject, candidates, seen);
|
|
235
235
|
}
|
|
@@ -254,7 +254,7 @@ export function renderWorkspaceOpenDocsForSubject(subject, cwd, profileId, seen
|
|
|
254
254
|
return '';
|
|
255
255
|
}
|
|
256
256
|
const candidates = dedupeByPhysicalPath(docs)
|
|
257
|
-
.map((doc) => ({ doc, rung: minRung(workspaceOpenRung(doc), doc.projectMemory) }))
|
|
257
|
+
.map((doc) => ({ doc, rung: minRung(workspaceOpenRung(doc, subject), doc.projectMemory) }))
|
|
258
258
|
.filter(({ rung }) => rung !== 'none')
|
|
259
259
|
.sort((a, b) => {
|
|
260
260
|
const aRoot = owningRootOf(a.doc) ?? '';
|
|
@@ -272,7 +272,7 @@ export function renderWorkspaceOpenDocsForSubject(subject, cwd, profileId, seen
|
|
|
272
272
|
export function memoryReadDocBlocks(subject, excludeRealpath, targetNames, seen) {
|
|
273
273
|
const candidates = dedupeByPhysicalPath(resolvedDocs())
|
|
274
274
|
.filter((doc) => realpathOrSelf(doc.path) !== excludeRealpath)
|
|
275
|
-
.map((doc) => ({ doc, rung: memoryReadDeliveryRung(doc, targetNames) }))
|
|
275
|
+
.map((doc) => ({ doc, rung: memoryReadDeliveryRung(doc, subject, targetNames) }))
|
|
276
276
|
.filter(({ rung }) => rung !== 'none');
|
|
277
277
|
return renderCandidateBlocks(subject, candidates, seen);
|
|
278
278
|
}
|
|
@@ -282,7 +282,7 @@ export function memoryReadDocBlocks(subject, excludeRealpath, targetNames, seen)
|
|
|
282
282
|
* dedup set as the other channels. */
|
|
283
283
|
export function renderOnCommandDocsForSubject(subject, command, seen = new Map()) {
|
|
284
284
|
const candidates = dedupeByPhysicalPath(resolvedDocs())
|
|
285
|
-
.map((doc) => ({ doc, rung: commandDeliveryRung(doc, command) }))
|
|
285
|
+
.map((doc) => ({ doc, rung: commandDeliveryRung(doc, subject, command) }))
|
|
286
286
|
.filter(({ rung }) => rung !== 'none');
|
|
287
287
|
return renderCandidates(subject, candidates, seen);
|
|
288
288
|
}
|
|
@@ -8,11 +8,10 @@
|
|
|
8
8
|
// then the `preview`+`name` docs render as ONE catalog tree, each at its own
|
|
9
9
|
// rung (preview → a `# read when:` routing line; name → a bare entry); a doc
|
|
10
10
|
// with NO boot entry leaks only into its dir's `[+N more]` count, never a
|
|
11
|
-
// name — EXCEPT a node-local doc
|
|
12
|
-
//
|
|
13
|
-
//
|
|
14
|
-
//
|
|
15
|
-
// doc outright.
|
|
11
|
+
// name — EXCEPT a node-local doc with no boot entry: renderKnowledgeForSubject
|
|
12
|
+
// floors it up to `name` so it still shows its bare name rather than
|
|
13
|
+
// collapsing into a hidden count. A node-local doc with boot entries remains
|
|
14
|
+
// absent when none of those entries participates.
|
|
16
15
|
//
|
|
17
16
|
// • the SYSTEM-PROMPT half — `<memory kind="preference">`
|
|
18
17
|
// (renderPreferencesSection) — the always-present memory-usage guidance plus
|
|
@@ -27,11 +26,11 @@
|
|
|
27
26
|
//
|
|
28
27
|
// The pipeline is explicitly TWO-STEP and must never run in the other order:
|
|
29
28
|
// 1. SELECT WINNERS — MemoryDoc → parseSubstrateDoc → (null-filter
|
|
30
|
-
// non-substrate) → per-doc boot rung (`bootRung`, the max `at` over
|
|
31
|
-
//
|
|
29
|
+
// non-substrate) → per-doc boot rung (`bootRung`, the max `at` over
|
|
30
|
+
// participating `on: boot` surfaces entries) → gatePasses → first-wins DEDUP by
|
|
32
31
|
// name over the resolver's precedence order (nearest project > user >
|
|
33
32
|
// builtin). Node-local docs follow the same gate rule, but the
|
|
34
|
-
// knowledge-block render floors a
|
|
33
|
+
// knowledge-block render floors only a node-local doc with no boot entry to
|
|
35
34
|
// `name` — the one rung-floor exemption, scoped to the node-local store
|
|
36
35
|
// only.
|
|
37
36
|
// 2. RENDER IN DISPLAY ORDER — split winners into content vs. the rest;
|
|
@@ -108,7 +107,7 @@ function selectWinners(subject, kind) {
|
|
|
108
107
|
.filter((d) => d.kind === kind)
|
|
109
108
|
.filter((d) => d.projectMemory !== 'none')
|
|
110
109
|
.filter((d) => gatePasses(d, subject))
|
|
111
|
-
.map((d) => ({ ...d, bootRung: minRung(bootRung(d), d.projectMemory) }));
|
|
110
|
+
.map((d) => ({ ...d, bootRung: minRung(bootRung(d, subject), d.projectMemory) }));
|
|
112
111
|
return dedupeFirstWins(eligible);
|
|
113
112
|
}
|
|
114
113
|
// ---------------------------------------------------------------------------
|
|
@@ -223,13 +222,9 @@ function renderGrouped(winners, rootLabel, nodeLocalSet = new Set()) {
|
|
|
223
222
|
* Returned across ALL kinds — node-local is the catch-all this-node store and
|
|
224
223
|
* rides into the knowledge block.
|
|
225
224
|
*
|
|
226
|
-
* Node-local docs follow the same GATE rule as every other store
|
|
227
|
-
*
|
|
228
|
-
*
|
|
229
|
-
* so a doc with no boot entry is retained by this function — it is the caller
|
|
230
|
-
* (renderKnowledgeForSubject) that floors a bootless node-local doc up to
|
|
231
|
-
* `name` so it still shows its bare name instead of collapsing into a
|
|
232
|
-
* `[+N more]` count. */
|
|
225
|
+
* Node-local docs follow the same GATE rule as every other store. A doc with
|
|
226
|
+
* no boot entry is retained here; renderKnowledgeForSubject floors it to
|
|
227
|
+
* `name` so it shows as a bare name instead of collapsing into `[+N more]`. */
|
|
233
228
|
function nodeLocalDocs(nodeId, subject) {
|
|
234
229
|
const dir = memoryDir(nodeId);
|
|
235
230
|
if (!pathExists(dir))
|
|
@@ -574,8 +569,8 @@ export function renderPreferencesForSubject(subject, seen) {
|
|
|
574
569
|
* eligible. */
|
|
575
570
|
export function renderKnowledgeForSubject(subject, nodeId, seen) {
|
|
576
571
|
const nodeLocal = nodeLocalDocs(nodeId, subject).map((d) => {
|
|
577
|
-
const r = bootRung(d);
|
|
578
|
-
return { ...d, bootRung: isVisible(r) ? r : 'name' };
|
|
572
|
+
const r = bootRung(d, subject);
|
|
573
|
+
return { ...d, bootRung: isVisible(r) || d.surfaces.some((e) => e.on === 'boot') ? r : 'name' };
|
|
579
574
|
});
|
|
580
575
|
const nodeLocalSet = new Set(nodeLocal);
|
|
581
576
|
// Resolver winners first: first-wins dedup keeps the resolver's copy over a
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type ProfileProjectMemory } from '../../api/dto/profiles.js';
|
|
2
2
|
import type { MemoryDoc, MemoryScope } from '../memory-resolver.js';
|
|
3
|
+
import type { NodeConfigSubject } from './subject-fields.js';
|
|
3
4
|
export declare const KINDS: readonly ["knowledge", "preference"];
|
|
4
5
|
export type DocKind = (typeof KINDS)[number];
|
|
5
6
|
/** Is `v` one of the two valid document kinds? */
|
|
@@ -34,10 +35,10 @@ export type SurfaceEvent = (typeof SURFACE_EVENTS)[number];
|
|
|
34
35
|
export declare const SURFACE_RUNGS: readonly ["name", "preview", "content"];
|
|
35
36
|
export type SurfaceRung = (typeof SURFACE_RUNGS)[number];
|
|
36
37
|
/** One routing entry: when event `on` exposes a subject that fits `match`
|
|
37
|
-
* (and `matchFrontmatter`, `read` only)
|
|
38
|
-
* Constraints within one entry AND together
|
|
39
|
-
* fit; a `match` list is satisfied by any one
|
|
40
|
-
* event OR together. */
|
|
38
|
+
* (and `matchFrontmatter`, `read` only) and its optional node-config `gate`,
|
|
39
|
+
* the doc delivers at rung `at`. Constraints within one entry AND together
|
|
40
|
+
* (each present constraint must fit; a `match` list is satisfied by any one
|
|
41
|
+
* glob); multiple entries per event OR together. */
|
|
41
42
|
export interface SurfaceEntry {
|
|
42
43
|
on: SurfaceEvent;
|
|
43
44
|
/** Globs vs the event's subject namespace. Required on read/memory-read/
|
|
@@ -47,11 +48,15 @@ export interface SurfaceEntry {
|
|
|
47
48
|
/** Predicate over the read file's own YAML frontmatter — `read` event only.
|
|
48
49
|
* Frontmatter key `match-frontmatter`. */
|
|
49
50
|
matchFrontmatter?: GatePredicate;
|
|
51
|
+
/** Optional predicate over the current node config. Frontmatter key `gate`.
|
|
52
|
+
* The document-level gate remains the hard eligibility check. */
|
|
53
|
+
gate?: GatePredicate;
|
|
50
54
|
at: SurfaceRung;
|
|
51
55
|
}
|
|
52
|
-
/** A doc's boot rung
|
|
53
|
-
* it carries
|
|
54
|
-
|
|
56
|
+
/** A doc's boot rung for `subject`: the highest `at` over participating
|
|
57
|
+
* `boot` entries, `none` when it carries none. The boot render's per-doc
|
|
58
|
+
* selection input. */
|
|
59
|
+
export declare function bootRung(doc: Pick<SubstrateSchema, 'surfaces'>, subject: NodeConfigSubject): Rung;
|
|
55
60
|
/** A gate predicate tree, evaluated by predicate.ts (`evalCondition`) against
|
|
56
61
|
* the node-config subject. Typed loosely on purpose — the matcher engine owns
|
|
57
62
|
* validation; structurally it is a field→matcher map with optional
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
// never throw): invalid `surfaces` entries are dropped rather than crashing a
|
|
9
9
|
// render, and `crtr memory lint` owns strict authoring-time enforcement.
|
|
10
10
|
import { PROFILE_PROJECT_MEMORY_VALUES } from '../../api/dto/profiles.js';
|
|
11
|
+
import { surfaceEntryGatePasses } from './gate.js';
|
|
11
12
|
// ---------------------------------------------------------------------------
|
|
12
13
|
// Kinds — the two semantic kinds (design §3): `knowledge` (consult — procedural
|
|
13
14
|
// playbooks + factual references merged) vs `preference` (behave — standing
|
|
@@ -95,12 +96,13 @@ export const SURFACE_EVENTS = ['boot', 'workspace-open', 'read', 'memory-read',
|
|
|
95
96
|
* absence of an entry. (`Rung`'s `none` survives only as the internal
|
|
96
97
|
* ranking floor, e.g. `bootRung` of a doc with no boot entry.) */
|
|
97
98
|
export const SURFACE_RUNGS = ['name', 'preview', 'content'];
|
|
98
|
-
/** A doc's boot rung
|
|
99
|
-
* it carries
|
|
100
|
-
|
|
99
|
+
/** A doc's boot rung for `subject`: the highest `at` over participating
|
|
100
|
+
* `boot` entries, `none` when it carries none. The boot render's per-doc
|
|
101
|
+
* selection input. */
|
|
102
|
+
export function bootRung(doc, subject) {
|
|
101
103
|
let r = 'none';
|
|
102
104
|
for (const e of doc.surfaces) {
|
|
103
|
-
if (e.on !== 'boot')
|
|
105
|
+
if (e.on !== 'boot' || !surfaceEntryGatePasses(e, subject))
|
|
104
106
|
continue;
|
|
105
107
|
if (rungRank(e.at) > rungRank(r))
|
|
106
108
|
r = e.at;
|
|
@@ -194,8 +196,8 @@ function parseGate(v) {
|
|
|
194
196
|
* dropped (bad `on`, bad `at`, a read/memory-read/command entry left with
|
|
195
197
|
* neither `match` nor — read only — `match-frontmatter`). `match-frontmatter`
|
|
196
198
|
* on a non-read event is dropped from the entry, which survives iff it still
|
|
197
|
-
* carries a `match
|
|
198
|
-
* over many docs and must never throw. */
|
|
199
|
+
* carries a `match`; an invalid entry `gate` is dropped. Lint owns strict
|
|
200
|
+
* enforcement; the runtime parser maps over many docs and must never throw. */
|
|
199
201
|
function parseSurfaces(v) {
|
|
200
202
|
if (!Array.isArray(v))
|
|
201
203
|
return [];
|
|
@@ -212,6 +214,7 @@ function parseSurfaces(v) {
|
|
|
212
214
|
continue;
|
|
213
215
|
const match = parseMatchGlobs(rec['match']);
|
|
214
216
|
const matchFrontmatter = on === 'read' ? parseGate(rec['match-frontmatter']) : undefined;
|
|
217
|
+
const gate = parseGate(rec['gate']);
|
|
215
218
|
if ((on === 'read' || on === 'memory-read' || on === 'command') &&
|
|
216
219
|
match === undefined &&
|
|
217
220
|
matchFrontmatter === undefined) {
|
|
@@ -222,6 +225,7 @@ function parseSurfaces(v) {
|
|
|
222
225
|
at: at,
|
|
223
226
|
...(match !== undefined ? { match } : {}),
|
|
224
227
|
...(matchFrontmatter !== undefined ? { matchFrontmatter } : {}),
|
|
228
|
+
...(gate !== undefined ? { gate } : {}),
|
|
225
229
|
});
|
|
226
230
|
}
|
|
227
231
|
return out;
|