@north-light/cli 0.3.788 → 0.3.789

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.
@@ -2,3 +2,4 @@ export * from './schema.js';
2
2
  export * from './manifest.js';
3
3
  export * from './result.js';
4
4
  export * from './object-kinds.js';
5
+ export * from './memory-extensions.js';
@@ -1 +1 @@
1
- export*from"./schema.js";export*from"./manifest.js";export*from"./result.js";export*from"./object-kinds.js";
1
+ export*from"./schema.js";export*from"./manifest.js";export*from"./result.js";export*from"./object-kinds.js";export*from"./memory-extensions.js";
@@ -0,0 +1,34 @@
1
+ export type MemoryExtensionScalar = string | boolean | number;
2
+ export type MemoryExtensionFieldType = 'boolean' | 'string' | 'number' | 'enum';
3
+ interface MemoryExtensionDeclarationBase {
4
+ write_help: string;
5
+ edit_help: string;
6
+ }
7
+ export interface BooleanMemoryExtensionDeclaration extends MemoryExtensionDeclarationBase {
8
+ type: 'boolean';
9
+ default?: boolean;
10
+ }
11
+ export interface StringMemoryExtensionDeclaration extends MemoryExtensionDeclarationBase {
12
+ type: 'string';
13
+ default?: string;
14
+ }
15
+ export interface NumberMemoryExtensionDeclaration extends MemoryExtensionDeclarationBase {
16
+ type: 'number';
17
+ default?: number;
18
+ }
19
+ export interface EnumMemoryExtensionDeclaration extends MemoryExtensionDeclarationBase {
20
+ type: 'enum';
21
+ values: string[];
22
+ default?: string;
23
+ }
24
+ export type MemoryExtensionDeclaration = BooleanMemoryExtensionDeclaration | StringMemoryExtensionDeclaration | NumberMemoryExtensionDeclaration | EnumMemoryExtensionDeclaration;
25
+ /** Field declarations owned by one plugin manifest. The plugin's `name` is
26
+ * the namespace; keys here are its lowercase kebab-case local field names. */
27
+ export type MemoryExtensionDeclarations = Record<string, MemoryExtensionDeclaration>;
28
+ export declare function isMemoryExtensionScalar(value: unknown): value is MemoryExtensionScalar;
29
+ export declare function validDefault(declaration: MemoryExtensionDeclaration, value: unknown): value is MemoryExtensionScalar;
30
+ /** Parse the closed declaration addendum. Callers that accept a plugin manifest
31
+ * invoke this at their install/preflight boundary; normal runtime catalogs only
32
+ * admit declarations which have already cleared that boundary. */
33
+ export declare function validateMemoryExtensionDeclarations(raw: unknown): MemoryExtensionDeclarations;
34
+ export {};
@@ -0,0 +1 @@
1
+ var m=Object.defineProperty;var l=(e,i)=>m(e,"name",{value:i,configurable:!0});const w=/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/,b=new Set(["type","values","default","write_help","edit_help"]);function d(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}l(d,"isRecord");function _(e){return typeof e=="string"||typeof e=="boolean"||typeof e=="number"&&Number.isFinite(e)}l(_,"isMemoryExtensionScalar");function n(e,i){return new Error(`invalid memory_extensions declaration at ${e}: ${i}`)}l(n,"declarationError");function h(e){return typeof e=="string"&&e.trim()!==""&&!/[\r\n]/.test(e)}l(h,"validHelp");function y(e,i){return _(i)?e.type==="enum"?typeof i=="string"&&e.values.includes(i):typeof i===e.type:!1}l(y,"validDefault");function g(e){if(!d(e))throw n("memory_extensions","expected a non-empty object");const i={},p=Object.entries(e);if(p.length===0)throw n("memory_extensions","must not be empty");for(const[a,t]of p){const o=`memory_extensions.${a}`;if(!w.test(a))throw n(o,"field names must be lowercase kebab-case");if(!d(t))throw n(o,"expected a declaration object");for(const r of Object.keys(t))if(!b.has(r))throw n(o,`unknown key \`${r}\``);const s=t.type;if(s!=="boolean"&&s!=="string"&&s!=="number"&&s!=="enum")throw n(`${o}.type`,"expected boolean, string, number, or enum");if(!h(t.write_help))throw n(`${o}.write_help`,"expected a nonblank single-line string");if(!h(t.edit_help))throw n(`${o}.edit_help`,"expected a nonblank single-line string");if(s==="enum"){const r=t.values;if(!Array.isArray(r)||r.length===0||!r.every(c=>typeof c=="string"&&c!==""))throw n(`${o}.values`,"expected a non-empty string list");if(new Set(r).size!==r.length)throw n(`${o}.values`,"values must be unique");const u={type:s,values:[...r],write_help:t.write_help,edit_help:t.edit_help};if("default"in t){if(!y(u,t.default))throw n(`${o}.default`,"must be one of the declared enum values");u.default=t.default}i[a]=u;continue}if("values"in t)throw n(`${o}.values`,"is allowed only for enum declarations");const f={type:s,write_help:t.write_help,edit_help:t.edit_help};if("default"in t){if(!y(f,t.default))throw n(`${o}.default`,`must be a ${s}`);f.default=t.default}i[a]=f}return i}l(g,"validateMemoryExtensionDeclarations");export{_ as isMemoryExtensionScalar,y as validDefault,g as validateMemoryExtensionDeclarations};
@@ -21,7 +21,7 @@ await writeFile('acme.tar', bundle.tar);
21
21
 
22
22
  `buildBundle` returns `commandsJson`, `bundleJson`, generated `memory/` members, uncompressed tar bytes, and an ETag. It runs the manifest validator and throws `ManifestInvalidError` when the generated command manifest is invalid. `buildCommandManifest(plugin, { mountPath })` returns the manifest object when archive bytes are not needed.
23
23
 
24
- The tar has exactly `bundle.json`, `commands.json`, and `memory/<name>.md` members for the documents declared in the `memory` array of `definePlugin`. `bundle.json` carries `bundleVersion`, plus `version` when the plugin declares one, `object_kinds` when it declares object kinds, and `groups` when a provider declares its tool groups (the directory refuses a provider archive without them). `groups` is keyed by group id, each value `{"consent_line": string, "who"?: "own" | "user" | "allowlist" | "any" | "team:<id>", "allowlist"?: string[]}`, with `who` and `allowlist` written only when declared:
24
+ The tar has exactly `bundle.json`, `commands.json`, and `memory/<name>.md` members for the documents declared in the `memory` array of `definePlugin`. `bundle.json` carries `bundleVersion`, plus `version` when the plugin declares one, `object_kinds` when it declares object kinds, `memory_extensions` when it declares `memoryExtensions`, and `groups` when a provider declares its tool groups (the directory refuses a provider archive without them). `groups` is keyed by group id, each value `{"consent_line": string, "who"?: "own" | "user" | "allowlist" | "any" | "team:<id>", "allowlist"?: string[]}`, with `who` and `allowlist` written only when declared:
25
25
 
26
26
  ```json
27
27
  {"bundleVersion":1,"version":1,"groups":{"read":{"consent_line":"Read your Acme apps and deployments."},"deploy":{"consent_line":"Start deployments on your Acme apps.","who":"allowlist","allowlist":["app:k3x9"]}}}
@@ -55,3 +55,18 @@ memory: [{
55
55
  ```
56
56
 
57
57
  `definePlugin` rejects a rule the installer would drop. Every rule costs context in every node it reaches, so prefer the narrowest trigger, and keep a `boot` rule at `content` for short, always-relevant guidance. An installation's profile can lower what a plugin's documents deliver at `boot`.
