@inventarch/runtime 1.1.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LANGUAGE.md +2 -2
- package/README.md +1 -1
- package/SPEC.md +5 -1
- package/dist/door.d.ts.map +1 -1
- package/dist/door.js +11 -4
- package/dist/door.js.map +1 -1
- package/dist/editor/workspace.d.ts.map +1 -1
- package/dist/editor/workspace.js +6 -5
- package/dist/editor/workspace.js.map +1 -1
- package/dist/errors.d.ts +1 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +6 -0
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/locator.d.ts +129 -0
- package/dist/locator.d.ts.map +1 -0
- package/dist/locator.js +308 -0
- package/dist/locator.js.map +1 -0
- package/dist/mandate-modes.d.ts +60 -0
- package/dist/mandate-modes.d.ts.map +1 -0
- package/dist/mandate-modes.js +112 -0
- package/dist/mandate-modes.js.map +1 -0
- package/dist/mentions.d.ts.map +1 -1
- package/dist/mentions.js +2 -3
- package/dist/mentions.js.map +1 -1
- package/dist/render.d.ts +6 -0
- package/dist/render.d.ts.map +1 -1
- package/dist/render.js +13 -0
- package/dist/render.js.map +1 -1
- package/package.json +12 -4
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import type { Node } from '@inventarch/graph';
|
|
2
|
+
import type { ReadHandle } from '@inventarch/db';
|
|
3
|
+
import type { RuntimeCode } from './errors.js';
|
|
4
|
+
/**
|
|
5
|
+
* Locators and the body reader: position-and-projection §5's `ia read` and design row 23.
|
|
6
|
+
*
|
|
7
|
+
* A locator names one admitted record, or one part of it, in one of four forms:
|
|
8
|
+
* - `<identity>`: the record, by its canonical `system/kind/facet/name` identity;
|
|
9
|
+
* - `<identity>#<phase>/<Primitive>`: the text of the record's cells at that address, a playbook's step;
|
|
10
|
+
* - `<identity>#<REQ-ID>`: the text of one of the record's requirements;
|
|
11
|
+
* - `<path>:<line>`: the innermost admitted record whose source span holds that line of a workspace source.
|
|
12
|
+
*
|
|
13
|
+
* The body behind a record is the document its source locator names, when its word carries one (SOURCE_LOCATORS) and the
|
|
14
|
+
* record states it; otherwise the record's own body (`bodyOf`). A fragment reads the record, never its document: the
|
|
15
|
+
* text of its cells or of its requirement at the fragment. A body is text and the SHA-256 of its UTF-8 bytes, never a
|
|
16
|
+
* certification: the reader neither admits the document nor judges what it says (IM-43). Structure (sections, fields,
|
|
17
|
+
* relationships) is the inspector's and never a body.
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* The field whose text names each word's document body, as its schema declares it: `work.source` on every work word
|
|
21
|
+
* that states one, @spec, @plan, @milestone, @task and @decision (position-and-projection rows 2d and 23, widened by
|
|
22
|
+
* decision work-source-locator: all five schemas declare the one field, and a plan's records name their sections of
|
|
23
|
+
* its document with it), `reference.document` on @authoring-guide (row 2h) and `template.resource`, a @template's
|
|
24
|
+
* input. A record that states none reads its own body.
|
|
25
|
+
*/
|
|
26
|
+
export declare const SOURCE_LOCATORS: Readonly<Record<string, string>>;
|
|
27
|
+
export type Locator = {
|
|
28
|
+
readonly form: 'identity';
|
|
29
|
+
readonly identity: string;
|
|
30
|
+
} | {
|
|
31
|
+
readonly form: 'cell' | 'requirement';
|
|
32
|
+
readonly identity: string;
|
|
33
|
+
readonly fragment: string;
|
|
34
|
+
} | {
|
|
35
|
+
readonly form: 'line';
|
|
36
|
+
readonly path: string;
|
|
37
|
+
readonly line: number;
|
|
38
|
+
};
|
|
39
|
+
export type ReadCode = Extract<RuntimeCode, `IA-RUNTIME-READ-${string}`>;
|
|
40
|
+
/** The refusal codes a read can return; each is registered in RUNTIME_CODES. */
|
|
41
|
+
export declare const READ_CODES: readonly ReadCode[];
|
|
42
|
+
export interface ReadBodyOptions {
|
|
43
|
+
/**
|
|
44
|
+
* The host's reader of one workspace file, given its canonical workspace-relative path. The host holds the root
|
|
45
|
+
* boundary (R10): it returns the file's bytes, and throws for a path it does not admit (a link, a missing or irregular
|
|
46
|
+
* file), which the read reports as an unreachable locator.
|
|
47
|
+
*/
|
|
48
|
+
readonly read: (path: string) => Uint8Array;
|
|
49
|
+
/**
|
|
50
|
+
* The workspace directory each adopted mount is bound to, by the `.ia/adopted/<id>/<revision>` tree label its sources
|
|
51
|
+
* carry (db `adoptedBindings`). A label is no directory, so the document of a record in an adopted mount is read from
|
|
52
|
+
* the directory bound here, and refused as unreachable when none is.
|
|
53
|
+
*/
|
|
54
|
+
readonly mounts?: ReadonlyMap<string, string>;
|
|
55
|
+
/** Read a record at runtime placement (band 0), which is refused otherwise. */
|
|
56
|
+
readonly includeRuntime?: boolean;
|
|
57
|
+
}
|
|
58
|
+
export interface ReadBody {
|
|
59
|
+
/** The locator as given. */
|
|
60
|
+
readonly locator: string;
|
|
61
|
+
readonly identity: string;
|
|
62
|
+
/** `record` for the record's own body or one of its fragments, `document` for the file its source locator names. */
|
|
63
|
+
readonly kind: 'record' | 'document';
|
|
64
|
+
/** A document's canonical workspace-relative path. */
|
|
65
|
+
readonly path?: string;
|
|
66
|
+
/** The SHA-256 of the body's UTF-8 bytes, in hex. */
|
|
67
|
+
readonly digest: string;
|
|
68
|
+
readonly body: string;
|
|
69
|
+
/** A read returns bytes and a digest, never a certification. */
|
|
70
|
+
readonly certified: false;
|
|
71
|
+
}
|
|
72
|
+
export interface ReadRefusal {
|
|
73
|
+
readonly ok: false;
|
|
74
|
+
readonly code: ReadCode;
|
|
75
|
+
readonly message: string;
|
|
76
|
+
/** The record the locator reached, once it reached one. */
|
|
77
|
+
readonly identity?: string;
|
|
78
|
+
/**
|
|
79
|
+
* The workspace path the refusal concerns: a line locator's source, the source of a record whose fragment is missing
|
|
80
|
+
* or whose placement is refused (with its line), or the file a source locator names.
|
|
81
|
+
*/
|
|
82
|
+
readonly path?: string;
|
|
83
|
+
readonly line?: number;
|
|
84
|
+
/**
|
|
85
|
+
* For a line no admitted record spans, what the workspace's sources hold in its file: `refused` when admission
|
|
86
|
+
* refused records there, else `admitted` when admitted records there span other lines. Absent when no record of the
|
|
87
|
+
* workspace's sources is in that file. For an identity, `refused` when a source holds it and admission refused it.
|
|
88
|
+
*/
|
|
89
|
+
readonly file?: 'admitted' | 'refused';
|
|
90
|
+
}
|
|
91
|
+
export type ReadResult = {
|
|
92
|
+
readonly ok: true;
|
|
93
|
+
readonly body: ReadBody;
|
|
94
|
+
} | ReadRefusal;
|
|
95
|
+
/** The locator `text` spells, or undefined when it spells none of the four forms. */
|
|
96
|
+
export declare function parseLocator(text: string): Locator | undefined;
|
|
97
|
+
/**
|
|
98
|
+
* The text at `fragment` of `node`: its cells at a `phase/Primitive` address in source order, else its requirement with
|
|
99
|
+
* that id. Undefined when the record has neither, which is also what a request mention's fragment is checked against.
|
|
100
|
+
*/
|
|
101
|
+
export declare function fragmentText(node: Node, fragment: string): string | undefined;
|
|
102
|
+
/**
|
|
103
|
+
* The anchor of one plain-text ATX heading, as GitHub's slugger gives it: an inline link keeps its text, letters are
|
|
104
|
+
* lowercased, every character other than a letter, mark, decimal or letter number, connector punctuation, `-` or space
|
|
105
|
+
* is dropped, and each space becomes `-`. Code spans and `*` emphasis come out as GitHub's, because their delimiters
|
|
106
|
+
* are dropped. The heading is not rendered first, so underscore emphasis, entity and character references, inline HTML
|
|
107
|
+
* and reference links keep their markup here, and such a heading may have another anchor on GitHub.
|
|
108
|
+
*/
|
|
109
|
+
export declare function headingAnchor(heading: string): string;
|
|
110
|
+
/**
|
|
111
|
+
* The section of markdown `text` under the ATX heading whose `headingAnchor` is `anchor`: from that heading to the next
|
|
112
|
+
* heading of the same or a higher level, headings in fenced code ignored. A repeated anchor takes GitHub's `-1`, `-2`,
|
|
113
|
+
* ... in document order. A leading byte order mark is not part of the first line's heading, as GitHub skips it, and
|
|
114
|
+
* stays in the section. Setext headings and headings inside list items or block quotes are not read. Undefined when no
|
|
115
|
+
* heading has the anchor.
|
|
116
|
+
*/
|
|
117
|
+
export declare function markdownSection(text: string, anchor: string): string | undefined;
|
|
118
|
+
/**
|
|
119
|
+
* The body behind `locator` in the root view of `handle`, or one refusal: IA-RUNTIME-READ-UNADMITTED when no admitted
|
|
120
|
+
* record answers it, IA-RUNTIME-READ-PLACEMENT for a record at runtime placement unless `includeRuntime` is set,
|
|
121
|
+
* IA-RUNTIME-READ-FRAGMENT when the record has no cell or requirement at the fragment, and IA-RUNTIME-READ-UNREACHABLE
|
|
122
|
+
* when its source locator names a file outside the workspace (or the record's tree), a record of an adopted mount
|
|
123
|
+
* `mounts` binds to no directory, a file the host's reader does not return, bytes that are not UTF-8, or an anchor that
|
|
124
|
+
* no markdown heading of the file has. A locator that spells none of the four forms is IA-RUNTIME-REQUEST-INVALID.
|
|
125
|
+
* A document path is read relative to the record's tree (db `sourceTree`): the workspace root for its own `.ia/src`,
|
|
126
|
+
* a package or installed store directory as it is, and for an adopted mount the directory `mounts` binds its label to.
|
|
127
|
+
*/
|
|
128
|
+
export declare function readBody(handle: ReadHandle, locator: string, options: ReadBodyOptions): ReadResult;
|
|
129
|
+
//# sourceMappingURL=locator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"locator.d.ts","sourceRoot":"","sources":["../src/locator.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAE9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEjD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAI/C;;;;;;;;;;;;;;GAcG;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAQ3D,CAAC;AAEH,MAAM,MAAM,OAAO,GACf;IAAE,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAA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,EAAE,KAAK,CAAC;IACnB,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,2DAA2D;IAC3D,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B;;;OAGG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB;;;;OAIG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,UAAU,GAAG,SAAS,CAAC;CACxC;AACD,MAAM,MAAM,UAAU,GAAG;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAA;CAAE,GAAG,WAAW,CAAC;AAItF,qFAAqF;AACrF,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAe9D;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAM7E;AA0CD;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAKrD;AACD;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAuChF;AAiBD;;;;;;;;;GASG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe,GAAG,UAAU,CAkIlG"}
|
package/dist/locator.js
ADDED
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { isPhase, isPrimitive, isRequirementId } from '@inventarch/language';
|
|
3
|
+
import { canonicalRoot } from '@inventarch/graph';
|
|
4
|
+
import { sourceTree } from '@inventarch/db';
|
|
5
|
+
import { RUNTIME_CODES, RuntimeError } from './errors.js';
|
|
6
|
+
import { bodyOf } from './render.js';
|
|
7
|
+
import { freeze } from './types.js';
|
|
8
|
+
/**
|
|
9
|
+
* Locators and the body reader: position-and-projection §5's `ia read` and design row 23.
|
|
10
|
+
*
|
|
11
|
+
* A locator names one admitted record, or one part of it, in one of four forms:
|
|
12
|
+
* - `<identity>`: the record, by its canonical `system/kind/facet/name` identity;
|
|
13
|
+
* - `<identity>#<phase>/<Primitive>`: the text of the record's cells at that address, a playbook's step;
|
|
14
|
+
* - `<identity>#<REQ-ID>`: the text of one of the record's requirements;
|
|
15
|
+
* - `<path>:<line>`: the innermost admitted record whose source span holds that line of a workspace source.
|
|
16
|
+
*
|
|
17
|
+
* The body behind a record is the document its source locator names, when its word carries one (SOURCE_LOCATORS) and the
|
|
18
|
+
* record states it; otherwise the record's own body (`bodyOf`). A fragment reads the record, never its document: the
|
|
19
|
+
* text of its cells or of its requirement at the fragment. A body is text and the SHA-256 of its UTF-8 bytes, never a
|
|
20
|
+
* certification: the reader neither admits the document nor judges what it says (IM-43). Structure (sections, fields,
|
|
21
|
+
* relationships) is the inspector's and never a body.
|
|
22
|
+
*/
|
|
23
|
+
/**
|
|
24
|
+
* The field whose text names each word's document body, as its schema declares it: `work.source` on every work word
|
|
25
|
+
* that states one, @spec, @plan, @milestone, @task and @decision (position-and-projection rows 2d and 23, widened by
|
|
26
|
+
* decision work-source-locator: all five schemas declare the one field, and a plan's records name their sections of
|
|
27
|
+
* its document with it), `reference.document` on @authoring-guide (row 2h) and `template.resource`, a @template's
|
|
28
|
+
* input. A record that states none reads its own body.
|
|
29
|
+
*/
|
|
30
|
+
export const SOURCE_LOCATORS = Object.freeze({
|
|
31
|
+
'authoring-guide': 'reference.document',
|
|
32
|
+
decision: 'work.source',
|
|
33
|
+
milestone: 'work.source',
|
|
34
|
+
plan: 'work.source',
|
|
35
|
+
spec: 'work.source',
|
|
36
|
+
task: 'work.source',
|
|
37
|
+
template: 'template.resource',
|
|
38
|
+
});
|
|
39
|
+
/** The refusal codes a read can return; each is registered in RUNTIME_CODES. */
|
|
40
|
+
export const READ_CODES = Object.freeze(RUNTIME_CODES.filter((code) => code.startsWith('IA-RUNTIME-READ-')));
|
|
41
|
+
const IDENTITY = /^[a-z][a-z0-9-]*\/[a-z][a-z0-9-]*\/[a-z][a-z0-9-]*\/[a-z][a-z0-9-]*$/;
|
|
42
|
+
const LINE = /^(.+):([1-9][0-9]*)$/;
|
|
43
|
+
/** The locator `text` spells, or undefined when it spells none of the four forms. */
|
|
44
|
+
export function parseLocator(text) {
|
|
45
|
+
const line = LINE.exec(text);
|
|
46
|
+
if (line !== null) {
|
|
47
|
+
const number = Number(line[2]);
|
|
48
|
+
return Number.isSafeInteger(number) ? freeze({ form: 'line', path: line[1], line: number }) : undefined;
|
|
49
|
+
}
|
|
50
|
+
const at = text.indexOf('#'), identity = at < 0 ? text : text.slice(0, at);
|
|
51
|
+
if (!IDENTITY.test(identity))
|
|
52
|
+
return undefined;
|
|
53
|
+
if (at < 0)
|
|
54
|
+
return freeze({ form: 'identity', identity });
|
|
55
|
+
const fragment = text.slice(at + 1), [phase, primitive, ...rest] = fragment.split('/');
|
|
56
|
+
if (phase !== undefined && primitive !== undefined && rest.length === 0 && isPhase(phase) && isPrimitive(primitive))
|
|
57
|
+
return freeze({ form: 'cell', identity, fragment });
|
|
58
|
+
return isRequirementId(fragment) ? freeze({ form: 'requirement', identity, fragment }) : undefined;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* The text at `fragment` of `node`: its cells at a `phase/Primitive` address in source order, else its requirement with
|
|
62
|
+
* that id. Undefined when the record has neither, which is also what a request mention's fragment is checked against.
|
|
63
|
+
*/
|
|
64
|
+
export function fragmentText(node, fragment) {
|
|
65
|
+
const parts = [
|
|
66
|
+
...node.cells.filter((cell) => `${cell.phase}/${cell.primitive}` === fragment).map((cell) => cell.text),
|
|
67
|
+
...node.requirements.filter((requirement) => requirement.id === fragment).map((requirement) => requirement.text),
|
|
68
|
+
];
|
|
69
|
+
return parts.length === 0 ? undefined : parts.join('\n');
|
|
70
|
+
}
|
|
71
|
+
const HEADING = /^ {0,3}(#{1,6})(?:[ \t]+(.*?))?(?:[ \t]+#+)?[ \t]*$/;
|
|
72
|
+
const FENCE = /^ {0,3}(`{3,}|~{3,})/;
|
|
73
|
+
/**
|
|
74
|
+
* The first index of `character` in `text` at or after a position, asked for positions that never decrease, as one
|
|
75
|
+
* scan: a position past the last found is searched from there, and every other answer is the one already found.
|
|
76
|
+
*/
|
|
77
|
+
function scanner(text, character) {
|
|
78
|
+
let searched = 0, found = text.indexOf(character);
|
|
79
|
+
return (from) => {
|
|
80
|
+
if (from < searched || (found >= 0 && found < from))
|
|
81
|
+
found = text.indexOf(character, (searched = from));
|
|
82
|
+
return found;
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* `heading` with each inline link or image, `[text](destination)` or ``, replaced by its text:
|
|
87
|
+
* the text runs to the first `]`, which `(` must follow, and the destination to the first `)` after it. Each `]` and
|
|
88
|
+
* `)` is found once, by scanners that only move forward, so the time is linear however many brackets stay unclosed.
|
|
89
|
+
*/
|
|
90
|
+
function linkText(heading) {
|
|
91
|
+
const close = scanner(heading, ']'), paren = scanner(heading, ')'), parts = [];
|
|
92
|
+
let kept = 0, open = heading.indexOf('[');
|
|
93
|
+
while (open >= 0) {
|
|
94
|
+
const shut = close(open + 1), end = shut < 0 || heading[shut + 1] !== '(' ? -1 : paren(shut + 2);
|
|
95
|
+
if (end < 0)
|
|
96
|
+
open = heading.indexOf('[', open + 1);
|
|
97
|
+
else {
|
|
98
|
+
// An image's `!` belongs to the link when it follows the previous link.
|
|
99
|
+
parts.push(heading.slice(kept, open > kept && heading[open - 1] === '!' ? open - 1 : open));
|
|
100
|
+
parts.push(heading.slice(open + 1, shut));
|
|
101
|
+
kept = end + 1;
|
|
102
|
+
open = heading.indexOf('[', kept);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
parts.push(heading.slice(kept));
|
|
106
|
+
return parts.join('');
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* The anchor of one plain-text ATX heading, as GitHub's slugger gives it: an inline link keeps its text, letters are
|
|
110
|
+
* lowercased, every character other than a letter, mark, decimal or letter number, connector punctuation, `-` or space
|
|
111
|
+
* is dropped, and each space becomes `-`. Code spans and `*` emphasis come out as GitHub's, because their delimiters
|
|
112
|
+
* are dropped. The heading is not rendered first, so underscore emphasis, entity and character references, inline HTML
|
|
113
|
+
* and reference links keep their markup here, and such a heading may have another anchor on GitHub.
|
|
114
|
+
*/
|
|
115
|
+
export function headingAnchor(heading) {
|
|
116
|
+
return linkText(heading)
|
|
117
|
+
.toLowerCase()
|
|
118
|
+
.replace(/[^\p{L}\p{M}\p{Nd}\p{Nl}\p{Pc} -]/gu, '')
|
|
119
|
+
.replaceAll(' ', '-');
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* The section of markdown `text` under the ATX heading whose `headingAnchor` is `anchor`: from that heading to the next
|
|
123
|
+
* heading of the same or a higher level, headings in fenced code ignored. A repeated anchor takes GitHub's `-1`, `-2`,
|
|
124
|
+
* ... in document order. A leading byte order mark is not part of the first line's heading, as GitHub skips it, and
|
|
125
|
+
* stays in the section. Setext headings and headings inside list items or block quotes are not read. Undefined when no
|
|
126
|
+
* heading has the anchor.
|
|
127
|
+
*/
|
|
128
|
+
export function markdownSection(text, anchor) {
|
|
129
|
+
const lines = text.split(/(?<=\n)/), occurrences = new Map();
|
|
130
|
+
const unique = (base) => {
|
|
131
|
+
let result = base;
|
|
132
|
+
while (occurrences.has(result)) {
|
|
133
|
+
const count = occurrences.get(base) + 1;
|
|
134
|
+
occurrences.set(base, count);
|
|
135
|
+
result = `${base}-${count}`;
|
|
136
|
+
}
|
|
137
|
+
occurrences.set(result, 0);
|
|
138
|
+
return result;
|
|
139
|
+
};
|
|
140
|
+
let fence, start, level = 0;
|
|
141
|
+
for (const [index, raw] of lines.entries()) {
|
|
142
|
+
const line = (index === 0 ? raw.replace(/^\uFEFF/, '') : raw).replace(/\r?\n$/, ''), marker = FENCE.exec(line)?.[1];
|
|
143
|
+
if (fence !== undefined) {
|
|
144
|
+
if (marker !== undefined && marker[0] === fence[0] && marker.length >= fence.length && line.trim() === marker)
|
|
145
|
+
fence = undefined;
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
if (marker !== undefined) {
|
|
149
|
+
fence = marker;
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
const heading = HEADING.exec(line);
|
|
153
|
+
if (heading === null)
|
|
154
|
+
continue;
|
|
155
|
+
const depth = heading[1].length;
|
|
156
|
+
if (start !== undefined) {
|
|
157
|
+
if (depth <= level)
|
|
158
|
+
return lines.slice(start, index).join('');
|
|
159
|
+
}
|
|
160
|
+
else if (unique(headingAnchor(heading[2] ?? '')) === anchor) {
|
|
161
|
+
start = index;
|
|
162
|
+
level = depth;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return start === undefined ? undefined : lines.slice(start).join('');
|
|
166
|
+
}
|
|
167
|
+
/** The record's source locator: the field its word names in SOURCE_LOCATORS, when the record states it unconditionally. */
|
|
168
|
+
function sourceOf(node) {
|
|
169
|
+
const field = SOURCE_LOCATORS[node.discriminator];
|
|
170
|
+
if (field === undefined)
|
|
171
|
+
return undefined;
|
|
172
|
+
const [section, key] = field.split('.');
|
|
173
|
+
const stated = node.sections
|
|
174
|
+
.filter((s) => s.name === section)
|
|
175
|
+
.flatMap((s) => s.fields)
|
|
176
|
+
.find((f) => 'key' in f && f.key === key && f.when === undefined && 'text' in f.value);
|
|
177
|
+
return stated === undefined || !('text' in stated.value) ? undefined : { field, value: stated.value.text };
|
|
178
|
+
}
|
|
179
|
+
const sha256 = (text) => createHash('sha256').update(text, 'utf8').digest('hex');
|
|
180
|
+
const refuse = (code, message, where) => freeze({ ok: false, code, message, ...where });
|
|
181
|
+
/**
|
|
182
|
+
* The body behind `locator` in the root view of `handle`, or one refusal: IA-RUNTIME-READ-UNADMITTED when no admitted
|
|
183
|
+
* record answers it, IA-RUNTIME-READ-PLACEMENT for a record at runtime placement unless `includeRuntime` is set,
|
|
184
|
+
* IA-RUNTIME-READ-FRAGMENT when the record has no cell or requirement at the fragment, and IA-RUNTIME-READ-UNREACHABLE
|
|
185
|
+
* when its source locator names a file outside the workspace (or the record's tree), a record of an adopted mount
|
|
186
|
+
* `mounts` binds to no directory, a file the host's reader does not return, bytes that are not UTF-8, or an anchor that
|
|
187
|
+
* no markdown heading of the file has. A locator that spells none of the four forms is IA-RUNTIME-REQUEST-INVALID.
|
|
188
|
+
* A document path is read relative to the record's tree (db `sourceTree`): the workspace root for its own `.ia/src`,
|
|
189
|
+
* a package or installed store directory as it is, and for an adopted mount the directory `mounts` binds its label to.
|
|
190
|
+
*/
|
|
191
|
+
export function readBody(handle, locator, options) {
|
|
192
|
+
const parsed = parseLocator(locator);
|
|
193
|
+
if (parsed === undefined)
|
|
194
|
+
throw new RuntimeError('IA-RUNTIME-REQUEST-INVALID', `Locator '${locator}' is not <identity>, <identity>#<phase>/<Primitive>, <identity>#<REQ-ID> or <path>:<line>`);
|
|
195
|
+
let node;
|
|
196
|
+
if (parsed.form === 'line') {
|
|
197
|
+
let path;
|
|
198
|
+
try {
|
|
199
|
+
path = canonicalRoot(parsed.path);
|
|
200
|
+
}
|
|
201
|
+
catch {
|
|
202
|
+
path = undefined;
|
|
203
|
+
}
|
|
204
|
+
node = handle
|
|
205
|
+
.records()
|
|
206
|
+
.filter((r) => r.source.path === path && r.source.line <= parsed.line && parsed.line <= r.source.endLine)
|
|
207
|
+
.sort((a, b) => a.source.endLine - a.source.line - (b.source.endLine - b.source.line))[0];
|
|
208
|
+
if (node === undefined) {
|
|
209
|
+
const at = path ?? parsed.path, file = handle.refused.some((r) => r.path === path)
|
|
210
|
+
? 'refused'
|
|
211
|
+
: handle.records().some((r) => r.source.path === path)
|
|
212
|
+
? 'admitted'
|
|
213
|
+
: undefined;
|
|
214
|
+
return refuse('IA-RUNTIME-READ-UNADMITTED', `No admitted record spans ${parsed.path}:${parsed.line}; ${file === 'refused'
|
|
215
|
+
? `admission refused records of ${at}`
|
|
216
|
+
: file === 'admitted'
|
|
217
|
+
? `the admitted records of ${at} span other lines`
|
|
218
|
+
: path === undefined
|
|
219
|
+
? `${parsed.path} is not a path relative to the workspace root`
|
|
220
|
+
: `no record of this workspace's sources is in ${at}`}`, { path: at, line: parsed.line, ...(file === undefined ? {} : { file }) });
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
node = handle.get(parsed.identity);
|
|
225
|
+
// A source holding the identity whose record admission refused is in the workspace's sources; only an identity no
|
|
226
|
+
// source holds is not.
|
|
227
|
+
const refused = node === undefined ? handle.refused.find((r) => r.identity === parsed.identity) : undefined;
|
|
228
|
+
if (refused !== undefined)
|
|
229
|
+
return refuse('IA-RUNTIME-READ-UNADMITTED', `${parsed.identity} is in this workspace's sources, but admission refused it`, { identity: parsed.identity, path: refused.path, line: refused.line, file: 'refused' });
|
|
230
|
+
if (node === undefined)
|
|
231
|
+
return refuse('IA-RUNTIME-READ-UNADMITTED', `${parsed.identity} is not in this workspace's sources`, {
|
|
232
|
+
identity: parsed.identity,
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
const { identity } = node;
|
|
236
|
+
if (node.placement.kind === 'runtime' && options.includeRuntime !== true)
|
|
237
|
+
return refuse('IA-RUNTIME-READ-PLACEMENT', `${identity} is at runtime placement (band 0), which a read includes only when asked to`, { identity, path: node.source.path, line: node.source.line });
|
|
238
|
+
const found = (kind, body, path) => freeze({
|
|
239
|
+
ok: true,
|
|
240
|
+
body: {
|
|
241
|
+
locator,
|
|
242
|
+
identity,
|
|
243
|
+
kind,
|
|
244
|
+
...(path === undefined ? {} : { path }),
|
|
245
|
+
digest: sha256(body),
|
|
246
|
+
body,
|
|
247
|
+
certified: false,
|
|
248
|
+
},
|
|
249
|
+
});
|
|
250
|
+
if (parsed.form === 'cell' || parsed.form === 'requirement') {
|
|
251
|
+
const body = fragmentText(node, parsed.fragment);
|
|
252
|
+
return body === undefined
|
|
253
|
+
? refuse('IA-RUNTIME-READ-FRAGMENT', `${identity} has no ${parsed.form} ${parsed.fragment}`, {
|
|
254
|
+
identity,
|
|
255
|
+
path: node.source.path,
|
|
256
|
+
line: node.source.line,
|
|
257
|
+
})
|
|
258
|
+
: found('record', body);
|
|
259
|
+
}
|
|
260
|
+
const source = sourceOf(node);
|
|
261
|
+
if (source === undefined)
|
|
262
|
+
return found('record', bodyOf(node));
|
|
263
|
+
const { field, value } = source, at = value.indexOf('#'), file = at < 0 ? value : value.slice(0, at), anchor = at < 0 ? undefined : value.slice(at + 1);
|
|
264
|
+
const unreachable = (reason, path) => refuse('IA-RUNTIME-READ-UNREACHABLE', `The ${field} of ${identity}, ${value}, ${reason}`, {
|
|
265
|
+
identity,
|
|
266
|
+
...(path === undefined ? {} : { path }),
|
|
267
|
+
});
|
|
268
|
+
// A scheme names a resource a read never fetches; it is no workspace path, so it is not canonicalized into one.
|
|
269
|
+
if (/^[A-Za-z][A-Za-z0-9+.-]+:/.test(file))
|
|
270
|
+
return unreachable('is a URL, and a read fetches nothing');
|
|
271
|
+
let relative;
|
|
272
|
+
try {
|
|
273
|
+
relative = canonicalRoot(file);
|
|
274
|
+
}
|
|
275
|
+
catch {
|
|
276
|
+
return unreachable('is outside the workspace');
|
|
277
|
+
}
|
|
278
|
+
if (relative === '')
|
|
279
|
+
return unreachable('names no file');
|
|
280
|
+
// An adopted mount's sources carry the label of its tree, so its documents are read from the directory bound to it;
|
|
281
|
+
// they are outside the mount's revision pin, which covers its `.ia/src` sources only.
|
|
282
|
+
const tree = sourceTree(node.source.path), directory = tree.startsWith('.ia/adopted/') ? options.mounts?.get(tree) : tree;
|
|
283
|
+
if (directory === undefined)
|
|
284
|
+
return unreachable(`is in adopted mount ${tree}, which the read binds to no directory`);
|
|
285
|
+
const path = directory === '' ? relative : `${directory}/${relative}`;
|
|
286
|
+
let bytes, content;
|
|
287
|
+
try {
|
|
288
|
+
bytes = options.read(path);
|
|
289
|
+
}
|
|
290
|
+
catch (error) {
|
|
291
|
+
return unreachable(`cannot be read: ${error instanceof Error ? error.message : String(error)}`, path);
|
|
292
|
+
}
|
|
293
|
+
try {
|
|
294
|
+
content = new TextDecoder('utf-8', { fatal: true, ignoreBOM: true }).decode(bytes);
|
|
295
|
+
}
|
|
296
|
+
catch {
|
|
297
|
+
return unreachable('is not UTF-8 text', path);
|
|
298
|
+
}
|
|
299
|
+
if (anchor === undefined)
|
|
300
|
+
return found('document', content, path);
|
|
301
|
+
if (!/\.(?:md|markdown)$/i.test(relative))
|
|
302
|
+
return unreachable('has an anchor, but only a markdown file has headings to select', path);
|
|
303
|
+
const section = markdownSection(content, anchor);
|
|
304
|
+
return section === undefined
|
|
305
|
+
? unreachable(`selects heading #${anchor}, which ${path} does not have`, path)
|
|
306
|
+
: found('document', section, path);
|
|
307
|
+
}
|
|
308
|
+
//# sourceMappingURL=locator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"locator.js","sourceRoot":"","sources":["../src/locator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAE7E,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE1D,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEpC;;;;;;;;;;;;;;GAcG;AAEH;;;;;;GAMG;AACH,MAAM,CAAC,M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EAAE,CAAC;IACtE,IAAI,KAAiB,EAAE,OAAe,CAAC;IACvC,IAAI,CAAC;QACH,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,WAAW,CAAC,mBAAmB,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;IACxG,CAAC;IACD,IAAI,CAAC;QACH,OAAO,GAAG,IAAI,WAAW,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACrF,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,WAAW,CAAC,mBAAmB,EAAE,IAAI,CAAC,CAAC;IAChD,CAAC;IACD,IAAI,MAAM,KAAK,SAAS;QAAE,OAAO,KAAK,CAAC,UAAU,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;IAClE,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,QAAQ,CAAC;QACvC,OAAO,WAAW,CAAC,gEAAgE,EAAE,IAAI,CAAC,CAAC;IAC7F,MAAM,OAAO,GAAG,eAAe,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IACjD,OAAO,OAAO,KAAK,SAAS;QAC1B,CAAC,CAAC,WAAW,CAAC,oBAAoB,MAAM,WAAW,IAAI,gBAAgB,EAAE,IAAI,CAAC;QAC9E,CAAC,CAAC,KAAK,CAAC,UAAU,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;AACvC,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { CompiledRecord } from '@inventarch/language';
|
|
2
|
+
import type { RuntimeCode } from './errors.js';
|
|
3
|
+
/**
|
|
4
|
+
* Mandate authority as closed moves (position-and-projection design, items 2c and 13).
|
|
5
|
+
*
|
|
6
|
+
* A `@mandate` may declare an `authority` section: the participant it binds, the moves it allows (closed to the five
|
|
7
|
+
* kernel moves), the workspaces it scopes, and the words and path selections it excludes or covers. This module
|
|
8
|
+
* publishes the CLI mode -> move table and the pure refusal check that the authoring verbs will consume. Nothing here
|
|
9
|
+
* is wired into the CLI yet: the authoring verbs land in a later milestone, and until then no command consults a
|
|
10
|
+
* mandate. A mandate adds closed restrictions only; it never grants host permissions, and a mandate without
|
|
11
|
+
* `authority.moves` restricts no move.
|
|
12
|
+
*/
|
|
13
|
+
/** The five kernel moves, in kernel order. */
|
|
14
|
+
export declare const MOVES: readonly ["Observation", "Execution", "Delegation", "Synthesis", "Verification"];
|
|
15
|
+
export type Move = (typeof MOVES)[number];
|
|
16
|
+
/** One kernel move per CLI mode (design item 13). */
|
|
17
|
+
export declare const MODE_MOVES: Readonly<{
|
|
18
|
+
readonly read: "Observation";
|
|
19
|
+
readonly validate: "Verification";
|
|
20
|
+
readonly author: "Synthesis";
|
|
21
|
+
readonly effect: "Execution";
|
|
22
|
+
readonly 're-seat': "Delegation";
|
|
23
|
+
}>;
|
|
24
|
+
export type Mode = keyof typeof MODE_MOVES;
|
|
25
|
+
/** The modes in table order. */
|
|
26
|
+
export declare const MODES: readonly Mode[];
|
|
27
|
+
export declare function isMode(value: unknown): value is Mode;
|
|
28
|
+
export type MandateCode = Extract<RuntimeCode, `IA-RUNTIME-MANDATE-${string}`>;
|
|
29
|
+
/** The refusal codes a mandate can return; both are registered in RUNTIME_CODES. */
|
|
30
|
+
export declare const MANDATE_CODES: readonly MandateCode[];
|
|
31
|
+
/** The `authority` section of one compiled `@mandate`; an absent field is an absent restriction. */
|
|
32
|
+
export interface MandateAuthority {
|
|
33
|
+
readonly identity: string;
|
|
34
|
+
/** The name of the `@agent` the mandate binds (`authority.participant`). */
|
|
35
|
+
readonly participant?: string;
|
|
36
|
+
/** The moves the mandate allows (`authority.moves`); absent, it allows every move. */
|
|
37
|
+
readonly moves?: readonly Move[];
|
|
38
|
+
/** Words the participant may not author (`authority.excluded-words`). */
|
|
39
|
+
readonly excludedWords?: readonly string[];
|
|
40
|
+
/** The names of the `@workspace` records the mandate applies in (`authority.scope`). */
|
|
41
|
+
readonly scope?: readonly string[];
|
|
42
|
+
/** Path selections the mandate claims (`authority.covers`). */
|
|
43
|
+
readonly covers?: readonly string[];
|
|
44
|
+
}
|
|
45
|
+
export interface MandateRefusal {
|
|
46
|
+
readonly code: MandateCode;
|
|
47
|
+
readonly message: string;
|
|
48
|
+
/** Exactly one catalog command with closed arguments. */
|
|
49
|
+
readonly next: string;
|
|
50
|
+
}
|
|
51
|
+
/** Read the authority a compiled `@mandate` declares; a non-mandate or a malformed field is IA-RUNTIME-REQUEST-INVALID. */
|
|
52
|
+
export declare function mandateAuthorityOf(record: CompiledRecord): MandateAuthority;
|
|
53
|
+
/**
|
|
54
|
+
* Undefined when the mandate permits `mode` for `words`, else one refusal. The move is judged first: a declared move
|
|
55
|
+
* list admits only the moves it lists and must name at least one (an empty list is IA-RUNTIME-REQUEST-INVALID); a
|
|
56
|
+
* mandate without moves restricts no move. Then any word in `excluded-words` is refused, whatever the moves. `next`
|
|
57
|
+
* names the one catalog command that shows the mandate.
|
|
58
|
+
*/
|
|
59
|
+
export declare function mandateRefusal(mandate: MandateAuthority | CompiledRecord, mode: Mode, words?: readonly string[]): MandateRefusal | undefined;
|
|
60
|
+
//# sourceMappingURL=mandate-modes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mandate-modes.d.ts","sourceRoot":"","sources":["../src/mandate-modes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAiB,cAAc,EAAiB,MAAM,sBAAsB,CAAC;AAGzF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C;;;;;;;;;GASG;AAEH,8CAA8C;AAC9C,eAAO,MAAM,KAAK,kFAAe,CAAC;AAClC,MAAM,MAAM,IAAI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c,CAC5B,OAAO,EAAE,gBAAgB,GAAG,cAAc,EAC1C,IAAI,EAAE,IAAI,EACV,KAAK,GAAE,SAAS,MAAM,EAAO,GAC5B,cAAc,GAAG,SAAS,CAqB5B"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { MOVES as KERNEL_MOVES } from '@inventarch/language';
|
|
2
|
+
import { RUNTIME_CODES, RuntimeError } from './errors.js';
|
|
3
|
+
/**
|
|
4
|
+
* Mandate authority as closed moves (position-and-projection design, items 2c and 13).
|
|
5
|
+
*
|
|
6
|
+
* A `@mandate` may declare an `authority` section: the participant it binds, the moves it allows (closed to the five
|
|
7
|
+
* kernel moves), the workspaces it scopes, and the words and path selections it excludes or covers. This module
|
|
8
|
+
* publishes the CLI mode -> move table and the pure refusal check that the authoring verbs will consume. Nothing here
|
|
9
|
+
* is wired into the CLI yet: the authoring verbs land in a later milestone, and until then no command consults a
|
|
10
|
+
* mandate. A mandate adds closed restrictions only; it never grants host permissions, and a mandate without
|
|
11
|
+
* `authority.moves` restricts no move.
|
|
12
|
+
*/
|
|
13
|
+
/** The five kernel moves, in kernel order. */
|
|
14
|
+
export const MOVES = KERNEL_MOVES;
|
|
15
|
+
/** One kernel move per CLI mode (design item 13). */
|
|
16
|
+
export const MODE_MOVES = Object.freeze({
|
|
17
|
+
read: 'Observation',
|
|
18
|
+
validate: 'Verification',
|
|
19
|
+
author: 'Synthesis',
|
|
20
|
+
effect: 'Execution',
|
|
21
|
+
're-seat': 'Delegation',
|
|
22
|
+
});
|
|
23
|
+
/** The modes in table order. */
|
|
24
|
+
export const MODES = Object.freeze(Object.keys(MODE_MOVES));
|
|
25
|
+
export function isMode(value) {
|
|
26
|
+
return typeof value === 'string' && Object.hasOwn(MODE_MOVES, value);
|
|
27
|
+
}
|
|
28
|
+
/** The refusal codes a mandate can return; both are registered in RUNTIME_CODES. */
|
|
29
|
+
export const MANDATE_CODES = Object.freeze(RUNTIME_CODES.filter((code) => code.startsWith('IA-RUNTIME-MANDATE-')));
|
|
30
|
+
const invalid = (message) => {
|
|
31
|
+
throw new RuntimeError('IA-RUNTIME-REQUEST-INVALID', message);
|
|
32
|
+
};
|
|
33
|
+
/** Every value authored under `authority.<key>`: a repeated list key contributes each of its lists' items. */
|
|
34
|
+
function authorityValues(record, key) {
|
|
35
|
+
const fields = record.sections
|
|
36
|
+
.filter((section) => section.name === 'authority')
|
|
37
|
+
.flatMap((section) => section.fields)
|
|
38
|
+
.filter((child) => 'key' in child && child.key === key);
|
|
39
|
+
for (const field of fields)
|
|
40
|
+
if (field.when !== undefined || field.fields !== undefined || field.value.kind === 'block')
|
|
41
|
+
invalid(`${record.identity}: authority.${key} must be an unconditional inline value`);
|
|
42
|
+
return fields.flatMap((field) => (field.value.kind === 'list' ? field.value.items : [field.value]));
|
|
43
|
+
}
|
|
44
|
+
function texts(record, key) {
|
|
45
|
+
return authorityValues(record, key).map((value) => value.kind === 'scalar' || value.kind === 'string' || value.kind === 'prose'
|
|
46
|
+
? value.text
|
|
47
|
+
: invalid(`${record.identity}: authority.${key} holds a value that is not text`));
|
|
48
|
+
}
|
|
49
|
+
function names(record, key, discriminator) {
|
|
50
|
+
return authorityValues(record, key).map((value) => value.kind === 'ref' && value.discriminator === discriminator && value.fragment === undefined
|
|
51
|
+
? value.name
|
|
52
|
+
: invalid(`${record.identity}: authority.${key} holds a value that is not a @${discriminator} reference`));
|
|
53
|
+
}
|
|
54
|
+
function isMove(value) {
|
|
55
|
+
return MOVES.includes(value);
|
|
56
|
+
}
|
|
57
|
+
/** Read the authority a compiled `@mandate` declares; a non-mandate or a malformed field is IA-RUNTIME-REQUEST-INVALID. */
|
|
58
|
+
export function mandateAuthorityOf(record) {
|
|
59
|
+
if (record.discriminator !== 'mandate')
|
|
60
|
+
invalid(`${record.identity} is not a @mandate`);
|
|
61
|
+
const participants = names(record, 'participant', 'agent');
|
|
62
|
+
if (participants.length > 1)
|
|
63
|
+
invalid(`${record.identity}: authority.participant names more than one agent`);
|
|
64
|
+
const present = (key) => authorityValues(record, key).length > 0;
|
|
65
|
+
const moves = texts(record, 'moves').map((move) => isMove(move) ? move : invalid(`${record.identity}: authority.moves names ${move}, not a kernel move`));
|
|
66
|
+
// Presence is judged by the key: a declared but empty list names no move, which the design's one-or-more refuses
|
|
67
|
+
// rather than reading as a lockout of every mode or as an absent restriction.
|
|
68
|
+
const hasMoves = record.sections
|
|
69
|
+
.filter((section) => section.name === 'authority')
|
|
70
|
+
.flatMap((section) => section.fields)
|
|
71
|
+
.some((child) => 'key' in child && child.key === 'moves');
|
|
72
|
+
if (hasMoves && moves.length === 0)
|
|
73
|
+
invalid(`${record.identity}: authority.moves must name at least one kernel move`);
|
|
74
|
+
return Object.freeze({
|
|
75
|
+
identity: record.identity,
|
|
76
|
+
...(participants.length === 1 ? { participant: participants[0] } : {}),
|
|
77
|
+
...(hasMoves ? { moves: Object.freeze(moves) } : {}),
|
|
78
|
+
...(present('excluded-words') ? { excludedWords: Object.freeze(texts(record, 'excluded-words')) } : {}),
|
|
79
|
+
...(present('scope') ? { scope: Object.freeze(names(record, 'scope', 'workspace')) } : {}),
|
|
80
|
+
...(present('covers') ? { covers: Object.freeze(texts(record, 'covers')) } : {}),
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Undefined when the mandate permits `mode` for `words`, else one refusal. The move is judged first: a declared move
|
|
85
|
+
* list admits only the moves it lists and must name at least one (an empty list is IA-RUNTIME-REQUEST-INVALID); a
|
|
86
|
+
* mandate without moves restricts no move. Then any word in `excluded-words` is refused, whatever the moves. `next`
|
|
87
|
+
* names the one catalog command that shows the mandate.
|
|
88
|
+
*/
|
|
89
|
+
export function mandateRefusal(mandate, mode, words = []) {
|
|
90
|
+
if (!isMode(mode))
|
|
91
|
+
invalid(`Mode must be one of ${MODES.join(', ')}`);
|
|
92
|
+
const authority = 'sections' in mandate ? mandateAuthorityOf(mandate) : mandate;
|
|
93
|
+
if (authority.moves !== undefined && authority.moves.length === 0)
|
|
94
|
+
invalid(`${authority.identity}: authority.moves must name at least one kernel move`);
|
|
95
|
+
const move = MODE_MOVES[mode];
|
|
96
|
+
const next = `ia inspect ${authority.identity} --edges both`;
|
|
97
|
+
if (authority.moves !== undefined && !authority.moves.includes(move))
|
|
98
|
+
return Object.freeze({
|
|
99
|
+
code: 'IA-RUNTIME-MANDATE-MOVE',
|
|
100
|
+
message: `${authority.identity} allows ${authority.moves.join(', ')}; ${mode} needs ${move}`,
|
|
101
|
+
next,
|
|
102
|
+
});
|
|
103
|
+
const excluded = words.filter((word) => authority.excludedWords?.includes(word));
|
|
104
|
+
if (excluded.length > 0)
|
|
105
|
+
return Object.freeze({
|
|
106
|
+
code: 'IA-RUNTIME-MANDATE-WORD',
|
|
107
|
+
message: `${authority.identity} excludes ${excluded.join(', ')}`,
|
|
108
|
+
next,
|
|
109
|
+
});
|
|
110
|
+
return undefined;
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=mandate-modes.js.map
|