farna-bootstrapper 0.0.0-stage → 0.1.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/CHANGELOG.md +91 -0
- package/LICENSE +30 -0
- package/NOTICE +42 -0
- package/README.md +1079 -2
- package/SECURITY.md +65 -0
- package/dist/cli/commands/check.d.ts +58 -0
- package/dist/cli/commands/check.js +198 -0
- package/dist/cli/commands/generate.d.ts +75 -0
- package/dist/cli/commands/generate.js +218 -0
- package/dist/cli/commands/init.d.ts +52 -0
- package/dist/cli/commands/init.js +271 -0
- package/dist/cli/main.d.ts +2 -0
- package/dist/cli/main.js +51 -0
- package/dist/cli/program.d.ts +23 -0
- package/dist/cli/program.js +183 -0
- package/dist/compose/resolve.d.ts +154 -0
- package/dist/compose/resolve.js +545 -0
- package/dist/config/load.d.ts +4 -0
- package/dist/config/load.js +45 -0
- package/dist/config/schema.d.ts +22 -0
- package/dist/config/schema.js +46 -0
- package/dist/core/constants.d.ts +268 -0
- package/dist/core/constants.js +336 -0
- package/dist/core/errors.d.ts +44 -0
- package/dist/core/errors.js +75 -0
- package/dist/core/fs.d.ts +31 -0
- package/dist/core/fs.js +169 -0
- package/dist/core/json.d.ts +22 -0
- package/dist/core/json.js +174 -0
- package/dist/core/paths.d.ts +45 -0
- package/dist/core/paths.js +110 -0
- package/dist/core/text.d.ts +10 -0
- package/dist/core/text.js +27 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +1 -0
- package/dist/lock/lockfile.d.ts +229 -0
- package/dist/lock/lockfile.js +333 -0
- package/dist/materialise/source-tree.d.ts +77 -0
- package/dist/materialise/source-tree.js +264 -0
- package/dist/permissions/permissions.d.ts +128 -0
- package/dist/permissions/permissions.js +452 -0
- package/dist/render/commit.d.ts +59 -0
- package/dist/render/commit.js +279 -0
- package/dist/render/generate-lock.d.ts +9 -0
- package/dist/render/generate-lock.js +203 -0
- package/dist/render/identity.d.ts +23 -0
- package/dist/render/identity.js +396 -0
- package/dist/render/orphans.d.ts +59 -0
- package/dist/render/orphans.js +234 -0
- package/dist/render/port.d.ts +96 -0
- package/dist/render/port.js +1 -0
- package/dist/render/prepare.d.ts +33 -0
- package/dist/render/prepare.js +139 -0
- package/dist/render/root-cleanliness.d.ts +28 -0
- package/dist/render/root-cleanliness.js +76 -0
- package/dist/render/stage.d.ts +36 -0
- package/dist/render/stage.js +92 -0
- package/dist/render/staging.d.ts +16 -0
- package/dist/render/staging.js +94 -0
- package/dist/render/structured.d.ts +35 -0
- package/dist/render/structured.js +258 -0
- package/dist/render/upstream.d.ts +41 -0
- package/dist/render/upstream.js +179 -0
- package/dist/report/format.d.ts +7 -0
- package/dist/report/format.js +97 -0
- package/dist/report/warnings.d.ts +21 -0
- package/dist/report/warnings.js +24 -0
- package/dist/source/digest.d.ts +18 -0
- package/dist/source/digest.js +77 -0
- package/dist/source/frontmatter.d.ts +12 -0
- package/dist/source/frontmatter.js +29 -0
- package/dist/source/load.d.ts +103 -0
- package/dist/source/load.js +676 -0
- package/dist/source/schema.d.ts +149 -0
- package/dist/source/schema.js +283 -0
- package/dist/source/yaml.d.ts +10 -0
- package/dist/source/yaml.js +49 -0
- package/dist/verify/containment.d.ts +22 -0
- package/dist/verify/containment.js +753 -0
- package/package.json +79 -4
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const idSchema: z.ZodString;
|
|
3
|
+
export declare const personaSchema: z.ZodObject<{
|
|
4
|
+
kind: z.ZodLiteral<"persona">;
|
|
5
|
+
id: z.ZodString;
|
|
6
|
+
displayName: z.ZodString;
|
|
7
|
+
purpose: z.ZodString;
|
|
8
|
+
resources: z.ZodArray<z.ZodString>;
|
|
9
|
+
model: z.ZodOptional<z.ZodString>;
|
|
10
|
+
extends: z.ZodOptional<z.ZodString>;
|
|
11
|
+
}, z.core.$strict>;
|
|
12
|
+
/**
|
|
13
|
+
* A rule has no `description`: nothing would emit it, and a field the tool
|
|
14
|
+
* accepts and ignores is the silent no-op this schema exists to reject. A
|
|
15
|
+
* description is F001 (unknown key).
|
|
16
|
+
*/
|
|
17
|
+
export declare const ruleFrontmatterSchema: z.ZodObject<{
|
|
18
|
+
kind: z.ZodLiteral<"rule">;
|
|
19
|
+
id: z.ZodString;
|
|
20
|
+
displayName: z.ZodOptional<z.ZodString>;
|
|
21
|
+
}, z.core.$strict>;
|
|
22
|
+
/**
|
|
23
|
+
* A command's `description` is required. OpenCode's command file carries it,
|
|
24
|
+
* and a command without one cannot be rendered honestly; the missing field is a
|
|
25
|
+
* deliberate F001 at the source boundary rather than a renderer error later.
|
|
26
|
+
*/
|
|
27
|
+
export declare const commandFrontmatterSchema: z.ZodObject<{
|
|
28
|
+
kind: z.ZodLiteral<"command">;
|
|
29
|
+
id: z.ZodString;
|
|
30
|
+
description: z.ZodString;
|
|
31
|
+
}, z.core.$strict>;
|
|
32
|
+
/**
|
|
33
|
+
* A skill's description is required: OpenCode's `SKILL.md` frontmatter carries
|
|
34
|
+
* it, and a skill without one is not loadable by the harness.
|
|
35
|
+
*/
|
|
36
|
+
export declare const skillFrontmatterSchema: z.ZodObject<{
|
|
37
|
+
kind: z.ZodLiteral<"skill">;
|
|
38
|
+
id: z.ZodString;
|
|
39
|
+
description: z.ZodString;
|
|
40
|
+
}, z.core.$strict>;
|
|
41
|
+
/**
|
|
42
|
+
* An environment-variable reference. The value is a variable name, never a
|
|
43
|
+
* secret: a literal in a credential position is `F002_SECRET_LITERAL`.
|
|
44
|
+
*/
|
|
45
|
+
export declare const ENV_NAME_RE: RegExp;
|
|
46
|
+
export declare const envRefSchema: z.ZodObject<{
|
|
47
|
+
fromEnv: z.ZodString;
|
|
48
|
+
}, z.core.$strict>;
|
|
49
|
+
/**
|
|
50
|
+
* The parser accepts either a reference or a literal so the loader can raise
|
|
51
|
+
* the precise security code. A literal never reaches the plan: the loader turns
|
|
52
|
+
* any string value into `F002` naming the field and never echoing the value.
|
|
53
|
+
*/
|
|
54
|
+
declare const envValueSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
55
|
+
fromEnv: z.ZodString;
|
|
56
|
+
}, z.core.$strict>, z.ZodString]>;
|
|
57
|
+
/**
|
|
58
|
+
* One MCP server declaration. `env`, `headers` **and `args`** values may be
|
|
59
|
+
* environment references; the materialiser writes rulesync's canonical
|
|
60
|
+
* `${NAME}` reference, which the OpenCode adapter converts to `{env:NAME}`, so
|
|
61
|
+
* no secret value is ever read by this tool or written into an artefact.
|
|
62
|
+
*
|
|
63
|
+
* `env` and `headers` accept references only: a literal there is `F002`. `args`
|
|
64
|
+
* also accepts literals because a command genuinely needs them (`-y`, `serve`,
|
|
65
|
+
* a path), and a credential-shaped literal is reported as
|
|
66
|
+
* `W116_SECRET_IN_ARGS` instead of being refused.
|
|
67
|
+
*/
|
|
68
|
+
export declare const mcpSchema: z.ZodObject<{
|
|
69
|
+
kind: z.ZodLiteral<"mcp">;
|
|
70
|
+
id: z.ZodString;
|
|
71
|
+
server: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
72
|
+
type: z.ZodLiteral<"stdio">;
|
|
73
|
+
command: z.ZodString;
|
|
74
|
+
args: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
|
|
75
|
+
fromEnv: z.ZodString;
|
|
76
|
+
}, z.core.$strict>, z.ZodString]>>>;
|
|
77
|
+
env: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodObject<{
|
|
78
|
+
fromEnv: z.ZodString;
|
|
79
|
+
}, z.core.$strict>, z.ZodString]>>>;
|
|
80
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
81
|
+
type: z.ZodLiteral<"http">;
|
|
82
|
+
url: z.ZodString;
|
|
83
|
+
headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodObject<{
|
|
84
|
+
fromEnv: z.ZodString;
|
|
85
|
+
}, z.core.$strict>, z.ZodString]>>>;
|
|
86
|
+
}, z.core.$strict>], "type">;
|
|
87
|
+
}, z.core.$strict>;
|
|
88
|
+
export declare const HOOK_PHASES: readonly ["before-tool", "after-tool", "session-start", "session-end", "stop"];
|
|
89
|
+
/**
|
|
90
|
+
* A hook is data, never executed by this tool. The matcher is interpolated
|
|
91
|
+
* into a generated JavaScript `RegExp`, so it must compile here; a malformed
|
|
92
|
+
* matcher would otherwise produce a plugin that throws when it loads.
|
|
93
|
+
*/
|
|
94
|
+
export declare const hookSchema: z.ZodObject<{
|
|
95
|
+
kind: z.ZodLiteral<"hook">;
|
|
96
|
+
id: z.ZodString;
|
|
97
|
+
phase: z.ZodEnum<{
|
|
98
|
+
"before-tool": "before-tool";
|
|
99
|
+
"after-tool": "after-tool";
|
|
100
|
+
"session-start": "session-start";
|
|
101
|
+
"session-end": "session-end";
|
|
102
|
+
stop: "stop";
|
|
103
|
+
}>;
|
|
104
|
+
matcher: z.ZodOptional<z.ZodString>;
|
|
105
|
+
command: z.ZodString;
|
|
106
|
+
}, z.core.$strict>;
|
|
107
|
+
export declare const permissionSchema: z.ZodObject<{
|
|
108
|
+
kind: z.ZodLiteral<"permission">;
|
|
109
|
+
id: z.ZodString;
|
|
110
|
+
tools: z.ZodRecord<z.ZodEnum<{
|
|
111
|
+
mcp: "mcp";
|
|
112
|
+
read: "read";
|
|
113
|
+
write: "write";
|
|
114
|
+
edit: "edit";
|
|
115
|
+
shell: "shell";
|
|
116
|
+
network: "network";
|
|
117
|
+
task: "task";
|
|
118
|
+
"*": "*";
|
|
119
|
+
}> & z.core.$partial, z.ZodEnum<{
|
|
120
|
+
allow: "allow";
|
|
121
|
+
ask: "ask";
|
|
122
|
+
deny: "deny";
|
|
123
|
+
}>>;
|
|
124
|
+
allowlist: z.ZodOptional<z.ZodBoolean>;
|
|
125
|
+
patterns: z.ZodOptional<z.ZodRecord<z.ZodEnum<{
|
|
126
|
+
mcp: "mcp";
|
|
127
|
+
read: "read";
|
|
128
|
+
write: "write";
|
|
129
|
+
edit: "edit";
|
|
130
|
+
shell: "shell";
|
|
131
|
+
network: "network";
|
|
132
|
+
task: "task";
|
|
133
|
+
}> & z.core.$partial, z.ZodRecord<z.ZodString, z.ZodEnum<{
|
|
134
|
+
allow: "allow";
|
|
135
|
+
ask: "ask";
|
|
136
|
+
deny: "deny";
|
|
137
|
+
}>>>>;
|
|
138
|
+
}, z.core.$strict>;
|
|
139
|
+
export type PersonaDeclaration = z.infer<typeof personaSchema>;
|
|
140
|
+
export type RuleFrontmatter = z.infer<typeof ruleFrontmatterSchema>;
|
|
141
|
+
export type CommandFrontmatter = z.infer<typeof commandFrontmatterSchema>;
|
|
142
|
+
export type SkillFrontmatter = z.infer<typeof skillFrontmatterSchema>;
|
|
143
|
+
export type PermissionDeclaration = z.infer<typeof permissionSchema>;
|
|
144
|
+
export type McpDeclaration = z.infer<typeof mcpSchema>;
|
|
145
|
+
export type HookDeclaration = z.infer<typeof hookSchema>;
|
|
146
|
+
export type McpServerDeclaration = McpDeclaration['server'];
|
|
147
|
+
export type EnvValueInput = z.infer<typeof envValueSchema>;
|
|
148
|
+
export type HookPhase = (typeof HOOK_PHASES)[number];
|
|
149
|
+
export {};
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { ID_MAX_LENGTH, ID_RE } from '../core/constants.js';
|
|
3
|
+
import { PERMISSION_CATEGORIES, PERMISSION_KEYS } from '../permissions/permissions.js';
|
|
4
|
+
export const idSchema = z.string().regex(ID_RE, 'must be lower-case kebab-case').max(ID_MAX_LENGTH);
|
|
5
|
+
export const personaSchema = z
|
|
6
|
+
.strictObject({
|
|
7
|
+
kind: z.literal('persona'),
|
|
8
|
+
id: idSchema,
|
|
9
|
+
displayName: z.string().min(1).max(80),
|
|
10
|
+
purpose: z.string().min(1).max(120),
|
|
11
|
+
resources: z.array(z.string().min(1)).max(200),
|
|
12
|
+
model: idSchema.optional(),
|
|
13
|
+
extends: idSchema.optional(),
|
|
14
|
+
})
|
|
15
|
+
.superRefine((persona, ctx) => {
|
|
16
|
+
if (persona.extends === persona.id) {
|
|
17
|
+
ctx.addIssue({
|
|
18
|
+
code: 'custom',
|
|
19
|
+
path: ['extends'],
|
|
20
|
+
message: 'a persona cannot extend itself',
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
const seen = new Set();
|
|
24
|
+
for (const ref of persona.resources) {
|
|
25
|
+
const match = /^([a-z]+)\/(.+)$/.exec(ref);
|
|
26
|
+
if (match === null) {
|
|
27
|
+
ctx.addIssue({
|
|
28
|
+
code: 'custom',
|
|
29
|
+
path: ['resources'],
|
|
30
|
+
message: `"${ref}" is not a "kind/id" reference`,
|
|
31
|
+
});
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
if (seen.has(ref)) {
|
|
35
|
+
ctx.addIssue({
|
|
36
|
+
code: 'custom',
|
|
37
|
+
path: ['resources'],
|
|
38
|
+
message: `duplicate reference "${ref}"`,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
seen.add(ref);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
/**
|
|
45
|
+
* A rule has no `description`: nothing would emit it, and a field the tool
|
|
46
|
+
* accepts and ignores is the silent no-op this schema exists to reject. A
|
|
47
|
+
* description is F001 (unknown key).
|
|
48
|
+
*/
|
|
49
|
+
export const ruleFrontmatterSchema = z.strictObject({
|
|
50
|
+
kind: z.literal('rule'),
|
|
51
|
+
id: idSchema,
|
|
52
|
+
displayName: z.string().min(1).max(80).optional(),
|
|
53
|
+
});
|
|
54
|
+
/**
|
|
55
|
+
* A command's `description` is required. OpenCode's command file carries it,
|
|
56
|
+
* and a command without one cannot be rendered honestly; the missing field is a
|
|
57
|
+
* deliberate F001 at the source boundary rather than a renderer error later.
|
|
58
|
+
*/
|
|
59
|
+
export const commandFrontmatterSchema = z.strictObject({
|
|
60
|
+
kind: z.literal('command'),
|
|
61
|
+
id: idSchema,
|
|
62
|
+
description: z.string().min(1).max(200),
|
|
63
|
+
});
|
|
64
|
+
/**
|
|
65
|
+
* A skill's description is required: OpenCode's `SKILL.md` frontmatter carries
|
|
66
|
+
* it, and a skill without one is not loadable by the harness.
|
|
67
|
+
*/
|
|
68
|
+
export const skillFrontmatterSchema = z.strictObject({
|
|
69
|
+
kind: z.literal('skill'),
|
|
70
|
+
id: idSchema,
|
|
71
|
+
description: z.string().min(1).max(200),
|
|
72
|
+
});
|
|
73
|
+
/**
|
|
74
|
+
* An environment-variable reference. The value is a variable name, never a
|
|
75
|
+
* secret: a literal in a credential position is `F002_SECRET_LITERAL`.
|
|
76
|
+
*/
|
|
77
|
+
export const ENV_NAME_RE = /^[A-Z_][A-Z0-9_]*$/;
|
|
78
|
+
export const envRefSchema = z.strictObject({
|
|
79
|
+
fromEnv: z
|
|
80
|
+
.string()
|
|
81
|
+
.regex(ENV_NAME_RE, 'environment variable names use upper-case letters, digits and underscore'),
|
|
82
|
+
});
|
|
83
|
+
/**
|
|
84
|
+
* The parser accepts either a reference or a literal so the loader can raise
|
|
85
|
+
* the precise security code. A literal never reaches the plan: the loader turns
|
|
86
|
+
* any string value into `F002` naming the field and never echoing the value.
|
|
87
|
+
*/
|
|
88
|
+
const envValueSchema = z.union([envRefSchema, z.string()]);
|
|
89
|
+
/** Whitespace (including control whitespace) and other control characters. */
|
|
90
|
+
function hasWhitespaceOrControl(value) {
|
|
91
|
+
return [...value].some((character) => {
|
|
92
|
+
const code = character.codePointAt(0) ?? 0;
|
|
93
|
+
return code <= 0x20 || code === 0x7f;
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
const envKeySchema = z
|
|
97
|
+
.string()
|
|
98
|
+
.min(1)
|
|
99
|
+
.max(200)
|
|
100
|
+
.refine((key) => key !== '__proto__', '__proto__ is not a valid environment or header name');
|
|
101
|
+
const stdioServerSchema = z.strictObject({
|
|
102
|
+
type: z.literal('stdio'),
|
|
103
|
+
command: z
|
|
104
|
+
.string()
|
|
105
|
+
.min(1)
|
|
106
|
+
.max(2048)
|
|
107
|
+
.refine((command) => !hasWhitespaceOrControl(command), 'command must be the program only; put its arguments in args'),
|
|
108
|
+
// An argument is either a literal the server needs (`-y`, a path) or an
|
|
109
|
+
// environment reference. `args` is not a declared credential position, so a
|
|
110
|
+
// literal is allowed — but a credential-shaped one is reported as W116 rather
|
|
111
|
+
// than silently written into `opencode.jsonc`, and `{ "fromEnv": "NAME" }` is
|
|
112
|
+
// the supported way to pass a secret.
|
|
113
|
+
args: z
|
|
114
|
+
.array(z.union([envRefSchema, z.string().max(2048)]))
|
|
115
|
+
.max(64)
|
|
116
|
+
.optional(),
|
|
117
|
+
env: z.record(envKeySchema, envValueSchema).optional(),
|
|
118
|
+
});
|
|
119
|
+
const httpServerSchema = z.strictObject({
|
|
120
|
+
type: z.literal('http'),
|
|
121
|
+
url: z
|
|
122
|
+
.string()
|
|
123
|
+
.max(2048)
|
|
124
|
+
.refine((value) => {
|
|
125
|
+
try {
|
|
126
|
+
const parsed = new URL(value);
|
|
127
|
+
return parsed.protocol === 'http:' || parsed.protocol === 'https:';
|
|
128
|
+
}
|
|
129
|
+
catch {
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
}, 'an http MCP server needs an absolute http or https URL'),
|
|
133
|
+
headers: z.record(envKeySchema, envValueSchema).optional(),
|
|
134
|
+
});
|
|
135
|
+
/**
|
|
136
|
+
* One MCP server declaration. `env`, `headers` **and `args`** values may be
|
|
137
|
+
* environment references; the materialiser writes rulesync's canonical
|
|
138
|
+
* `${NAME}` reference, which the OpenCode adapter converts to `{env:NAME}`, so
|
|
139
|
+
* no secret value is ever read by this tool or written into an artefact.
|
|
140
|
+
*
|
|
141
|
+
* `env` and `headers` accept references only: a literal there is `F002`. `args`
|
|
142
|
+
* also accepts literals because a command genuinely needs them (`-y`, `serve`,
|
|
143
|
+
* a path), and a credential-shaped literal is reported as
|
|
144
|
+
* `W116_SECRET_IN_ARGS` instead of being refused.
|
|
145
|
+
*/
|
|
146
|
+
export const mcpSchema = z.strictObject({
|
|
147
|
+
kind: z.literal('mcp'),
|
|
148
|
+
id: idSchema,
|
|
149
|
+
server: z.discriminatedUnion('type', [stdioServerSchema, httpServerSchema]),
|
|
150
|
+
});
|
|
151
|
+
export const HOOK_PHASES = [
|
|
152
|
+
'before-tool',
|
|
153
|
+
'after-tool',
|
|
154
|
+
'session-start',
|
|
155
|
+
'session-end',
|
|
156
|
+
'stop',
|
|
157
|
+
];
|
|
158
|
+
/**
|
|
159
|
+
* A hook is data, never executed by this tool. The matcher is interpolated
|
|
160
|
+
* into a generated JavaScript `RegExp`, so it must compile here; a malformed
|
|
161
|
+
* matcher would otherwise produce a plugin that throws when it loads.
|
|
162
|
+
*/
|
|
163
|
+
export const hookSchema = z
|
|
164
|
+
.strictObject({
|
|
165
|
+
kind: z.literal('hook'),
|
|
166
|
+
id: idSchema,
|
|
167
|
+
phase: z.enum(HOOK_PHASES),
|
|
168
|
+
matcher: z.string().min(1).max(200).optional(),
|
|
169
|
+
command: z.string().min(1).max(2000),
|
|
170
|
+
})
|
|
171
|
+
.superRefine((hook, ctx) => {
|
|
172
|
+
if (/[\n\r\0]/.test(hook.command)) {
|
|
173
|
+
ctx.addIssue({
|
|
174
|
+
code: 'custom',
|
|
175
|
+
path: ['command'],
|
|
176
|
+
message: 'command cannot contain a newline or NUL',
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
if (hook.matcher === undefined) {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
if (/[\n\r\0]/.test(hook.matcher)) {
|
|
183
|
+
ctx.addIssue({
|
|
184
|
+
code: 'custom',
|
|
185
|
+
path: ['matcher'],
|
|
186
|
+
message: 'matcher cannot contain a newline or NUL',
|
|
187
|
+
});
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
try {
|
|
191
|
+
new RegExp(hook.matcher);
|
|
192
|
+
}
|
|
193
|
+
catch {
|
|
194
|
+
ctx.addIssue({
|
|
195
|
+
code: 'custom',
|
|
196
|
+
path: ['matcher'],
|
|
197
|
+
message: 'matcher is not a valid regular expression',
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
const permissionValueSchema = z.enum(['allow', 'ask', 'deny']);
|
|
202
|
+
const permissionValueMapSchema = z
|
|
203
|
+
.partialRecord(z.enum(PERMISSION_KEYS), permissionValueSchema)
|
|
204
|
+
.refine((tools) => Object.keys(tools).length >= 1, 'a permission resource declares at least one category')
|
|
205
|
+
.refine((tools) => Object.keys(tools).length <= 16, 'a permission resource declares at most sixteen categories');
|
|
206
|
+
/**
|
|
207
|
+
* A pattern is interpolated verbatim into the target's `Tool(pattern)` grammar.
|
|
208
|
+
* A pattern carrying `)` or `,` would change the entry's meaning, a newline or
|
|
209
|
+
* control character would break the line-oriented frontmatter, and padding is
|
|
210
|
+
* never intentional. All are refused at the source boundary rather than escaped,
|
|
211
|
+
* because the harness's grammar has no escaping this tool can verify.
|
|
212
|
+
*/
|
|
213
|
+
function describePatternProblem(pattern) {
|
|
214
|
+
if (pattern !== pattern.trim()) {
|
|
215
|
+
return 'pattern has leading or trailing whitespace';
|
|
216
|
+
}
|
|
217
|
+
const hasControl = [...pattern].some((character) => {
|
|
218
|
+
const code = character.codePointAt(0) ?? 0;
|
|
219
|
+
return code <= 0x1f || code === 0x7f;
|
|
220
|
+
});
|
|
221
|
+
if (hasControl) {
|
|
222
|
+
return 'pattern contains a newline or control character';
|
|
223
|
+
}
|
|
224
|
+
if (pattern.includes(')') || pattern.includes(',')) {
|
|
225
|
+
return 'pattern cannot contain ")" or ",": it is interpolated into the target grammar Tool(pattern) and is not representable';
|
|
226
|
+
}
|
|
227
|
+
return undefined;
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* JavaScript enumerates an object's own keys with every canonical array index
|
|
231
|
+
* (`0`, `1`, `10`, ...) first, in ascending numeric order, and only then the
|
|
232
|
+
* remaining string keys in insertion order. A pattern map is a plain object all
|
|
233
|
+
* the way to the renderer, so a numeric pattern such as `"10"` would silently
|
|
234
|
+
* move ahead of the patterns declared before it. OpenCode's last-match-wins
|
|
235
|
+
* makes that a permission change, and the digest (which records the declared
|
|
236
|
+
* order) would be identical for both spellings. Refuse the key at the source
|
|
237
|
+
* boundary rather than emit an order the source did not declare.
|
|
238
|
+
*/
|
|
239
|
+
const CANONICAL_ARRAY_INDEX_RE = /^(0|[1-9]\d*)$/;
|
|
240
|
+
const patternRecordSchema = z
|
|
241
|
+
.record(z.string().min(1).max(200), permissionValueSchema)
|
|
242
|
+
.superRefine((record, ctx) => {
|
|
243
|
+
for (const pattern of Object.keys(record)) {
|
|
244
|
+
if (CANONICAL_ARRAY_INDEX_RE.test(pattern)) {
|
|
245
|
+
ctx.addIssue({
|
|
246
|
+
code: 'custom',
|
|
247
|
+
path: [pattern],
|
|
248
|
+
message: `integer-like pattern key "${pattern}" cannot preserve declaration order: JavaScript enumerates canonical array-index keys first, so it would be emitted ahead of the patterns declared before it; use a non-numeric key such as "**/${pattern}/**" or another pattern that is not a bare integer`,
|
|
249
|
+
});
|
|
250
|
+
continue;
|
|
251
|
+
}
|
|
252
|
+
const problem = describePatternProblem(pattern);
|
|
253
|
+
if (problem !== undefined) {
|
|
254
|
+
ctx.addIssue({ code: 'custom', path: [pattern], message: problem });
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
const permissionPatternMapSchema = z.partialRecord(z.enum(PERMISSION_CATEGORIES), patternRecordSchema);
|
|
259
|
+
export const permissionSchema = z
|
|
260
|
+
.strictObject({
|
|
261
|
+
kind: z.literal('permission'),
|
|
262
|
+
id: idSchema,
|
|
263
|
+
tools: permissionValueMapSchema,
|
|
264
|
+
/**
|
|
265
|
+
* Opt in to Claude Code's `tools` allow-list. The default is a deny-list:
|
|
266
|
+
* an allow entry grants nothing extra, but a partial `tools` list removes
|
|
267
|
+
* every tool it does not name. Only `true` narrows the persona.
|
|
268
|
+
*/
|
|
269
|
+
allowlist: z.boolean().optional(),
|
|
270
|
+
patterns: permissionPatternMapSchema.optional(),
|
|
271
|
+
})
|
|
272
|
+
.superRefine((permission, ctx) => {
|
|
273
|
+
if (permission.tools['*'] !== undefined) {
|
|
274
|
+
const combined = Object.keys(permission.tools).filter((key) => key !== '*');
|
|
275
|
+
if (combined.length > 0) {
|
|
276
|
+
ctx.addIssue({
|
|
277
|
+
code: 'custom',
|
|
278
|
+
path: ['tools'],
|
|
279
|
+
message: '"*" cannot be combined with a specific category',
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type ParseYamlOptions = {
|
|
2
|
+
subject: string;
|
|
3
|
+
};
|
|
4
|
+
/**
|
|
5
|
+
* Parse one plain YAML document with duplicate keys rejected, anchors,
|
|
6
|
+
* aliases and custom tags refused. A stream with a second document is refused:
|
|
7
|
+
* parsing only the first would silently discard everything after `---`.
|
|
8
|
+
* Returns the document's plain value.
|
|
9
|
+
*/
|
|
10
|
+
export declare function parseYamlStrict<T = unknown>(text: string, options: ParseYamlOptions): T;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Alias, parseAllDocuments, visit } from 'yaml';
|
|
2
|
+
import { invalidConfig } from '../core/errors.js';
|
|
3
|
+
const CORE_TAG_PREFIX = 'tag:yaml.org,2002:';
|
|
4
|
+
function assertNoExoticNodes(document, subject) {
|
|
5
|
+
visit(document, {
|
|
6
|
+
Node(_key, node) {
|
|
7
|
+
if (node instanceof Alias) {
|
|
8
|
+
throw invalidConfig('YAML aliases are not allowed', {
|
|
9
|
+
subject,
|
|
10
|
+
action: 'write the value out in full',
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
if (node.anchor !== undefined) {
|
|
14
|
+
throw invalidConfig('YAML anchors are not allowed', {
|
|
15
|
+
subject,
|
|
16
|
+
action: 'write the value out in full',
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
if (node.tag !== undefined && !String(node.tag).startsWith(CORE_TAG_PREFIX)) {
|
|
20
|
+
throw invalidConfig('YAML custom tags are not allowed', { subject });
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Parse one plain YAML document with duplicate keys rejected, anchors,
|
|
27
|
+
* aliases and custom tags refused. A stream with a second document is refused:
|
|
28
|
+
* parsing only the first would silently discard everything after `---`.
|
|
29
|
+
* Returns the document's plain value.
|
|
30
|
+
*/
|
|
31
|
+
export function parseYamlStrict(text, options) {
|
|
32
|
+
const documents = parseAllDocuments(text, {
|
|
33
|
+
uniqueKeys: true,
|
|
34
|
+
schema: 'core',
|
|
35
|
+
logLevel: 'silent',
|
|
36
|
+
});
|
|
37
|
+
const document = documents[0];
|
|
38
|
+
if (documents.length !== 1 || document === undefined) {
|
|
39
|
+
throw invalidConfig(`file contains ${documents.length} YAML documents; exactly one is required`, {
|
|
40
|
+
subject: options.subject,
|
|
41
|
+
action: 'keep one document per file and put each additional declaration in its own file',
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
for (const error of document.errors) {
|
|
45
|
+
throw invalidConfig(error.message, { subject: options.subject });
|
|
46
|
+
}
|
|
47
|
+
assertNoExoticNodes(document, options.subject);
|
|
48
|
+
return document.toJS();
|
|
49
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ResolvedSource } from '../compose/resolve.js';
|
|
2
|
+
import { type SupportedTarget } from '../core/constants.js';
|
|
3
|
+
import type { RenderResult } from '../render/port.js';
|
|
4
|
+
export declare function expectedAgentPath(target: SupportedTarget, personaId: string): string;
|
|
5
|
+
/**
|
|
6
|
+
* The exact set of managed paths a target renders. The set is derived from the
|
|
7
|
+
* plan, never from `RenderResult`: the renderer's own path list is what the
|
|
8
|
+
* gate is checking, so it cannot also define the expectation.
|
|
9
|
+
*/
|
|
10
|
+
export declare function expectedPaths(source: ResolvedSource): string[];
|
|
11
|
+
/**
|
|
12
|
+
* The containment gate. Every expected artefact is a non-empty file whose
|
|
13
|
+
* frontmatter key set and values equal the resolved persona, and whose body is
|
|
14
|
+
* exactly the persona's composed body (one trailing newline normalised). On
|
|
15
|
+
* OpenCode the workspace files are verified against the resolved resources too.
|
|
16
|
+
*
|
|
17
|
+
* Returns the exact bytes it verified, keyed by managed path. The caller writes
|
|
18
|
+
* THESE bytes: re-reading the stage after verification would let a renderer (or
|
|
19
|
+
* a concurrent writer) change the file between the gate and the write, so the
|
|
20
|
+
* bytes that were checked would not be the bytes that landed.
|
|
21
|
+
*/
|
|
22
|
+
export declare function verifyRender(source: ResolvedSource, render: RenderResult, outputRoot: string): Promise<Map<string, string>>;
|