58
+
59
+
60
+ ## Typed document fields
61
+
62
+ `definePlugin({memoryExtensions})` declares typed frontmatter fields for documents; `buildBundle` writes them as `memory_extensions`, and crtr's installer validates them with the same function (`validateMemoryExtensionDeclarations`). Field names are lowercase kebab-case; values live at `extensions.<plugin name>.<field>`.
63
+
64
+ ```ts
65
+ definePlugin({
66
+ // ...
67
+ memoryExtensions: {
68
+ status: { type: 'enum', values: ['open', 'done'], default: 'open', write_help: 'Set the home status.', edit_help: 'Change the home status.' },
69
+ pinned: { type: 'boolean', write_help: 'Pin to the top.', edit_help: 'Pin or unpin.' },
70
+ },
71
+ });
72
+ ```
@@ -19,7 +19,7 @@ crtr keeps one graph of **objects** in one Postgres database — a cluster crtrd
19
19
  - **Owners** are objects too: a node, the person (`user`), a profile, an app, or a repo. The owner decides who may read and change a document, where it syncs, and what deletes it. The default owner is the writing node (the document goes away with the node unless a kept document links to it); `--owner user|profile|app|repo` makes it outlive the node. A repo owns only public documents and syncs them to collaborators over the git ref `refs/crtr/docs`. An installed plugin is an app (`app:<plugin>`); crtr's own documents belong to the app `crtr`. Which owner to pick: [[internal/agent-shaping]].
20
20
  - **Names and pointers.** A document's full name is `<owner-handle>/<path>`; a node's handle is its id, so a node's report is `<node-id>/reports/<ts>-<id>-<kind>`. Point at an object as `[[name]]`, never by file path. In a document body each `[[link]]` attaches the target's preview wherever the body is delivered in full, and creates a `links-to` edge. A bare name resolves in the reader's view — own node, repos nearest-first, profile, app, then the person, installed plugins, and `crtr` last — so a repo document can shadow one of crtr's own. Moving a document (`doc move`) keeps its id and its links.
21
21
  - **Sharing.** Privacy has two levels, `public` and `private`, with one meaning on every object: an app reads a private object only through a scope that allows private. Between people, a share is a permission on one object: `crtr canvas share <object> <read|edit|message|use> <user:ID|team:ID|everyone>` (`--revoke` removes it). The owner and the owner's agents share; a shared person cannot re-share. `read` works on any object, `edit` on documents, `message` on nodes and profiles, `use` on environments; `everyone` is read-only and needs a joined install. A share flows down to everything the object owns, and `crtr canvas list --shared` lists what you reach only through a share.
22
- - **Watches and events.** Every object publishes events — all kinds share created, read, watched, deleted and configured; each kind adds its own (a document `edited`, a node `report.update`, a job `exited`) — each with a level 1–10. **Reading an object, writing a document, messaging a node, spawning one or starting a job makes you its watcher**, and its later events reach your inbox — an edit to a document you read can steer you while you run. `crtr canvas watch` adds a watch with a pattern or listening config; `crtr canvas unwatch` ends one when the object no longer bears on your work. `list`, `search` and `edges` record nothing. `crtr canvas edges` shows `acted-on`, `links-to` and `watches` edges.
22
+ - **Watches and events.** Every object publishes events — all kinds share created, read, watched, deleted and configured; each kind adds its own (a document `edited`, a node `report.update`, a job `exited`) — each with a level 1–10. **Reading an object, writing a document, messaging a node, spawning one or starting a job makes you its watcher**, and its later events reach your inbox — an edit to a document you read reaches you after your current turn and never wakes an idle node. `crtr canvas watch` adds a watch with a pattern or listening config; `crtr canvas unwatch` ends one when the object no longer bears on your work. `list`, `search` and `edges` record nothing. `crtr canvas edges` shows `acted-on`, `links-to` and `watches` edges.
23
23
  - **Jobs** are backgrounded bash commands: object type `job`, readable with `crtr canvas read` (command, status, exit code, log path). A job emits `exited` and `killed` events to its watchers.
24
24
  - **Custom objects** are objects an outside service, script or app registers with `crtr custom-object register` — a dotted kind, a declared event catalog with fixed levels, and optionally a receiver (`queue` pulled with `receive`/`ack`, an HTTPS `url`, or an `argv` command). They `publish` declared events to watchers and, with `crtr canvas watch --as <object>`, can watch other objects. Use one when something outside crtr must surface state on the canvas or react to canvas events.
25
25
  - **What is still files.** A node's context directory (`$CRTR_CONTEXT_DIR`) holds scripts, data, logs and page modules — never the way to share writing. Package documents (crtr's own and a plugin's `memory/` folder) stay markdown files in their package and are imported as public, read-only documents; see [[internal/plugins]].
@@ -42,7 +42,7 @@ A node's shell is not the person's. `HOME` depends on the app and execution mode
42
42
 
43
43
  ## Watches — how events reach a node
44
44
 
45
- Every object emits events, each with a level (1–10), and a **watch** routes an object's events to a watcher. Reading an object, writing or editing a document, messaging a node, spawning a node or starting a job makes you a watcher of it, so a document you read can steer you when it is edited and a child you spawn wakes you when it finishes. The watcher's listening configuration decides how an event arrives — interrupt, steer, after the current turn, or at the next turn — by level (by default 10 interrupts, 7–9 steer, 5–6 wait for the turn to end, 3–4 wait for the next turn). `crtr canvas watch <name> [--pattern … --listen …]` adds a watch without reading; `crtr canvas unwatch <name>` removes one — do it when an object no longer bears on your work so its events stop arriving. `crtr canvas edges <your id> --type watches --direction out` lists everything you watch. Node events include `report.update`/`report.final` (from `push`), `messaged`, and `notice.crash`/`close`; a job emits `exited`/`killed`; a document emits `edited`/`deleted`.
45
+ Every object emits events, each with a level (1–10), and a **watch** routes an object's events to a watcher. Reading an object, writing or editing a document, messaging a node, spawning a node or starting a job makes you a watcher of it, so a document you read reaches you when it is edited (as deferred mail: after your current turn, never waking an idle node) and a child you spawn wakes you when it finishes. The watcher's listening configuration decides how an event arrives — interrupt, steer, after the current turn, or at the next turn — by level (by default 10 interrupts, 7–9 steer, 5–6 wait for the turn to end, 3–4 wait for the next turn). `crtr canvas watch <name> [--pattern … --listen …]` adds a watch without reading; `crtr canvas unwatch <name>` removes one — do it when an object no longer bears on your work so its events stop arriving. `crtr canvas edges <your id> --type watches --direction out` lists everything you watch. Node events include `report.update`/`report.final` (from `push`), `messaged`, and `notice.crash`/`close`; a job emits `exited`/`killed`; a document emits `edited`/`deleted`.
46
46
 
47
47
  **Jobs** are backgrounded bash commands, objects of type `job` that you watch from the start; `crtr canvas read <job>` shows command, status, exit code and log path. **Custom objects** (`crtr custom-object register`) let an outside service or script publish declared events to watchers on the canvas, with a queue, URL or argv receiver for events it watches in turn; see `crtr custom-object -h`.
48
48
 
@@ -130,7 +130,7 @@ export declare function moveDocument(db: CanvasDb, reader: Reader | null, doc: O
130
130
  owner?: ObjectRow;
131
131
  }, reposFn?: ReposFn): Promise<ObjectRow>;
132
132
  /** Mark the document deleted; the row stays with its last preview. Publishes `deleted`
133
- * (level 8), then ends the watches on it and drops its rules. A null actor is repo sync or
133
+ * (level 4: deferred mail, never a wake), then ends the watches on it and drops its rules. A null actor is repo sync or
134
134
  * node deletion; `deletedAt` is the tombstone's own time when sync imports one. What it linked to is re-checked by {@link collectUnlinked}. */
