@dtmd/temper 0.0.24 → 0.0.26
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/README.md +14 -12
- package/dist/src/assembly.d.ts +45 -11
- package/dist/src/assembly.js +116 -8
- package/dist/src/builtins.d.ts +436 -103
- package/dist/src/builtins.js +772 -167
- package/dist/src/claude-code.d.ts +6 -3
- package/dist/src/claude-code.js +2 -2
- package/dist/src/contract.d.ts +153 -44
- package/dist/src/contract.js +123 -34
- package/dist/src/counsel.d.ts +11 -0
- package/dist/src/counsel.js +68 -0
- package/dist/src/declarations.d.ts +108 -2
- package/dist/src/declarations.js +606 -100
- package/dist/src/dial.d.ts +3 -3
- package/dist/src/dial.js +21 -5
- package/dist/src/emit.d.ts +12 -14
- package/dist/src/emit.js +123 -47
- package/dist/src/generated/AbsenceGateRow.d.ts +16 -0
- package/dist/src/generated/AbsenceGateRow.js +2 -0
- package/dist/src/generated/AreaMode.d.ts +5 -0
- package/dist/src/generated/AreaMode.js +2 -0
- package/dist/src/generated/AreaRow.d.ts +20 -0
- package/dist/src/generated/AreaRow.js +1 -0
- package/dist/src/generated/AssemblyFactRow.d.ts +17 -4
- package/dist/src/generated/BoundRow.d.ts +9 -4
- package/dist/src/generated/CedeRow.d.ts +14 -0
- package/dist/src/generated/CedeRow.js +2 -0
- package/dist/src/generated/CharsetRow.d.ts +14 -3
- package/dist/src/generated/ClauseRow.d.ts +23 -21
- package/dist/src/generated/CollectionAddressRow.d.ts +1 -1
- package/dist/src/generated/Declarations.d.ts +24 -9
- package/dist/src/generated/FeatureValue.d.ts +3 -3
- package/dist/src/generated/Features.d.ts +3 -3
- package/dist/src/generated/KindFactRow.d.ts +41 -8
- package/dist/src/generated/Payload.d.ts +3 -5
- package/dist/src/generated/PayloadMember.d.ts +7 -0
- package/dist/src/generated/RunsRow.d.ts +17 -0
- package/dist/src/generated/RunsRow.js +2 -0
- package/dist/src/generated/Section.d.ts +2 -2
- package/dist/src/generated/SectionContainsRow.d.ts +1 -1
- package/dist/src/generated/TypecheckRow.d.ts +20 -0
- package/dist/src/generated/TypecheckRow.js +2 -0
- package/dist/src/generated/Verifier.d.ts +8 -2
- package/dist/src/generated/index.d.ts +6 -0
- package/dist/src/index.d.ts +20 -15
- package/dist/src/index.js +10 -9
- package/dist/src/kind.d.ts +382 -52
- package/dist/src/kind.js +461 -49
- package/dist/src/lockfile.d.ts +39 -0
- package/dist/src/lockfile.js +265 -0
- package/dist/src/member-address.d.ts +15 -3
- package/dist/src/member-address.js +23 -6
- package/dist/src/needs.d.ts +25 -15
- package/dist/src/needs.js +10 -11
- package/dist/src/patterns.d.ts +112 -0
- package/dist/src/patterns.js +90 -0
- package/dist/src/pipe.d.ts +16 -0
- package/dist/src/pipe.js +39 -0
- package/dist/src/playbook.d.ts +203 -0
- package/dist/src/playbook.js +239 -0
- package/dist/src/prose.d.ts +69 -12
- package/dist/src/prose.js +125 -13
- package/dist/src/reference.d.ts +70 -0
- package/dist/src/reference.js +368 -0
- package/package.json +13 -4
- package/schemas/agent.json +23 -0
- package/schemas/command.json +5 -0
- package/schemas/output-style.json +4 -0
- package/schemas/rule.json +33 -0
- package/schemas/skill.json +63 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The version a `{ package, bin }` tool runs at — its program's lockfile's: the one the
|
|
3
|
+
* `packageManager` field of the program's `package.json` names (npm's `package-lock.json`,
|
|
4
|
+
* pnpm's `pnpm-lock.yaml`), read from the workspace the engine runs the program in (its
|
|
5
|
+
* cwd), else from the workspace root its package manager resolves (the nearest ancestor
|
|
6
|
+
* declaring a workspace, read only when it includes the program), keyed by the program's
|
|
7
|
+
* path below it. The reference states it; the engine's `src/tool.rs` is the same read for
|
|
8
|
+
* `check` and `explain`, and the two must agree: an absent field, or another manager,
|
|
9
|
+
* refuses by name.
|
|
10
|
+
*
|
|
11
|
+
* Formats (external facts): `packageManager` (`<name>@<version>`, an optional `+<hash>`) —
|
|
12
|
+
* https://github.com/nodejs/corepack/blob/main/README.md (retrieved 2026-11-26);
|
|
13
|
+
* https://docs.npmjs.com/cli/v10/configuring-npm/package-lock-json,
|
|
14
|
+
* https://github.com/pnpm/spec/blob/master/lockfile/9.0.md and https://pnpm.io/lockfile
|
|
15
|
+
* (all retrieved 2026-11-25); workspace roots: https://pnpm.io/workspaces,
|
|
16
|
+
* https://pnpm.io/pnpm-workspace_yaml and https://docs.npmjs.com/cli/v10/using-npm/workspaces
|
|
17
|
+
* (retrieved 2026-11-26).
|
|
18
|
+
*/
|
|
19
|
+
/** npm's lockfile. */
|
|
20
|
+
export declare const NPM_LOCKFILE = "package-lock.json";
|
|
21
|
+
/** pnpm's lockfile. */
|
|
22
|
+
export declare const PNPM_LOCKFILE = "pnpm-lock.yaml";
|
|
23
|
+
/** A read lockfile: its file name, and the version it records for a direct dependency. */
|
|
24
|
+
export interface Lockfile {
|
|
25
|
+
readonly name: string;
|
|
26
|
+
version(pkg: string): string | undefined;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Read the lockfile of the program in `workspace`: its own directory's, else the one at
|
|
30
|
+
* the nearest ancestor declaring a workspace, read only when that declaration includes
|
|
31
|
+
* the program; `undefined` otherwise — an ancestor's lockfile no workspace of the
|
|
32
|
+
* program's names locks some other project, and is never read.
|
|
33
|
+
*
|
|
34
|
+
* # Throws
|
|
35
|
+
* When the program's `package.json` declares no `packageManager` or names a manager temper
|
|
36
|
+
* does not read — a manager is never guessed — when an npm program's directory holds
|
|
37
|
+
* `npm-shrinkwrap.json`, or when `package-lock.json` is not JSON.
|
|
38
|
+
*/
|
|
39
|
+
export declare function readLockfile(workspace: string): Lockfile | undefined;
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The version a `{ package, bin }` tool runs at — its program's lockfile's: the one the
|
|
3
|
+
* `packageManager` field of the program's `package.json` names (npm's `package-lock.json`,
|
|
4
|
+
* pnpm's `pnpm-lock.yaml`), read from the workspace the engine runs the program in (its
|
|
5
|
+
* cwd), else from the workspace root its package manager resolves (the nearest ancestor
|
|
6
|
+
* declaring a workspace, read only when it includes the program), keyed by the program's
|
|
7
|
+
* path below it. The reference states it; the engine's `src/tool.rs` is the same read for
|
|
8
|
+
* `check` and `explain`, and the two must agree: an absent field, or another manager,
|
|
9
|
+
* refuses by name.
|
|
10
|
+
*
|
|
11
|
+
* Formats (external facts): `packageManager` (`<name>@<version>`, an optional `+<hash>`) —
|
|
12
|
+
* https://github.com/nodejs/corepack/blob/main/README.md (retrieved 2026-11-26);
|
|
13
|
+
* https://docs.npmjs.com/cli/v10/configuring-npm/package-lock-json,
|
|
14
|
+
* https://github.com/pnpm/spec/blob/master/lockfile/9.0.md and https://pnpm.io/lockfile
|
|
15
|
+
* (all retrieved 2026-11-25); workspace roots: https://pnpm.io/workspaces,
|
|
16
|
+
* https://pnpm.io/pnpm-workspace_yaml and https://docs.npmjs.com/cli/v10/using-npm/workspaces
|
|
17
|
+
* (retrieved 2026-11-26).
|
|
18
|
+
*/
|
|
19
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
20
|
+
import { dirname, join, matchesGlob, relative, resolve, sep } from "node:path";
|
|
21
|
+
/** npm's lockfile. */
|
|
22
|
+
export const NPM_LOCKFILE = "package-lock.json";
|
|
23
|
+
/** pnpm's lockfile. */
|
|
24
|
+
export const PNPM_LOCKFILE = "pnpm-lock.yaml";
|
|
25
|
+
/** npm's publishable lockfile, read before `package-lock.json`: beside an npm program it refuses by name. */
|
|
26
|
+
const NPM_SHRINKWRAP = "npm-shrinkwrap.json";
|
|
27
|
+
/** The managers temper reads, by the name `packageManager` spells before its `@`. */
|
|
28
|
+
const MANAGER_LOCKFILES = { npm: NPM_LOCKFILE, pnpm: PNPM_LOCKFILE };
|
|
29
|
+
function field(value, key) {
|
|
30
|
+
return value !== null && typeof value === "object" && !Array.isArray(value) ? value[key] : undefined;
|
|
31
|
+
}
|
|
32
|
+
function str(value) {
|
|
33
|
+
return typeof value === "string" ? value : undefined;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* `pkg`'s version in an npm lockfile: v2/v3's `packages` — the importer's own
|
|
37
|
+
* `node_modules` before the hoisted root one, following a link — else v1's `dependencies`.
|
|
38
|
+
*/
|
|
39
|
+
function npmVersion(document, importer, pkg) {
|
|
40
|
+
const packages = field(document, "packages");
|
|
41
|
+
if (packages !== undefined) {
|
|
42
|
+
const hoisted = `node_modules/${pkg}`;
|
|
43
|
+
const entry = (importer === "" ? undefined : field(packages, `${importer}/${hoisted}`)) ?? field(packages, hoisted);
|
|
44
|
+
const version = str(field(entry, "version"));
|
|
45
|
+
if (version !== undefined)
|
|
46
|
+
return version;
|
|
47
|
+
const resolved = field(entry, "link") === true ? str(field(entry, "resolved")) : undefined;
|
|
48
|
+
return resolved === undefined ? undefined : str(field(field(packages, resolved), "version"));
|
|
49
|
+
}
|
|
50
|
+
return str(field(field(field(document, "dependencies"), pkg), "version"));
|
|
51
|
+
}
|
|
52
|
+
/** A YAML scalar as pnpm writes it: bare, or single- or double-quoted. */
|
|
53
|
+
function unquote(raw) {
|
|
54
|
+
const text = raw.trim();
|
|
55
|
+
if (text.length >= 2 && (text[0] === "'" || text[0] === '"') && text.at(-1) === text[0]) {
|
|
56
|
+
return text.slice(1, -1).replaceAll(text[0] === "'" ? "''" : '\\"', text[0] === "'" ? "'" : '"');
|
|
57
|
+
}
|
|
58
|
+
return text;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* `pkg`'s version in a pnpm lockfile: the first of its documents — split at their `---`
|
|
62
|
+
* marker lines, a leading boot (env) document before the project's — that records it.
|
|
63
|
+
*/
|
|
64
|
+
function pnpmVersion(text, importer, pkg) {
|
|
65
|
+
const documents = [[]];
|
|
66
|
+
for (const line of text.split(/\r?\n/)) {
|
|
67
|
+
if (line.trimEnd() === "---")
|
|
68
|
+
documents.push([]);
|
|
69
|
+
else
|
|
70
|
+
documents.at(-1)?.push(line);
|
|
71
|
+
}
|
|
72
|
+
for (const document of documents) {
|
|
73
|
+
const version = pnpmDocumentVersion(document, importer, pkg);
|
|
74
|
+
if (version !== undefined)
|
|
75
|
+
return version;
|
|
76
|
+
}
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* `pkg`'s version in one pnpm lockfile document — the importer's dependency groups (v6+),
|
|
81
|
+
* else the top-level groups (v5). pnpm writes block-style YAML at two-space indents, so
|
|
82
|
+
* the read walks the indentation of exactly that path rather than parsing YAML in general.
|
|
83
|
+
*/
|
|
84
|
+
function pnpmDocumentVersion(document, importer, pkg) {
|
|
85
|
+
const lines = document.filter((line) => line.trim() !== "" && !line.trimStart().startsWith("#"));
|
|
86
|
+
const entries = lines.map((line) => {
|
|
87
|
+
const indent = line.length - line.trimStart().length;
|
|
88
|
+
const body = line.trim();
|
|
89
|
+
const colon = body.match(/^('(?:[^']|'')*'|"(?:[^"\\]|\\.)*"|[^:]+):(?:\s+(.*))?$/);
|
|
90
|
+
return colon === null
|
|
91
|
+
? { indent, key: undefined, value: undefined }
|
|
92
|
+
: { indent, key: unquote(colon[1] ?? ""), value: colon[2] === undefined ? undefined : unquote(colon[2]) };
|
|
93
|
+
});
|
|
94
|
+
/** The children of the mapping entry at `at`, as indices. */
|
|
95
|
+
const children = (at) => {
|
|
96
|
+
const parent = at < 0 ? -1 : (entries[at]?.indent ?? 0);
|
|
97
|
+
const out = [];
|
|
98
|
+
let depth;
|
|
99
|
+
for (let i = at + 1; i < entries.length; i++) {
|
|
100
|
+
const indent = entries[i]?.indent ?? 0;
|
|
101
|
+
if (indent <= parent)
|
|
102
|
+
break;
|
|
103
|
+
depth ??= indent;
|
|
104
|
+
if (indent === depth)
|
|
105
|
+
out.push(i);
|
|
106
|
+
}
|
|
107
|
+
return out;
|
|
108
|
+
};
|
|
109
|
+
const child = (at, key) => children(at).find((i) => entries[i]?.key === key);
|
|
110
|
+
const importers = child(-1, "importers");
|
|
111
|
+
const root = importers === undefined ? -1 : child(importers, importer === "" ? "." : importer);
|
|
112
|
+
if (root === undefined)
|
|
113
|
+
return undefined;
|
|
114
|
+
for (const group of ["dependencies", "devDependencies", "optionalDependencies"]) {
|
|
115
|
+
const at = child(root, group);
|
|
116
|
+
const entry = at === undefined ? undefined : child(at, pkg);
|
|
117
|
+
if (entry === undefined)
|
|
118
|
+
continue;
|
|
119
|
+
const bare = entries[entry]?.value;
|
|
120
|
+
const versionAt = bare === undefined ? child(entry, "version") : undefined;
|
|
121
|
+
const version = bare ?? (versionAt === undefined ? undefined : entries[versionAt]?.value);
|
|
122
|
+
if (version !== undefined)
|
|
123
|
+
return version.split("(")[0];
|
|
124
|
+
}
|
|
125
|
+
return undefined;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Read the lockfile of the program in `workspace`: its own directory's, else the one at
|
|
129
|
+
* the nearest ancestor declaring a workspace, read only when that declaration includes
|
|
130
|
+
* the program; `undefined` otherwise — an ancestor's lockfile no workspace of the
|
|
131
|
+
* program's names locks some other project, and is never read.
|
|
132
|
+
*
|
|
133
|
+
* # Throws
|
|
134
|
+
* When the program's `package.json` declares no `packageManager` or names a manager temper
|
|
135
|
+
* does not read — a manager is never guessed — when an npm program's directory holds
|
|
136
|
+
* `npm-shrinkwrap.json`, or when `package-lock.json` is not JSON.
|
|
137
|
+
*/
|
|
138
|
+
export function readLockfile(workspace) {
|
|
139
|
+
const program = resolve(workspace);
|
|
140
|
+
const lockfile = declaredLockfile(program);
|
|
141
|
+
const own = readLockfileIn(program, "", lockfile);
|
|
142
|
+
if (own !== undefined)
|
|
143
|
+
return own;
|
|
144
|
+
for (let dir = dirname(program);; dir = dirname(dir)) {
|
|
145
|
+
const globs = workspaceGlobs(dir);
|
|
146
|
+
if (globs !== undefined) {
|
|
147
|
+
const importer = relative(dir, program).split(sep).join("/");
|
|
148
|
+
return includes(globs, importer) ? readLockfileIn(dir, importer, lockfile) : undefined;
|
|
149
|
+
}
|
|
150
|
+
if (dirname(dir) === dir)
|
|
151
|
+
return undefined;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
/** The lockfile of the manager the `packageManager` field of `program`'s `package.json` names. */
|
|
155
|
+
function declaredLockfile(program) {
|
|
156
|
+
const path = join(program, "package.json");
|
|
157
|
+
const text = readText(path);
|
|
158
|
+
let declared;
|
|
159
|
+
if (text !== undefined) {
|
|
160
|
+
try {
|
|
161
|
+
declared = field(JSON.parse(text), "packageManager");
|
|
162
|
+
}
|
|
163
|
+
catch (error) {
|
|
164
|
+
throw new Error(`\`${path}\` does not parse: ${String(error)}`);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
if (typeof declared !== "string") {
|
|
168
|
+
throw new Error(`\`${path}\` declares no \`packageManager\`, so the program's package manager is unknown — temper never guesses it. ` +
|
|
169
|
+
"Add `\"packageManager\": \"npm@<version>\"` (or `pnpm@<version>`) to it, naming the manager that installs the program's packages.");
|
|
170
|
+
}
|
|
171
|
+
const lockfile = MANAGER_LOCKFILES[declared.split("@")[0] ?? ""];
|
|
172
|
+
if (lockfile === undefined) {
|
|
173
|
+
throw new Error(`\`${path}\` declares the package manager \`${declared}\`, which temper does not read — ` +
|
|
174
|
+
"a `{ package, bin }` tool's version is read from npm's or pnpm's lockfile.");
|
|
175
|
+
}
|
|
176
|
+
return lockfile;
|
|
177
|
+
}
|
|
178
|
+
/** pnpm's workspace declaration, beside the root's lockfile. */
|
|
179
|
+
const PNPM_WORKSPACE = "pnpm-workspace.yaml";
|
|
180
|
+
/** `path`'s text, `undefined` when it cannot be read. */
|
|
181
|
+
function readText(path) {
|
|
182
|
+
try {
|
|
183
|
+
return readFileSync(path, "utf8");
|
|
184
|
+
}
|
|
185
|
+
catch {
|
|
186
|
+
return undefined;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* The workspace globs `dir` declares, when it declares a workspace at all: pnpm's
|
|
191
|
+
* `pnpm-workspace.yaml` `packages` (absent, the root alone), then `package.json`'s
|
|
192
|
+
* `workspaces` array, npm's. A declaration that cannot be read or parsed declares nothing.
|
|
193
|
+
*/
|
|
194
|
+
function workspaceGlobs(dir) {
|
|
195
|
+
let globs;
|
|
196
|
+
const pnpm = readText(join(dir, PNPM_WORKSPACE));
|
|
197
|
+
if (pnpm !== undefined)
|
|
198
|
+
globs = pnpmPackages(pnpm);
|
|
199
|
+
const npm = readText(join(dir, "package.json"));
|
|
200
|
+
if (npm !== undefined) {
|
|
201
|
+
let manifest;
|
|
202
|
+
try {
|
|
203
|
+
manifest = JSON.parse(npm);
|
|
204
|
+
}
|
|
205
|
+
catch {
|
|
206
|
+
manifest = undefined;
|
|
207
|
+
}
|
|
208
|
+
const workspaces = field(manifest, "workspaces");
|
|
209
|
+
if (Array.isArray(workspaces)) {
|
|
210
|
+
globs = [...(globs ?? []), ...workspaces.filter((item) => typeof item === "string")];
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
return globs;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* The top-level `packages` sequence of a `pnpm-workspace.yaml`, block (`- glob` lines) or
|
|
217
|
+
* flow (`[a, b]`) style — the shapes pnpm's docs write it in.
|
|
218
|
+
*/
|
|
219
|
+
function pnpmPackages(text) {
|
|
220
|
+
const lines = text.split(/\r?\n/);
|
|
221
|
+
const at = lines.findIndex((line) => /^packages:(\s|$)/.test(line));
|
|
222
|
+
if (at < 0)
|
|
223
|
+
return [];
|
|
224
|
+
const rest = (lines[at] ?? "").slice("packages:".length).replace(/\s+#.*$/, "").trim();
|
|
225
|
+
if (rest.startsWith("[") && rest.endsWith("]")) {
|
|
226
|
+
return rest
|
|
227
|
+
.slice(1, -1)
|
|
228
|
+
.split(",")
|
|
229
|
+
.map(unquote)
|
|
230
|
+
.filter((glob) => glob !== "");
|
|
231
|
+
}
|
|
232
|
+
const globs = [];
|
|
233
|
+
for (const line of lines.slice(at + 1)) {
|
|
234
|
+
const body = line.trim();
|
|
235
|
+
if (body === "" || body.startsWith("#"))
|
|
236
|
+
continue;
|
|
237
|
+
if (line.length === line.trimStart().length && !body.startsWith("-"))
|
|
238
|
+
break;
|
|
239
|
+
if (body.startsWith("-"))
|
|
240
|
+
globs.push(unquote(body.slice(1).replace(/\s+#.*$/, "")));
|
|
241
|
+
}
|
|
242
|
+
return globs;
|
|
243
|
+
}
|
|
244
|
+
/** Whether `globs` include the project at `path`: a positive one matches, no `!` one does. */
|
|
245
|
+
function includes(globs, path) {
|
|
246
|
+
const matches = (glob) => matchesGlob(path, glob.replace(/^(\.\/)+/, "").replace(/\/+$/, ""));
|
|
247
|
+
const negated = globs.filter((glob) => glob.startsWith("!")).map((glob) => glob.slice(1));
|
|
248
|
+
return globs.some((glob) => !glob.startsWith("!") && matches(glob)) && !negated.some(matches);
|
|
249
|
+
}
|
|
250
|
+
/** The lockfile named `lockfile` in `dir` alone, for the program at `importer` below it. */
|
|
251
|
+
function readLockfileIn(dir, importer, lockfile) {
|
|
252
|
+
if (lockfile === NPM_LOCKFILE && existsSync(join(dir, NPM_SHRINKWRAP))) {
|
|
253
|
+
throw new Error(`the program's packages are locked by \`${join(dir, NPM_SHRINKWRAP)}\`, which temper does not read — ` +
|
|
254
|
+
"a `{ package, bin }` tool's version is read from `package-lock.json` or `pnpm-lock.yaml`.");
|
|
255
|
+
}
|
|
256
|
+
const path = join(dir, lockfile);
|
|
257
|
+
if (!existsSync(path))
|
|
258
|
+
return undefined;
|
|
259
|
+
const text = readFileSync(path, "utf8");
|
|
260
|
+
if (lockfile === NPM_LOCKFILE) {
|
|
261
|
+
const document = JSON.parse(text);
|
|
262
|
+
return { name: NPM_LOCKFILE, version: (pkg) => npmVersion(document, importer, pkg) };
|
|
263
|
+
}
|
|
264
|
+
return { name: PNPM_LOCKFILE, version: (pkg) => pnpmVersion(text, importer, pkg) };
|
|
265
|
+
}
|
|
@@ -59,6 +59,15 @@ export interface LeafAddress {
|
|
|
59
59
|
*/
|
|
60
60
|
readonly childPath: string;
|
|
61
61
|
}
|
|
62
|
+
/** The root member's own address — the harness itself, host of its embedded children. */
|
|
63
|
+
export declare const ROOT_ADDRESS = "root";
|
|
64
|
+
/**
|
|
65
|
+
* The embedded kinds the root member hosts, by kind key: a roster member of one is the
|
|
66
|
+
* root's child, so its own address is `root/<kind>/<key>` ({@link memberAddress}). Kept
|
|
67
|
+
* here rather than beside the kinds (`builtins.ts` re-exports it) because the address is
|
|
68
|
+
* the grammar's to spell, and the grammar owes the member model nothing.
|
|
69
|
+
*/
|
|
70
|
+
export declare const ROOT_HOSTED_KINDS: ReadonlySet<string>;
|
|
62
71
|
/** Spell a top-level member's own `<kind>:<name>` address. */
|
|
63
72
|
export declare function hostAddress(kind: string, name: string): string;
|
|
64
73
|
/** Spell a nested member's address from its host's address, its own kind and its key. */
|
|
@@ -89,7 +98,10 @@ export interface AddressedMember {
|
|
|
89
98
|
* own `host` column).
|
|
90
99
|
*
|
|
91
100
|
* A top-level member's address is its kind joined onto its name ({@link hostAddress}). A
|
|
92
|
-
*
|
|
101
|
+
* member of a {@link ROOT_HOSTED_KINDS} kind is the root's nested member, so its address
|
|
102
|
+
* is `root/<kind>/<key>` — the one spelling `check` resolves it at and the lock's `runs`
|
|
103
|
+
* and `typecheck` rows name it by; a second `<kind>:<name>` spelling would key the same
|
|
104
|
+
* member two ways across the rows it is declared under. A nested **file** child's identity *is* its whole `<host-address>/<kind>/<key>` address,
|
|
93
105
|
* exactly as an embedded member's is: the host segment is the whole of what tells two
|
|
94
106
|
* same-named children under different hosts apart, so two hosts may each carry a `home`
|
|
95
107
|
* and neither claims the other's. Keying one by `<kind>:<name>` alone made a child's name
|
|
@@ -190,8 +202,8 @@ export declare function parseHostAddress(address: string): HostAddress | undefin
|
|
|
190
202
|
* Parse a nested-member address, or `undefined` when `address` is not one.
|
|
191
203
|
*
|
|
192
204
|
* The grammar is an **odd** count of non-empty segments, three or more: a host address —
|
|
193
|
-
* every segment but the final two, itself a member address at any depth
|
|
194
|
-
* kind and the key. Depth is the model's to choose, not the grammar's: any member's address
|
|
205
|
+
* every segment but the final two, itself a member address at any depth, or the root's
|
|
206
|
+
* bare {@link ROOT_ADDRESS} — then the nested kind and the key. Depth is the model's to choose, not the grammar's: any member's address
|
|
195
207
|
* may host, so the reader reads what the model nests rather than capping at one layer.
|
|
196
208
|
*
|
|
197
209
|
* The **leaf tail is ruled out by the count**: a leaf is its own grain, parsed by
|
|
@@ -19,6 +19,15 @@
|
|
|
19
19
|
* is the other end of the same grammar: a spelling moves on both sides at once or the seam
|
|
20
20
|
* breaks.
|
|
21
21
|
*/
|
|
22
|
+
/** The root member's own address — the harness itself, host of its embedded children. */
|
|
23
|
+
export const ROOT_ADDRESS = "root";
|
|
24
|
+
/**
|
|
25
|
+
* The embedded kinds the root member hosts, by kind key: a roster member of one is the
|
|
26
|
+
* root's child, so its own address is `root/<kind>/<key>` ({@link memberAddress}). Kept
|
|
27
|
+
* here rather than beside the kinds (`builtins.ts` re-exports it) because the address is
|
|
28
|
+
* the grammar's to spell, and the grammar owes the member model nothing.
|
|
29
|
+
*/
|
|
30
|
+
export const ROOT_HOSTED_KINDS = new Set(["tool", "requirement"]);
|
|
22
31
|
/** Spell a top-level member's own `<kind>:<name>` address. */
|
|
23
32
|
export function hostAddress(kind, name) {
|
|
24
33
|
return `${kind}:${name}`;
|
|
@@ -34,7 +43,10 @@ export function nestedAddress(host, kind, key) {
|
|
|
34
43
|
* own `host` column).
|
|
35
44
|
*
|
|
36
45
|
* A top-level member's address is its kind joined onto its name ({@link hostAddress}). A
|
|
37
|
-
*
|
|
46
|
+
* member of a {@link ROOT_HOSTED_KINDS} kind is the root's nested member, so its address
|
|
47
|
+
* is `root/<kind>/<key>` — the one spelling `check` resolves it at and the lock's `runs`
|
|
48
|
+
* and `typecheck` rows name it by; a second `<kind>:<name>` spelling would key the same
|
|
49
|
+
* member two ways across the rows it is declared under. A nested **file** child's identity *is* its whole `<host-address>/<kind>/<key>` address,
|
|
38
50
|
* exactly as an embedded member's is: the host segment is the whole of what tells two
|
|
39
51
|
* same-named children under different hosts apart, so two hosts may each carry a `home`
|
|
40
52
|
* and neither claims the other's. Keying one by `<kind>:<name>` alone made a child's name
|
|
@@ -53,8 +65,11 @@ export function nestedAddress(host, kind, key) {
|
|
|
53
65
|
*/
|
|
54
66
|
export function memberAddress(member) {
|
|
55
67
|
const { host } = member;
|
|
56
|
-
if (host === undefined)
|
|
57
|
-
return
|
|
68
|
+
if (host === undefined) {
|
|
69
|
+
return ROOT_HOSTED_KINDS.has(member.kind)
|
|
70
|
+
? nestedAddress(ROOT_ADDRESS, member.kind, member.name)
|
|
71
|
+
: hostAddress(member.kind, member.name);
|
|
72
|
+
}
|
|
58
73
|
return nestedAddress(memberAddress(host), member.kind, member.name);
|
|
59
74
|
}
|
|
60
75
|
/**
|
|
@@ -189,8 +204,8 @@ function segment(address) {
|
|
|
189
204
|
* Parse a nested-member address, or `undefined` when `address` is not one.
|
|
190
205
|
*
|
|
191
206
|
* The grammar is an **odd** count of non-empty segments, three or more: a host address —
|
|
192
|
-
* every segment but the final two, itself a member address at any depth
|
|
193
|
-
* kind and the key. Depth is the model's to choose, not the grammar's: any member's address
|
|
207
|
+
* every segment but the final two, itself a member address at any depth, or the root's
|
|
208
|
+
* bare {@link ROOT_ADDRESS} — then the nested kind and the key. Depth is the model's to choose, not the grammar's: any member's address
|
|
194
209
|
* may host, so the reader reads what the model nests rather than capping at one layer.
|
|
195
210
|
*
|
|
196
211
|
* The **leaf tail is ruled out by the count**: a leaf is its own grain, parsed by
|
|
@@ -206,8 +221,10 @@ export function parseNestedAddress(address) {
|
|
|
206
221
|
// The host is itself a member address, read at its own grain: a top-level host address,
|
|
207
222
|
// or a nested one read back through this very parser however deep it runs. Never off a
|
|
208
223
|
// first-colon split, which would take `area` / `a/page/b` out of `area:a/page/b`.
|
|
224
|
+
// The root member is a host too, at its bare `root` rather than a `<kind>:<name>` — the
|
|
225
|
+
// engine's `host_identity` reads it the same way — so a root-hosted member reads here.
|
|
209
226
|
const { host } = segments;
|
|
210
|
-
if (parseHostAddress(host) === undefined && parseNestedAddress(host) === undefined) {
|
|
227
|
+
if (host !== ROOT_ADDRESS && parseHostAddress(host) === undefined && parseNestedAddress(host) === undefined) {
|
|
211
228
|
return undefined;
|
|
212
229
|
}
|
|
213
230
|
return { host, kind: segments.kind, key: segments.key };
|
package/dist/src/needs.d.ts
CHANGED
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Needs — the capabilities a member's behavior uses, declared as typed values.
|
|
3
|
-
* Emit derives
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* permission with no member is visible as exactly that.
|
|
3
|
+
* Emit derives the settings permission lists from their union, so a permission is never
|
|
4
|
+
* authored twice: `permissions.allow` and `permissions.ask` are the unions of the
|
|
5
|
+
* members' declared `needs`, and a permission with no member is visible as exactly that.
|
|
7
6
|
*/
|
|
7
|
+
/**
|
|
8
|
+
* The settings permission list a capability's entry joins: `"allow"` runs the tool
|
|
9
|
+
* without a prompt, `"ask"` prompts for confirmation even where an allow rule also
|
|
10
|
+
* matches — rules evaluate deny, then ask, then allow (code.claude.com/docs/en/permissions,
|
|
11
|
+
* "Manage permissions", retrieved 2026-11-26).
|
|
12
|
+
*/
|
|
13
|
+
export type PermissionList = "allow" | "ask";
|
|
8
14
|
/** A declared capability — its `permission` is the entry it derives in the union. */
|
|
9
15
|
export interface Capability {
|
|
10
|
-
/**
|
|
11
|
-
* The permission-list entry this capability derives. The union of every
|
|
12
|
-
* member's needs is the settings `permissions.allow` — the fold hooks and MCP
|
|
13
|
-
* members ride into once those kinds land.
|
|
14
|
-
*/
|
|
16
|
+
/** The permission-rule entry this capability derives. */
|
|
15
17
|
readonly permission: string;
|
|
18
|
+
/** The list the entry joins; absent, `"allow"`. */
|
|
19
|
+
readonly list?: PermissionList;
|
|
16
20
|
}
|
|
17
21
|
/**
|
|
18
22
|
* A shell-command capability. Its derived permission is the Claude Code allow
|
|
@@ -20,12 +24,18 @@ export interface Capability {
|
|
|
20
24
|
* 2026-07-04) — e.g. `bash("git diff")`.
|
|
21
25
|
*/
|
|
22
26
|
export declare function bash(command: string): Capability;
|
|
23
|
-
/** Any capability whose permission entry the author states verbatim. */
|
|
24
|
-
export declare function capability(permission: string
|
|
27
|
+
/** Any capability whose permission entry the author states verbatim, on `list` (default `"allow"`). */
|
|
28
|
+
export declare function capability(permission: string, opts?: {
|
|
29
|
+
list?: PermissionList;
|
|
30
|
+
}): Capability;
|
|
31
|
+
/** The derived settings permission lists — each the deduped, sorted union of its entries. */
|
|
32
|
+
export interface PermissionLists {
|
|
33
|
+
readonly allow: readonly string[];
|
|
34
|
+
readonly ask: readonly string[];
|
|
35
|
+
}
|
|
25
36
|
/**
|
|
26
|
-
* The derived permission
|
|
27
|
-
* and sorted so the derived artifact is byte-stable across runs.
|
|
28
|
-
* The
|
|
37
|
+
* The derived permission lists — the union of every capability's entry on its list,
|
|
38
|
+
* deduped and sorted so the derived artifact is byte-stable across runs. The
|
|
29
39
|
* permission is derived here, never authored.
|
|
30
40
|
*/
|
|
31
|
-
export declare function permissionUnion(needs: readonly Capability[]):
|
|
41
|
+
export declare function permissionUnion(needs: readonly Capability[]): PermissionLists;
|
package/dist/src/needs.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Needs — the capabilities a member's behavior uses, declared as typed values.
|
|
3
|
-
* Emit derives
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* permission with no member is visible as exactly that.
|
|
3
|
+
* Emit derives the settings permission lists from their union, so a permission is never
|
|
4
|
+
* authored twice: `permissions.allow` and `permissions.ask` are the unions of the
|
|
5
|
+
* members' declared `needs`, and a permission with no member is visible as exactly that.
|
|
7
6
|
*/
|
|
8
7
|
/**
|
|
9
8
|
* A shell-command capability. Its derived permission is the Claude Code allow
|
|
@@ -13,16 +12,16 @@
|
|
|
13
12
|
export function bash(command) {
|
|
14
13
|
return { permission: `Bash(${command})` };
|
|
15
14
|
}
|
|
16
|
-
/** Any capability whose permission entry the author states verbatim. */
|
|
17
|
-
export function capability(permission) {
|
|
18
|
-
return { permission };
|
|
15
|
+
/** Any capability whose permission entry the author states verbatim, on `list` (default `"allow"`). */
|
|
16
|
+
export function capability(permission, opts = {}) {
|
|
17
|
+
return opts.list === undefined || opts.list === "allow" ? { permission } : { permission, list: opts.list };
|
|
19
18
|
}
|
|
20
19
|
/**
|
|
21
|
-
* The derived permission
|
|
22
|
-
* and sorted so the derived artifact is byte-stable across runs.
|
|
23
|
-
* The
|
|
20
|
+
* The derived permission lists — the union of every capability's entry on its list,
|
|
21
|
+
* deduped and sorted so the derived artifact is byte-stable across runs. The
|
|
24
22
|
* permission is derived here, never authored.
|
|
25
23
|
*/
|
|
26
24
|
export function permissionUnion(needs) {
|
|
27
|
-
|
|
25
|
+
const union = (list) => [...new Set(needs.filter((need) => (need.list ?? "allow") === list).map((need) => need.permission))].sort();
|
|
26
|
+
return { allow: union("allow"), ask: union("ask") };
|
|
28
27
|
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `@dtmd/temper/patterns` subpath — temper's default harness as shapes the consumer
|
|
3
|
+
* hydrates. Each export is a typed constructor: temper supplies the structure, wiring,
|
|
4
|
+
* edges and rendering; the consumer supplies the content. A required parameter is where
|
|
5
|
+
* the consumer's own content lives and has no default; an optional one is mechanics,
|
|
6
|
+
* with a default.
|
|
7
|
+
*
|
|
8
|
+
* These are the **mechanics** shapes — what using temper well takes in any harness:
|
|
9
|
+
*
|
|
10
|
+
* - {@link gateHooks} — the three gate hooks: the session-start report and the guard's
|
|
11
|
+
* two edges.
|
|
12
|
+
* - {@link typecheck} — the compiler `emit` runs over the program before running it.
|
|
13
|
+
* - {@link reference} — the emitted harness reference, its description hydratable and its
|
|
14
|
+
* topics derived from what is declared.
|
|
15
|
+
*
|
|
16
|
+
* And the central pattern, {@link playbook}: one area of guidance as a path rule, a routing
|
|
17
|
+
* skill and its topic files.
|
|
18
|
+
*
|
|
19
|
+
* The SDK counsel rule is not a shape here: `emit` synthesizes it over every program,
|
|
20
|
+
* patterns or not, so there is nothing to compose. {@link defaultPatterns} composes every shape
|
|
21
|
+
* with its defaults, and the playbooks it is given, into the parts `harness()` takes. It carries no taste — no memory
|
|
22
|
+
* content, no conventions — and declares no telemetry: a tap is opt-in, the consumer's
|
|
23
|
+
* own `require` entry with a `telemetry` verifier.
|
|
24
|
+
*/
|
|
25
|
+
import type { Typecheck } from "./assembly.js";
|
|
26
|
+
import type { Input, Member } from "./kind.js";
|
|
27
|
+
import type { Playbook } from "./playbook.js";
|
|
28
|
+
import type { ReferenceInit } from "./reference.js";
|
|
29
|
+
export type { ReferenceInit } from "./reference.js";
|
|
30
|
+
export { reference } from "./reference.js";
|
|
31
|
+
export type { NestedTrigger, PathsTrigger, Playbook, PlaybookAttachments, PlaybookExecution, PlaybookGuard, PlaybookInit, PlaybookInvocation, PlaybookRenderer, PlaybookSatisfies, PlaybookTopic, PlaybookTrigger, PointerView, RouterView, } from "./playbook.js";
|
|
32
|
+
export { playbook } from "./playbook.js";
|
|
33
|
+
/** What {@link gateHooks} takes — mechanics alone, every field defaulted. */
|
|
34
|
+
export interface GateHooksInit {
|
|
35
|
+
/**
|
|
36
|
+
* The {@link tool} member every gate hook runs as temper. Absent, the temper package's
|
|
37
|
+
* bin from the program's `node_modules/.bin` — the gate hook's own default.
|
|
38
|
+
*/
|
|
39
|
+
readonly tool?: Member;
|
|
40
|
+
/**
|
|
41
|
+
* The requirements the gate hooks fill, keyed by the event each hook binds — each entry
|
|
42
|
+
* the `satisfies` edge of that hook alone, never a flat list binding all three, since a
|
|
43
|
+
* requirement may bind the one member that fills it. Absent, none.
|
|
44
|
+
*/
|
|
45
|
+
readonly satisfies?: GateHooksSatisfies;
|
|
46
|
+
}
|
|
47
|
+
/** The requirements each gate hook fills, keyed by the event it binds. */
|
|
48
|
+
export interface GateHooksSatisfies {
|
|
49
|
+
/** The session-start report's claims. */
|
|
50
|
+
readonly SessionStart?: readonly string[];
|
|
51
|
+
/** The guard's file-writing edge's claims. */
|
|
52
|
+
readonly PreToolUse?: readonly string[];
|
|
53
|
+
/** The guard's shell edge's claims. */
|
|
54
|
+
readonly PostToolUse?: readonly string[];
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The three gate hooks: the advisory report at `SessionStart`, the write-boundary guard
|
|
58
|
+
* at `PreToolUse` over the file-writing tools, and the guard's shell edge at
|
|
59
|
+
* `PostToolUse` over `Bash`. Each is a `gateHook(...)` member, so the engine renders its
|
|
60
|
+
* command; the harness's `mode` decides how firmly the guard binds.
|
|
61
|
+
*
|
|
62
|
+
* # Throws
|
|
63
|
+
* If `tool` is not a `tool(...)` member (`gateHook`).
|
|
64
|
+
*/
|
|
65
|
+
export declare function gateHooks(init?: GateHooksInit): readonly Member[];
|
|
66
|
+
/** What {@link typecheck} takes — the project file is the consumer's; the compiler is mechanics. */
|
|
67
|
+
export interface TypecheckInit {
|
|
68
|
+
/** The project file the compiler checks — `input(import.meta.url, "./tsconfig.json")`. */
|
|
69
|
+
readonly project: Input;
|
|
70
|
+
/**
|
|
71
|
+
* The {@link tool} member that runs the compiler. Absent, the program's own TypeScript
|
|
72
|
+
* compiler: `tool({ package: "typescript", bin: "tsc" })`.
|
|
73
|
+
*/
|
|
74
|
+
readonly tool?: Member;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The program's typecheck — the compiler `emit` runs before the program, refusing on a
|
|
78
|
+
* type error. Its `tool` is a member the harness composes in `members`, as {@link defaultPatterns}
|
|
79
|
+
* does.
|
|
80
|
+
*
|
|
81
|
+
* # Throws
|
|
82
|
+
* If `tool` is not a `tool(...)` member.
|
|
83
|
+
*/
|
|
84
|
+
export declare function typecheck(init: TypecheckInit): Typecheck;
|
|
85
|
+
/** What {@link defaultPatterns} takes — one option per shape, each the shape's own init. */
|
|
86
|
+
export interface DefaultPatternsOptions {
|
|
87
|
+
/** The {@link typecheck} — required, since its project file is the consumer's path. */
|
|
88
|
+
readonly typecheck: TypecheckInit;
|
|
89
|
+
/** The {@link gateHooks}' mechanics; absent, their defaults. */
|
|
90
|
+
readonly gates?: GateHooksInit;
|
|
91
|
+
/** The {@link reference}'s description and domains; absent, its defaults. */
|
|
92
|
+
readonly reference?: ReferenceInit;
|
|
93
|
+
/** The {@link playbook}s the harness declares — the consumer's own areas; absent, none. */
|
|
94
|
+
readonly playbooks?: readonly Playbook[];
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* The composed default patterns — the parts `harness()` takes:
|
|
98
|
+
* `harness(defaultPatterns(options))` is a whole program, and a consumer adds its own members by spreading
|
|
99
|
+
* (`harness({ ...base, members: [...base.members, ...mine] })`).
|
|
100
|
+
*/
|
|
101
|
+
export interface DefaultPatterns {
|
|
102
|
+
/** Every tool the shapes run, then the gate hooks, the reference, and each playbook's members. */
|
|
103
|
+
readonly members: readonly Member[];
|
|
104
|
+
/** The program's typecheck, its tool among {@link members}. */
|
|
105
|
+
readonly typecheck: Typecheck;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Compose every mechanics shape with its defaults: the typecheck and its compiler, the
|
|
109
|
+
* three gate hooks and any tool they run, the harness reference, then every playbook given.
|
|
110
|
+
* A tool two shapes share is composed once.
|
|
111
|
+
*/
|
|
112
|
+
export declare function defaultPatterns(options: DefaultPatternsOptions): DefaultPatterns;
|