135
135
  export declare function deleteDocument(db: CanvasDb, reader: Reader | null, doc: ObjectRow, reposFn?: ReposFn, deletedAt?: string): Promise<ObjectRow>;
136
136
  /** Repo sync: bring a deleted document back under `name` (checked free first). Revisions, record
@@ -2,4 +2,4 @@ var _=Object.defineProperty;var m=(e,t)=>_(e,"name",{value:t,configurable:!0});i
2
2
  AND substr(o.name, 1, ?) = ? AND strpos(substr(o.name, ? + 1), '/') = 0 AND ${i.sql} ORDER BY o.name`).all(n.owner,s.length,s,s.length,...i.params);return await p(e,a)}m(I,"listingOf");async function L(e,t,n){const s=t.class==="node",i=s?await A(e,t.node.id):{node:"",preferenceSnapshot:null,objects:new Map,listed:new Map},a={db:e,reader:t,subject:s?await D(e,t):null,ledger:i,channel:"transcript"},o=await $(a,await N(e,t,n));return{attachments:o.attachments,linked:o.linked.map(u=>u.object),...s?{ledger:i}:{},delivered:o.delivered}}m(L,"explicitReadAttachments");function M(e,t){const n=[];if(t.attachments&&n.push(t.attachments,""),n.push(T("object",e,l("privacy",e.privacy)+l("revision",t.revision))),n.push(`Preview: ${e.preview}`),t.summary&&n.push(`Summary: ${t.summary}`),t.fields!==void 0&&n.push(`<fields>
3
3
  ${JSON.stringify(t.fields,null,2)}
4
4
  </fields>`),t.needs_merge?(t.heads.forEach((s,i)=>{n.push(`<head${l("rev",s.rev_id)}${l("number",s.number)}${l("author",s.author_id)}>`,t.bodies[i]??"","</head>")}),n.push(`This document has ${t.heads.length} heads. Your next \`crtr doc edit\` writes the merged body and joins them into one revision.`)):n.push("",t.bodies[0]??""),t.listing&&t.listing.length>0){const s=t.listing.some(o=>o.owner?.id===e.owner?.id&&o.name.startsWith(`${e.name}/`)),i=t.listing.some(o=>o.owner?.id!==e.owner?.id||!o.name.startsWith(`${e.name}/`)),a=s&&i?`Names under ${e.name}/ and documents it links to`:s?`Names under ${e.name}/`:"Documents it links to";n.push("",...k(a,t.listing))}return n.join(`
5
- `)}m(M,"render");function K(e){const t=e.attrs.revision,n=e.attrs.from_revision??(typeof t=="number"?t-1:null),s=e.attrs.rationale;return{...e.attrs,from_revision:n,revision:t,authors:e.actor?[e.actor.id]:[],rationales:typeof s=="string"?[s]:[]}}m(K,"editAttrs");const U=m((e,t)=>{const n=K(t);if(e===null)return n;const s=e.authors??[];return{...n,from_revision:e.from_revision??null,authors:[...s,...n.authors.filter(i=>!s.includes(i))],rationales:[...e.rationales??[],...n.rationales]}},"mergeEdits"),G={name:"document",addressable:"name",events:E({edited:{level:8,supersedes:!0,merge:U},deleted:{level:8}}),async listItem(e,t){return{summary:(await j(e,t)).summary??null,rules:(await f(e,t)).length}},async read(e,t,n,s){const i=await b(e,t,n),a=i.record,o=await I(e,await O(e,t),n),{attachments:u,linked:w,ledger:c,delivered:g}=await L(e,t,n),y=new Set(o.map(r=>r.id)),h=[...o,...await p(e,w.filter(r=>!y.has(r.id)))],d={summary:a.summary??null,revision:a.revision,heads:i.heads.map(r=>({rev_id:r.rev_id,number:r.number,author_id:r.author,created_at:r.created_at})),bodies:i.heads.map(r=>r.body),needs_merge:i.needsMerge,...h.length>0?{listing:h}:{},...u===""?{}:{attachments:u}};return s.fields&&(d.fields={why_it_exists:a.why_it_exists??null,unlisted:a.unlisted,lint_ignore:a.lint_ignore??[],extensions:a.extensions??{},rules:(await f(e,n)).map(({matchFrontmatter:r,...v})=>({...v,...r===void 0?{}:{match_frontmatter:r}}))}),{data:d,text:M(await R(e,n),d),record:{headsKey:S(i.heads),...c===void 0?{}:{ledger:c},delivered:g}}}};export{G as documentKind};
5
+ `)}m(M,"render");function K(e){const t=e.attrs.revision,n=e.attrs.from_revision??(typeof t=="number"?t-1:null),s=e.attrs.rationale;return{...e.attrs,from_revision:n,revision:t,authors:e.actor?[e.actor.id]:[],rationales:typeof s=="string"?[s]:[]}}m(K,"editAttrs");const U=m((e,t)=>{const n=K(t);if(e===null)return n;const s=e.authors??[];return{...n,from_revision:e.from_revision??null,authors:[...s,...n.authors.filter(i=>!s.includes(i))],rationales:[...e.rationales??[],...n.rationales]}},"mergeEdits"),G={name:"document",addressable:"name",events:E({edited:{level:4,supersedes:!0,merge:U},deleted:{level:4}}),async listItem(e,t){return{summary:(await j(e,t)).summary??null,rules:(await f(e,t)).length}},async read(e,t,n,s){const i=await b(e,t,n),a=i.record,o=await I(e,await O(e,t),n),{attachments:u,linked:w,ledger:c,delivered:g}=await L(e,t,n),y=new Set(o.map(r=>r.id)),h=[...o,...await p(e,w.filter(r=>!y.has(r.id)))],d={summary:a.summary??null,revision:a.revision,heads:i.heads.map(r=>({rev_id:r.rev_id,number:r.number,author_id:r.author,created_at:r.created_at})),bodies:i.heads.map(r=>r.body),needs_merge:i.needsMerge,...h.length>0?{listing:h}:{},...u===""?{}:{attachments:u}};return s.fields&&(d.fields={why_it_exists:a.why_it_exists??null,unlisted:a.unlisted,lint_ignore:a.lint_ignore??[],extensions:a.extensions??{},rules:(await f(e,n)).map(({matchFrontmatter:r,...v})=>({...v,...r===void 0?{}:{match_frontmatter:r}}))}),{data:d,text:M(await R(e,n),d),record:{headsKey:S(i.heads),...c===void 0?{}:{ledger:c},delivered:g}}}};export{G as documentKind};
@@ -1,4 +1,6 @@
1
- import type { MemoryExtensionDeclarations, MemoryExtensionScalar, PluginManifest, Scope } from '../types.js';
1
+ import { isMemoryExtensionScalar, validateMemoryExtensionDeclarations, type MemoryExtensionDeclarations } from '../api/command-manifest/memory-extensions.js';
2
+ import type { PluginManifest, Scope } from '../types.js';
3
+ export { isMemoryExtensionScalar, validateMemoryExtensionDeclarations };
2
4
  export type MemoryExtensionCatalog = Record<string, MemoryExtensionDeclarations>;
3
5
  export interface MemoryExtensionValidationIssue {
4
6
  path: string;
@@ -8,11 +10,6 @@ export interface MemoryExtensionCatalogOptions {
8
10
  /** The manifest currently being staged. Its namespace shadows an installed copy only for that candidate validation. */
9
11
  candidate?: Pick<PluginManifest, 'name' | 'memory_extensions'>;
10
12
  }
11
- export declare function isMemoryExtensionScalar(value: unknown): value is MemoryExtensionScalar;
12
- /** Parse the closed declaration addendum. Callers that accept a plugin manifest
13
- * invoke this at their install/preflight boundary; normal runtime catalogs only
14
- * admit declarations which have already cleared that boundary. */
15
- export declare function validateMemoryExtensionDeclarations(raw: unknown): MemoryExtensionDeclarations;
16
13
  /** Throw when a manifest carries an invalid addendum; absent is valid. */
17
14
  export declare function validatePluginMemoryExtensions(manifest: Pick<PluginManifest, 'memory_extensions'>): void;
18
15
  /** Declarations for a native document. Project documents use their owning
@@ -1 +1 @@
1
- var _=Object.defineProperty;var l=(e,o)=>_(e,"name",{value:o,configurable:!0});import{listInstalledPlugins as y,listInstalledPluginsInRoot as $}from"./resolver.js";const v=/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/,j=new Set(["type","values","default","write_help","edit_help"]);function p(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}l(p,"isRecord");function m(e){return typeof e=="string"||typeof e=="boolean"||typeof e=="number"&&Number.isFinite(e)}l(m,"isMemoryExtensionScalar");function f(e,o){return new Error(`invalid memory_extensions declaration at ${e}: ${o}`)}l(f,"declarationError");function g(e){return typeof e=="string"&&e.trim()!==""&&!/[\r\n]/.test(e)}l(g,"validHelp");function h(e,o){return m(o)?e.type==="enum"?typeof o=="string"&&e.values.includes(o):typeof o===e.type:!1}l(h,"validDefault");function x(e){if(!p(e))throw f("memory_extensions","expected a non-empty object");const o={},i=Object.entries(e);if(i.length===0)throw f("memory_extensions","must not be empty");for(const[a,n]of i){const t=`memory_extensions.${a}`;if(!v.test(a))throw f(t,"field names must be lowercase kebab-case");if(!p(n))throw f(t,"expected a declaration object");for(const s of Object.keys(n))if(!j.has(s))throw f(t,`unknown key \`${s}\``);const r=n.type;if(r!=="boolean"&&r!=="string"&&r!=="number"&&r!=="enum")throw f(`${t}.type`,"expected boolean, string, number, or enum");if(!g(n.write_help))throw f(`${t}.write_help`,"expected a nonblank single-line string");if(!g(n.edit_help))throw f(`${t}.edit_help`,"expected a nonblank single-line string");if(r==="enum"){const s=n.values;if(!Array.isArray(s)||s.length===0||!s.every(c=>typeof c=="string"&&c!==""))throw f(`${t}.values`,"expected a non-empty string list");if(new Set(s).size!==s.length)throw f(`${t}.values`,"values must be unique");const d={type:r,values:[...s],write_help:n.write_help,edit_help:n.edit_help};if("default"in n){if(!h(d,n.default))throw f(`${t}.default`,"must be one of the declared enum values");d.default=n.default}o[a]=d;continue}if("values"in n)throw f(`${t}.values`,"is allowed only for enum declarations");const u={type:r,write_help:n.write_help,edit_help:n.edit_help};if("default"in n){if(!h(u,n.default))throw f(`${t}.default`,`must be a ${r}`);u.default=n.default}o[a]=u}return o}l(x,"validateMemoryExtensionDeclarations");function O(e){e.memory_extensions!==void 0&&x(e.memory_extensions)}l(O,"validatePluginMemoryExtensions");function b(e,o){if(e.memory_extensions!==void 0)try{return x(e.memory_extensions)}catch(i){if(o)throw i;return}}l(b,"declarationsFromManifest");function E(e,o,i){const a={},n=new Set;if(i!==void 0){n.add(i.name);const t=b(i,!0);t!==void 0&&(a[i.name]=t)}for(const t of e)for(const r of t){if(o&&!r.enabled)continue;const u=r.manifest.name;if(n.has(u)||a[u]!==void 0)continue;const s=b(r.manifest,!1);s!==void 0&&(a[u]=s)}return a}l(E,"catalogForPlugins");function M(e,o,i={}){const a=e==="project"?[$("project",o),y("user")]:e==="builtin"?[]:[y("user")];return E(a,!1,i.candidate)}l(M,"pluginExtensionCatalog");function I(e,o){if(e===void 0)return[];if(!p(e))return[{path:"extensions",message:"expected a mapping"}];const i=[];for(const[a,n]of Object.entries(e)){const t=`extensions.${a}`;if(!p(n)){i.push({path:t,message:"expected a mapping"});continue}const r=o[a];if(r===void 0){i.push({path:t,message:"unresolved extension namespace"});for(const[u,s]of Object.entries(n))m(s)||i.push({path:`${t}.${u}`,message:"expected a string, boolean, or finite number"});continue}for(const[u,s]of Object.entries(n)){const d=`${t}.${u}`;if(!m(s)){i.push({path:d,message:"expected a string, boolean, or finite number"});continue}const c=r[u];if(c===void 0){i.push({path:d,message:"undeclared extension field"});continue}if(!h(c,s)){const w=c.type==="enum"?`one of ${c.values.join("|")}`:c.type;i.push({path:d,message:`expected ${w}`})}}}return i}l(I,"validateMemoryExtensionValues");export{m as isMemoryExtensionScalar,M as pluginExtensionCatalog,x as validateMemoryExtensionDeclarations,I as validateMemoryExtensionValues,O as validatePluginMemoryExtensions};
1
+ var y=Object.defineProperty;var a=(e,t)=>y(e,"name",{value:t,configurable:!0});import{isMemoryExtensionScalar as l,validateMemoryExtensionDeclarations as p,validDefault as b}from"../api/command-manifest/memory-extensions.js";import{listInstalledPlugins as m,listInstalledPluginsInRoot as j}from"./resolver.js";function x(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}a(x,"isRecord");function P(e){e.memory_extensions!==void 0&&p(e.memory_extensions)}a(P,"validatePluginMemoryExtensions");function g(e,t){if(e.memory_extensions!==void 0)try{return p(e.memory_extensions)}catch(n){if(t)throw n;return}}a(g,"declarationsFromManifest");function $(e,t,n){const o={},u=new Set;if(n!==void 0){u.add(n.name);const s=g(n,!0);s!==void 0&&(o[n.name]=s)}for(const s of e)for(const f of s){if(t&&!f.enabled)continue;const i=f.manifest.name;if(u.has(i)||o[i]!==void 0)continue;const r=g(f.manifest,!1);r!==void 0&&(o[i]=r)}return o}a($,"catalogForPlugins");function _(e,t,n={}){const o=e==="project"?[j("project",t),m("user")]:e==="builtin"?[]:[m("user")];return $(o,!1,n.candidate)}a(_,"pluginExtensionCatalog");function I(e,t){if(e===void 0)return[];if(!x(e))return[{path:"extensions",message:"expected a mapping"}];const n=[];for(const[o,u]of Object.entries(e)){const s=`extensions.${o}`;if(!x(u)){n.push({path:s,message:"expected a mapping"});continue}const f=t[o];if(f===void 0){n.push({path:s,message:"unresolved extension namespace"});for(const[i,r]of Object.entries(u))l(r)||n.push({path:`${s}.${i}`,message:"expected a string, boolean, or finite number"});continue}for(const[i,r]of Object.entries(u)){const d=`${s}.${i}`;if(!l(r)){n.push({path:d,message:"expected a string, boolean, or finite number"});continue}const c=f[i];if(c===void 0){n.push({path:d,message:"undeclared extension field"});continue}if(!b(c,r)){const h=c.type==="enum"?`one of ${c.values.join("|")}`:c.type;n.push({path:d,message:`expected ${h}`})}}}return n}a(I,"validateMemoryExtensionValues");export{l as isMemoryExtensionScalar,_ as pluginExtensionCatalog,p as validateMemoryExtensionDeclarations,I as validateMemoryExtensionValues,P as validatePluginMemoryExtensions};
@@ -9,7 +9,7 @@ export declare function deleteNodeSandboxes(nodeIds: readonly string[]): Promise
9
9
  * The check and the DELETE run holding the node row's lock, which `beginExecution` also takes, so no new execution can start in
10
10
  * the sandbox between them. */
11
11
  export declare function deleteSandboxOfEndedNode(nodeId: string): void;
12
- /** Delete the sandbox of every finished, canceled, dead or parked node quiet for `quietMs`, keeping its rows; app runs included.
12
+ /** Delete the sandbox of every finished, canceled, dead, parked or idle-released node quiet for `quietMs`, keeping its rows; app runs included.
13
13
  * `quiet` decides the activity test ({@link lastActivityMs} reads disk too); `held` excludes nodes retention must not touch.
14
14
  * Each node is marked `sandbox_deleted_at` so later passes skip it until a new execution clears the mark. Returns the deleted count. */
15
15
  export declare function deleteQuietNodeSandboxes(opts: {
@@ -1,14 +1,14 @@
1
- var u=Object.defineProperty;var o=(e,n)=>u(e,"name",{value:n,configurable:!0});import{afterCommit as S,openDb as l,withCanvasWrite as s}from"../../canvas/db.js";import{emitEvent as i}from"../../events/emit.js";const N=60*6e4,c=`EXISTS (SELECT 1 FROM executions x WHERE x.node_id = n.node_id
2
- AND (x.state = 'running' OR (x.state = 'launching' AND x.started_at > ?)))`;function _(e=Date.now()){return new Date(e-N).toISOString()}o(_,"staleLaunchCutoff");async function O(e){if(e.length===0)return[];const n=e.map(()=>"?").join(","),d=await(await l()).prepare(`SELECT DISTINCT node_id FROM executions WHERE runner = 'blaxel' AND node_id IN (${n})`).all(...e),a=[];for(const{node_id:t}of d)try{await(await import("./index.js")).runnerForExecution("blaxel").delete(t)}catch(r){a.push(t),i({level:"error",event:"canvas.node_sandbox.delete_failed",node_id:t,error:r})}return a}o(O,"deleteNodeSandboxes");function f(e){S(()=>{s(async n=>{await n.prepare(`SELECT 1 AS ended FROM nodes n WHERE n.node_id = ?
1
+ var N=Object.defineProperty;var o=(e,n)=>N(e,"name",{value:n,configurable:!0});import{afterCommit as u,openDb as l,withCanvasWrite as s}from"../../canvas/db.js";import{emitEvent as i}from"../../events/emit.js";const x=60*6e4,c=`EXISTS (SELECT 1 FROM executions x WHERE x.node_id = n.node_id
2
+ AND (x.state = 'running' OR (x.state = 'launching' AND x.started_at > ?)))`,_="(n.status IN ('done', 'canceled', 'dead') OR (n.status = 'idle' AND n.intent = 'idle-release'))";function S(e=Date.now()){return new Date(e-x).toISOString()}o(S,"staleLaunchCutoff");async function R(e){if(e.length===0)return[];const n=e.map(()=>"?").join(","),d=await(await l()).prepare(`SELECT DISTINCT node_id FROM executions WHERE runner = 'blaxel' AND node_id IN (${n})`).all(...e),a=[];for(const{node_id:t}of d)try{await(await import("./index.js")).runnerForExecution("blaxel").delete(t)}catch(r){a.push(t),i({level:"error",event:"canvas.node_sandbox.delete_failed",node_id:t,error:r})}return a}o(R,"deleteNodeSandboxes");function f(e){u(()=>{s(async n=>{await n.prepare(`SELECT 1 AS ended FROM nodes n WHERE n.node_id = ?
3
3
  AND EXISTS (SELECT 1 FROM executions x WHERE x.node_id = n.node_id AND x.runner = 'blaxel')
4
4
  AND (n.status IN ('canceled', 'dead') OR (n.status = 'done' AND n.intent IS DISTINCT FROM 'parked'))
5
5
  AND NOT ${c}
6
6
  AND NOT EXISTS (SELECT 1 FROM crons c WHERE c.anchor_node = n.node_id AND c.cancel_on_wake = 0)
7
- FOR UPDATE OF n`).get(e,_())!==void 0&&(await(await import("./index.js")).runnerForExecution("blaxel").delete(e),await n.prepare("UPDATE nodes SET sandbox_deleted_at = ? WHERE node_id = ?").run(new Date().toISOString(),e))}).catch(n=>{i({level:"error",event:"canvas.node_sandbox.delete_failed",node_id:e,error:n})})})}o(f,"deleteSandboxOfEndedNode");async function w(e){const n=_(e.now),d=await(await l()).prepare(`SELECT n.node_id FROM nodes n WHERE n.status IN ('done', 'canceled', 'dead')
7
+ FOR UPDATE OF n`).get(e,S())!==void 0&&(await(await import("./index.js")).runnerForExecution("blaxel").delete(e),await n.prepare("UPDATE nodes SET sandbox_deleted_at = ? WHERE node_id = ?").run(new Date().toISOString(),e))}).catch(n=>{i({level:"error",event:"canvas.node_sandbox.delete_failed",node_id:e,error:n})})})}o(f,"deleteSandboxOfEndedNode");async function w(e){const n=S(e.now),d=await(await l()).prepare(`SELECT n.node_id FROM nodes n WHERE ${_}
8
8
  AND n.sandbox_deleted_at IS NULL
9
9
  AND EXISTS (SELECT 1 FROM executions x WHERE x.node_id = n.node_id AND x.runner = 'blaxel')
10
10
  AND NOT ${c}
11
- AND NOT EXISTS (SELECT 1 FROM crons c WHERE c.anchor_node = n.node_id AND c.cancel_on_wake = 0)`).all(n);let a=0;for(const{node_id:t}of d)if(!(!await e.quiet(t)||await e.held(t)))try{await s(async E=>await E.prepare(`SELECT 1 AS ok FROM nodes n WHERE n.node_id = ? AND n.status IN ('done', 'canceled', 'dead')
11
+ AND NOT EXISTS (SELECT 1 FROM crons c WHERE c.anchor_node = n.node_id AND c.cancel_on_wake = 0)`).all(n);let a=0;for(const{node_id:t}of d)if(!(!await e.quiet(t)||await e.held(t)))try{await s(async E=>await E.prepare(`SELECT 1 AS ok FROM nodes n WHERE n.node_id = ? AND ${_}
12
12
  AND n.sandbox_deleted_at IS NULL AND NOT ${c}
13
13
  AND NOT EXISTS (SELECT 1 FROM crons c WHERE c.anchor_node = n.node_id AND c.cancel_on_wake = 0)
14
- FOR UPDATE OF n`).get(t,n)===void 0?!1:(await(await import("./index.js")).runnerForExecution("blaxel").delete(t),await E.prepare("UPDATE nodes SET sandbox_deleted_at = ? WHERE node_id = ?").run(new Date().toISOString(),t),!0))&&a++}catch(r){i({level:"error",event:"canvas.node_sandbox.delete_failed",node_id:t,error:r})}return a}o(w,"deleteQuietNodeSandboxes");export{N as STALE_LAUNCH_MS,O as deleteNodeSandboxes,w as deleteQuietNodeSandboxes,f as deleteSandboxOfEndedNode};
14
+ FOR UPDATE OF n`).get(t,n)===void 0?!1:(await(await import("./index.js")).runnerForExecution("blaxel").delete(t),await E.prepare("UPDATE nodes SET sandbox_deleted_at = ? WHERE node_id = ?").run(new Date().toISOString(),t),!0))&&a++}catch(r){i({level:"error",event:"canvas.node_sandbox.delete_failed",node_id:t,error:r})}return a}o(w,"deleteQuietNodeSandboxes");export{x as STALE_LAUNCH_MS,R as deleteNodeSandboxes,w as deleteQuietNodeSandboxes,f as deleteSandboxOfEndedNode};
package/dist/types.d.ts CHANGED
@@ -33,33 +33,8 @@ export interface PluginBundle {
33
33
  endpoint: string;
34
34
  authEnv?: string;
35
35
  }
36
- export type MemoryExtensionScalar = string | boolean | number;
37
- export type MemoryExtensionFieldType = 'boolean' | 'string' | 'number' | 'enum';
38
- interface MemoryExtensionDeclarationBase {
39
- write_help: string;
40
- edit_help: string;
41
- }
42
- export interface BooleanMemoryExtensionDeclaration extends MemoryExtensionDeclarationBase {
43
- type: 'boolean';
44
- default?: boolean;
45
- }
46
- export interface StringMemoryExtensionDeclaration extends MemoryExtensionDeclarationBase {
47
- type: 'string';
48
- default?: string;
49
- }
50
- export interface NumberMemoryExtensionDeclaration extends MemoryExtensionDeclarationBase {
51
- type: 'number';
52
- default?: number;
53
- }
54
- export interface EnumMemoryExtensionDeclaration extends MemoryExtensionDeclarationBase {
55
- type: 'enum';
56
- values: string[];
57
- default?: string;
58
- }
59
- export type MemoryExtensionDeclaration = BooleanMemoryExtensionDeclaration | StringMemoryExtensionDeclaration | NumberMemoryExtensionDeclaration | EnumMemoryExtensionDeclaration;
60
- /** Field declarations owned by one plugin manifest. The plugin's `name` is
61
- * the namespace; keys here are its lowercase kebab-case local field names. */
62
- export type MemoryExtensionDeclarations = Record<string, MemoryExtensionDeclaration>;
36
+ export type { MemoryExtensionScalar, MemoryExtensionFieldType, BooleanMemoryExtensionDeclaration, StringMemoryExtensionDeclaration, NumberMemoryExtensionDeclaration, EnumMemoryExtensionDeclaration, MemoryExtensionDeclaration, MemoryExtensionDeclarations, } from './api/command-manifest/memory-extensions.js';
37
+ import type { MemoryExtensionDeclarations } from './api/command-manifest/memory-extensions.js';
63
38
  /** One canvas object kind a plugin declares in `object_kinds`. */
64
39
  export interface ObjectKindDeclaration {
65
40
  description: string;
@@ -567,4 +542,3 @@ export declare function defaultRemoteCanvasConfig(): RemoteCanvasConfig;
567
542
  export declare function defaultKindsConfig(): Record<string, KindConfig>;
568
543
  export declare function defaultModelLaddersConfig(): ModelLaddersConfig;
569
544
  export declare function defaultScopeState(): ScopeState;
570
- export {};
@@ -19,7 +19,7 @@ await writeFile('acme.tar', bundle.tar);
19
19
 
20
20
  `buildBundle` returns `commandsJson`, `bundleJson`, generated `memory/` members, uncompressed tar bytes, and an ETag. It runs the manifest validator and throws `ManifestInvalidError` when the generated command manifest is invalid. `buildCommandManifest(plugin, { mountPath })` returns the manifest object when archive bytes are not needed.
21
21
 
22
- The tar has exactly `bundle.json`, `commands.json`, and `memory/<name>.md` members for the documents declared in the `memory` array of `definePlugin`. `bundle.json` carries `bundleVersion`, plus `version` when the plugin declares one, `object_kinds` when it declares object kinds, and `groups` when a provider declares its tool groups (the directory refuses a provider archive without them). `groups` is keyed by group id, each value `{"consent_line": string, "who"?: "own" | "user" | "allowlist" | "any" | "team:<id>", "allowlist"?: string[]}`, with `who` and `allowlist` written only when declared:
22
+ The tar has exactly `bundle.json`, `commands.json`, and `memory/<name>.md` members for the documents declared in the `memory` array of `definePlugin`. `bundle.json` carries `bundleVersion`, plus `version` when the plugin declares one, `object_kinds` when it declares object kinds, `memory_extensions` when it declares `memoryExtensions`, and `groups` when a provider declares its tool groups (the directory refuses a provider archive without them). `groups` is keyed by group id, each value `{"consent_line": string, "who"?: "own" | "user" | "allowlist" | "any" | "team:<id>", "allowlist"?: string[]}`, with `who` and `allowlist` written only when declared:
23
23
 
24
24
  ```json
25
25
  {"bundleVersion":1,"version":1,"groups":{"read":{"consent_line":"Read your Acme apps and deployments."},"deploy":{"consent_line":"Start deployments on your Acme apps.","who":"allowlist","allowlist":["app:k3x9"]}}}
@@ -54,3 +54,17 @@ memory: [{
54
54
 
55
55
  `definePlugin` rejects a rule the installer would drop. Every rule costs context in every node it reaches, so prefer the narrowest trigger, and keep a `boot` rule at `content` for short, always-relevant guidance. An installation's profile can lower what a plugin's documents deliver at `boot`.
56
56
 
57
+
58
+ ## Typed document fields
59
+
60
+ `definePlugin({memoryExtensions})` declares typed frontmatter fields for documents; `buildBundle` writes them as `memory_extensions`, and crtr's installer validates them with the same function (`validateMemoryExtensionDeclarations`). Field names are lowercase kebab-case; values live at `extensions.<plugin name>.<field>`.
61
+
62
+ ```ts
63
+ definePlugin({
64
+ // ...
65
+ memoryExtensions: {
66
+ status: { type: 'enum', values: ['open', 'done'], default: 'open', write_help: 'Set the home status.', edit_help: 'Change the home status.' },
67
+ pinned: { type: 'boolean', write_help: 'Pin to the top.', edit_help: 'Pin or unpin.' },
68
+ },
69
+ });
70
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@north-light/cli",
3
- "version": "0.3.788",
3
+ "version": "0.3.789",
4
4
  "description": "crtr — agent runtime with memory, plugins, and marketplaces",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -157,8 +157,8 @@
157
157
  },
158
158
  "license": "UNLICENSED",
159
159
  "dependencies": {
160
- "@north-light/identity": "0.3.788",
161
- "@north-light/plugin": "0.3.788",
160
+ "@north-light/identity": "0.3.789",
161
+ "@north-light/plugin": "0.3.789",
162
162
  "@earendil-works/chord": "1.5.2",
163
163
  "@earendil-works/pi-agent-core": "1.5.2",
164
164
  "@earendil-works/pi-ai": "1.5.2",
@@ -2,3 +2,4 @@ export * from './schema.js';
2
2
  export * from './manifest.js';
3
3
  export * from './result.js';
4
4
  export * from './object-kinds.js';
5
+ export * from './memory-extensions.js';
@@ -0,0 +1,91 @@
1
+ // The shape rules for a plugin's `memory_extensions` block, shared by crouter's install paths and the plugin kit
2
+ // (`definePlugin({memoryExtensions})`) so both refuse exactly the same declarations. Zero dependencies.
3
+ const LOCAL_FIELD_NAME = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
4
+ const DECLARATION_KEYS = new Set(['type', 'values', 'default', 'write_help', 'edit_help']);
5
+ function isRecord(value) {
6
+ return value !== null && typeof value === 'object' && !Array.isArray(value);
7
+ }
8
+ export function isMemoryExtensionScalar(value) {
9
+ return typeof value === 'string' || typeof value === 'boolean' || (typeof value === 'number' && Number.isFinite(value));
10
+ }
11
+ function declarationError(path, message) {
12
+ return new Error(`invalid memory_extensions declaration at ${path}: ${message}`);
13
+ }
14
+ function validHelp(value) {
15
+ return typeof value === 'string' && value.trim() !== '' && !/[\r\n]/.test(value);
16
+ }
17
+ export function validDefault(declaration, value) {
18
+ if (!isMemoryExtensionScalar(value))
19
+ return false;
20
+ if (declaration.type === 'enum')
21
+ return typeof value === 'string' && declaration.values.includes(value);
22
+ return typeof value === declaration.type;
23
+ }
24
+ /** Parse the closed declaration addendum. Callers that accept a plugin manifest
25
+ * invoke this at their install/preflight boundary; normal runtime catalogs only
26
+ * admit declarations which have already cleared that boundary. */
27
+ export function validateMemoryExtensionDeclarations(raw) {
28
+ if (!isRecord(raw))
29
+ throw declarationError('memory_extensions', 'expected a non-empty object');
30
+ const declarations = {};
31
+ const fields = Object.entries(raw);
32
+ if (fields.length === 0)
33
+ throw declarationError('memory_extensions', 'must not be empty');
34
+ for (const [field, value] of fields) {
35
+ const path = `memory_extensions.${field}`;
36
+ if (!LOCAL_FIELD_NAME.test(field)) {
37
+ throw declarationError(path, 'field names must be lowercase kebab-case');
38
+ }
39
+ if (!isRecord(value))
40
+ throw declarationError(path, 'expected a declaration object');
41
+ for (const key of Object.keys(value)) {
42
+ if (!DECLARATION_KEYS.has(key))
43
+ throw declarationError(path, `unknown key \`${key}\``);
44
+ }
45
+ const type = value['type'];
46
+ if (type !== 'boolean' && type !== 'string' && type !== 'number' && type !== 'enum') {
47
+ throw declarationError(`${path}.type`, 'expected boolean, string, number, or enum');
48
+ }
49
+ if (!validHelp(value['write_help']))
50
+ throw declarationError(`${path}.write_help`, 'expected a nonblank single-line string');
51
+ if (!validHelp(value['edit_help']))
52
+ throw declarationError(`${path}.edit_help`, 'expected a nonblank single-line string');
53
+ if (type === 'enum') {
54
+ const values = value['values'];
55
+ if (!Array.isArray(values) || values.length === 0 || !values.every((entry) => typeof entry === 'string' && entry !== '')) {
56
+ throw declarationError(`${path}.values`, 'expected a non-empty string list');
57
+ }
58
+ if (new Set(values).size !== values.length)
59
+ throw declarationError(`${path}.values`, 'values must be unique');
60
+ const declaration = {
61
+ type,
62
+ values: [...values],
63
+ write_help: value['write_help'],
64
+ edit_help: value['edit_help'],
65
+ };
66
+ if ('default' in value) {
67
+ if (!validDefault(declaration, value['default'])) {
68
+ throw declarationError(`${path}.default`, 'must be one of the declared enum values');
69
+ }
70
+ declaration.default = value['default'];
71
+ }
72
+ declarations[field] = declaration;
73
+ continue;
74
+ }
75
+ if ('values' in value)
76
+ throw declarationError(`${path}.values`, 'is allowed only for enum declarations');
77
+ const declaration = {
78
+ type,
79
+ write_help: value['write_help'],
80
+ edit_help: value['edit_help'],
81
+ };
82
+ if ('default' in value) {
83
+ if (!validDefault(declaration, value['default'])) {
84
+ throw declarationError(`${path}.default`, `must be a ${type}`);
85
+ }
86
+ declaration.default = value['default'];
87
+ }
88
+ declarations[field] = declaration;
89
+ }
90
+ return declarations;
91
+ }
@@ -1,95 +1,11 @@
1
1
  // plugin-extensions.ts — a plugin manifest's `memory_extensions` declarations and
2
2
  // the `extensions` frontmatter values its package documents carry.
3
+ import { isMemoryExtensionScalar, validateMemoryExtensionDeclarations, validDefault, } from '../api/command-manifest/memory-extensions.js';
3
4
  import { listInstalledPlugins, listInstalledPluginsInRoot } from './resolver.js';
4
- const LOCAL_FIELD_NAME = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
5
- const DECLARATION_KEYS = new Set(['type', 'values', 'default', 'write_help', 'edit_help']);
5
+ export { isMemoryExtensionScalar, validateMemoryExtensionDeclarations };
6
6
  function isRecord(value) {
7
7
  return value !== null && typeof value === 'object' && !Array.isArray(value);
8
8
  }
9
- export function isMemoryExtensionScalar(value) {
10
- return typeof value === 'string' || typeof value === 'boolean' || (typeof value === 'number' && Number.isFinite(value));
11
- }
12
- function declarationError(path, message) {
13
- return new Error(`invalid memory_extensions declaration at ${path}: ${message}`);
14
- }
15
- function validHelp(value) {
16
- return typeof value === 'string' && value.trim() !== '' && !/[\r\n]/.test(value);
17
- }
18
- function validDefault(declaration, value) {
19
- if (!isMemoryExtensionScalar(value))
20
- return false;
21
- if (declaration.type === 'enum')
22
- return typeof value === 'string' && declaration.values.includes(value);
23
- return typeof value === declaration.type;
24
- }
25
- /** Parse the closed declaration addendum. Callers that accept a plugin manifest
26
- * invoke this at their install/preflight boundary; normal runtime catalogs only
27
- * admit declarations which have already cleared that boundary. */
28
- export function validateMemoryExtensionDeclarations(raw) {
29
- if (!isRecord(raw))
30
- throw declarationError('memory_extensions', 'expected a non-empty object');
31
- const declarations = {};
32
- const fields = Object.entries(raw);
33
- if (fields.length === 0)
34
- throw declarationError('memory_extensions', 'must not be empty');
35
- for (const [field, value] of fields) {
36
- const path = `memory_extensions.${field}`;
37
- if (!LOCAL_FIELD_NAME.test(field)) {
38
- throw declarationError(path, 'field names must be lowercase kebab-case');
39
- }
40
- if (!isRecord(value))
41
- throw declarationError(path, 'expected a declaration object');
42
- for (const key of Object.keys(value)) {
43
- if (!DECLARATION_KEYS.has(key))
44
- throw declarationError(path, `unknown key \`${key}\``);
45
- }
46
- const type = value['type'];
47
- if (type !== 'boolean' && type !== 'string' && type !== 'number' && type !== 'enum') {
48
- throw declarationError(`${path}.type`, 'expected boolean, string, number, or enum');
49
- }
50
- if (!validHelp(value['write_help']))
51
- throw declarationError(`${path}.write_help`, 'expected a nonblank single-line string');
52
- if (!validHelp(value['edit_help']))
53
- throw declarationError(`${path}.edit_help`, 'expected a nonblank single-line string');
54
- if (type === 'enum') {
55
- const values = value['values'];
56
- if (!Array.isArray(values) || values.length === 0 || !values.every((entry) => typeof entry === 'string' && entry !== '')) {
57
- throw declarationError(`${path}.values`, 'expected a non-empty string list');
58
- }
59
- if (new Set(values).size !== values.length)
60
- throw declarationError(`${path}.values`, 'values must be unique');
61
- const declaration = {
62
- type,
63
- values: [...values],
64
- write_help: value['write_help'],
65
- edit_help: value['edit_help'],
66
- };
67
- if ('default' in value) {
68
- if (!validDefault(declaration, value['default'])) {
69
- throw declarationError(`${path}.default`, 'must be one of the declared enum values');
70
- }
71
- declaration.default = value['default'];
72
- }
73
- declarations[field] = declaration;
74
- continue;
75
- }
76
- if ('values' in value)
77
- throw declarationError(`${path}.values`, 'is allowed only for enum declarations');
78
- const declaration = {
79
- type,
80
- write_help: value['write_help'],
81
- edit_help: value['edit_help'],
82
- };
83
- if ('default' in value) {
84
- if (!validDefault(declaration, value['default'])) {
85
- throw declarationError(`${path}.default`, `must be a ${type}`);
86
- }
87
- declaration.default = value['default'];
88
- }
89
- declarations[field] = declaration;
90
- }
91
- return declarations;
92
- }
93
9
  /** Throw when a manifest carries an invalid addendum; absent is valid. */
94
10
  export function validatePluginMemoryExtensions(manifest) {
95
11
  if (manifest.memory_extensions !== undefined)
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@north-light/api",
3
- "version": "0.3.788",
3
+ "version": "0.3.789",
4
4
  "description": "Typed crtrd /v1 API contract — DTOs, route builders, the error contract, the CrtrClient, and the command-plugin manifest format. Zero runtime dependencies.",
5
5
  "type": "module",
6
6
  "main": "./dist/api/index.js",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@north-light/identity",
3
- "version": "0.3.788",
3
+ "version": "0.3.789",
4
4
  "description": "Northlight access-token verification and scope rules",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -24,6 +24,7 @@ export async function buildBundle(plugin, options) {
24
24
  ...(plugin.version !== undefined ? { version: plugin.version } : {}),
25
25
  ...(plugin.groups !== undefined ? { groups: groupsBlock(plugin.groups) } : {}),
26
26
  ...(objectKinds !== undefined ? { object_kinds: objectKinds } : {}),
27
+ ...(plugin.memoryExtensions !== undefined ? { memory_extensions: plugin.memoryExtensions } : {}),
27
28
  })}\n`;
28
29
  const memory = buildMemoryMembers(plugin.memory);
29
30
  const members = [
@@ -1,4 +1,4 @@
1
- import { LOCAL, mentionsFile, objectBlocksShapeReasons, objectKindReadReasons, outputBaseType } from '@north-light/api/command-manifest';
1
+ import { LOCAL, mentionsFile, objectBlocksShapeReasons, validateMemoryExtensionDeclarations, objectKindReadReasons, outputBaseType } from '@north-light/api/command-manifest';
2
2
  /** Thrown by `definePlugin` when a declaration is malformed, before anything is served. */
3
3
  export class PluginDefinitionError extends Error {
4
4
  constructor(message) {
@@ -87,6 +87,14 @@ export function definePlugin(spec) {
87
87
  validateMemoryDoc(doc);
88
88
  if (spec.objectKinds !== undefined)
89
89
  validateObjectKinds(spec.objectKinds, spec.name, spec.commands);
90
+ if (spec.memoryExtensions !== undefined) {
91
+ try {
92
+ validateMemoryExtensionDeclarations(spec.memoryExtensions);
93
+ }
94
+ catch (error) {
95
+ throw new PluginDefinitionError(error instanceof Error ? error.message : String(error));
96
+ }
97
+ }
90
98
  return Object.freeze({
91
99
  name: spec.name,
92
100
  description: spec.description,
@@ -100,6 +108,7 @@ export function definePlugin(spec) {
100
108
  ...(spec.provider !== undefined ? { provider: spec.provider } : {}),
101
109
  ...(spec.objectKinds !== undefined ? { objectKinds: snapshotObjectKinds(spec.objectKinds) } : {}),
102
110
  ...(spec.groups !== undefined ? { groups: snapshotGroups(spec.groups) } : {}),
111
+ ...(spec.memoryExtensions !== undefined ? { memoryExtensions: structuredClone(spec.memoryExtensions) } : {}),
103
112
  });
104
113
  }
105
114
  /** Each declared group is well formed and every leaf names a declared group. A declared group no leaf uses is allowed: a provider that ships documents only declares one so a grant naming it installs the bundle. */
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@north-light/plugin",
3
- "version": "0.3.788",
3
+ "version": "0.3.789",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -27,8 +27,8 @@
27
27
  "postpack": "node ../../scripts/pack-minify.mjs postpack packages/crouter-plugin"
28
28
  },
29
29
  "dependencies": {
30
- "@north-light/api": "0.3.788",
31
- "@north-light/identity": "0.3.788"
30
+ "@north-light/api": "0.3.789",
31
+ "@north-light/identity": "0.3.789"
32
32
  },
33
33
  "license": "UNLICENSED",
34
34
  "publishConfig": {
package/runtime.lock.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@north-light/cli",
3
- "version": "0.3.788",
3
+ "version": "0.3.789",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@north-light/cli",
9
- "version": "0.3.788",
9
+ "version": "0.3.789",
10
10
  "hasInstallScript": true,
11
11
  "license": "UNLICENSED",
12
12
  "workspaces": [
@@ -28,8 +28,8 @@
28
28
  "@milkdown/preset-gfm": "^7.22.3",
29
29
  "@milkdown/prose": "^7.22.3",
30
30
  "@milkdown/utils": "^7.22.3",
31
- "@north-light/identity": "0.3.788",
32
- "@north-light/plugin": "0.3.788",
31
+ "@north-light/identity": "0.3.789",
32
+ "@north-light/plugin": "0.3.789",
33
33
  "cron-parser": "^5.6.0",
34
34
  "esbuild": "0.28.2",
35
35
  "jose": "^6.2.12",
@@ -11902,17 +11902,17 @@
11902
11902
  },
11903
11903
  "packages/crouter-api": {
11904
11904
  "name": "@north-light/api",
11905
- "version": "0.3.788",
11905
+ "version": "0.3.789",
11906
11906
  "license": "UNLICENSED"
11907
11907
  },
11908
11908
  "packages/crouter-env-docker": {
11909
11909
  "name": "@north-light/env-docker",
11910
- "version": "0.3.788",
11910
+ "version": "0.3.789",
11911
11911
  "license": "UNLICENSED"
11912
11912
  },
11913
11913
  "packages/crouter-identity": {
11914
11914
  "name": "@north-light/identity",
11915
- "version": "0.3.788",
11915
+ "version": "0.3.789",
11916
11916
  "license": "UNLICENSED",
11917
11917
  "dependencies": {
11918
11918
  "jose": "^6.2.1"
@@ -11920,21 +11920,21 @@
11920
11920
  },
11921
11921
  "packages/crouter-plugin": {
11922
11922
  "name": "@north-light/plugin",
11923
- "version": "0.3.788",
11923
+ "version": "0.3.789",
11924
11924
  "license": "UNLICENSED",
11925
11925
  "dependencies": {
11926
- "@north-light/api": "0.3.788",
11927
- "@north-light/identity": "0.3.788"
11926
+ "@north-light/api": "0.3.789",
11927
+ "@north-light/identity": "0.3.789"
11928
11928
  }
11929
11929
  },
11930
11930
  "packages/crouter-sdk": {
11931
11931
  "name": "@north-light/sdk",
11932
- "version": "0.3.788",
11932
+ "version": "0.3.789",
11933
11933
  "license": "UNLICENSED",
11934
11934
  "dependencies": {
11935
- "@north-light/api": "0.3.788",
11936
- "@north-light/identity": "0.3.788",
11937
- "@north-light/plugin": "0.3.788",
11935
+ "@north-light/api": "0.3.789",
11936
+ "@north-light/identity": "0.3.789",
11937
+ "@north-light/plugin": "0.3.789",
11938
11938
  "jose": "^6.2.1"
11939
11939
  },
11940
11940
  "bin": {