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,264 @@
|
|
|
1
|
+
import { mkdir, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { dirname, join } from 'node:path';
|
|
3
|
+
import { stringify } from 'yaml';
|
|
4
|
+
import { COMMANDS_DIR, isOpencodeTarget, OPENCODE_V1_TARGET, RULESYNC_HOOKS_FILE, RULESYNC_MCP_FILE, SKILL_FILE_NAME, SKILLS_DIR, } from '../core/constants.js';
|
|
5
|
+
/**
|
|
6
|
+
* Join rule bodies into the persona body, in canonical order. The rule body
|
|
7
|
+
* itself is never re-wrapped or re-indented. This is the only place a persona's
|
|
8
|
+
* rules are carried on either target: there is no shared root rule file.
|
|
9
|
+
*/
|
|
10
|
+
export function personaBody(persona) {
|
|
11
|
+
const sections = persona.rules.map((rule) => {
|
|
12
|
+
// Boundary newlines belong to the file layout, not the rule text; the
|
|
13
|
+
// text between them is never re-wrapped or re-indented.
|
|
14
|
+
const body = rule.body.replace(/^\n+/, '').replace(/\n+$/, '');
|
|
15
|
+
return `## ${rule.displayName}\n\n${body}`;
|
|
16
|
+
});
|
|
17
|
+
// A persona with no rules has an empty body, not a lone newline: `resources`
|
|
18
|
+
// may be empty, and the honest renderer emits no body for it.
|
|
19
|
+
if (sections.length === 0) {
|
|
20
|
+
return '';
|
|
21
|
+
}
|
|
22
|
+
return `${sections.join('\n\n')}\n`;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* A workspace resource body, with only its boundary newlines removed. The
|
|
26
|
+
* newlines around the body are file layout; the text between them is never
|
|
27
|
+
* re-wrapped or re-indented.
|
|
28
|
+
*/
|
|
29
|
+
export function resourceBody(body) {
|
|
30
|
+
return body.replace(/^\n+/, '').replace(/\n+$/, '');
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Whether this persona's source form carries `tools`. The target reads it as an
|
|
34
|
+
* allow-list, so it is emitted only when a permission resource opted in AND at
|
|
35
|
+
* least one entry survived. `claude.allowlist` is that effective decision (see
|
|
36
|
+
* `mapPermissions`), so it is the one place the question is answered; a bare
|
|
37
|
+
* `read: allow` must not silently remove Glob, Grep, WebFetch and every other
|
|
38
|
+
* tool the product does not model.
|
|
39
|
+
*/
|
|
40
|
+
export function emitsTools(persona) {
|
|
41
|
+
return persona.claude.allowlist;
|
|
42
|
+
}
|
|
43
|
+
/** The rulesync tool-scoped section and target id for one OpenCode major. */
|
|
44
|
+
function opencodeSectionKey(target) {
|
|
45
|
+
return target === OPENCODE_V1_TARGET ? 'opencodev1' : 'opencode';
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* The renderer source form for the Claude Code per-agent block. `tools` and
|
|
49
|
+
* `disallowedTools` already hold the harness's own tool names (`Agent`, `Bash`,
|
|
50
|
+
* `Edit`, `Read`, `Write`, and `Bash(P)` for a pattern), never a product category.
|
|
51
|
+
*/
|
|
52
|
+
export function personaFrontmatter(persona) {
|
|
53
|
+
const block = {};
|
|
54
|
+
if (persona.model !== undefined) {
|
|
55
|
+
block.model = persona.model;
|
|
56
|
+
}
|
|
57
|
+
if (emitsTools(persona)) {
|
|
58
|
+
block.tools = persona.claude.allow;
|
|
59
|
+
}
|
|
60
|
+
if (persona.claude.deny.length > 0) {
|
|
61
|
+
block.disallowedTools = persona.claude.deny;
|
|
62
|
+
}
|
|
63
|
+
const frontmatter = {
|
|
64
|
+
name: persona.id,
|
|
65
|
+
targets: ['claudecode'],
|
|
66
|
+
description: persona.purpose,
|
|
67
|
+
};
|
|
68
|
+
if (Object.keys(block).length > 0) {
|
|
69
|
+
frontmatter.claudecode = block;
|
|
70
|
+
}
|
|
71
|
+
return frontmatter;
|
|
72
|
+
}
|
|
73
|
+
export function personaSourceFile(persona) {
|
|
74
|
+
const frontmatter = stringify(personaFrontmatter(persona), { lineWidth: 0 });
|
|
75
|
+
return `---\n${frontmatter}---\n\n${personaBody(persona)}`;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* The renderer source form for an OpenCode per-agent block. The V2 target
|
|
79
|
+
* (`opencode`) emits `description`, `mode`, `model` and the ordered
|
|
80
|
+
* `permissions` array; the V1 target (`opencodev1`) emits `name`,
|
|
81
|
+
* `description`, `mode`, `model` and the per-tool `permission` map. Both are
|
|
82
|
+
* authored from the same resolved permission map under rulesync's canonical
|
|
83
|
+
* category names (`read`, `edit`, `bash`, `task`): the adapter chooses the
|
|
84
|
+
* emitted shape, so the product never restates one target's shape for the
|
|
85
|
+
* other.
|
|
86
|
+
*/
|
|
87
|
+
export function opencodePersonaFrontmatter(persona, target) {
|
|
88
|
+
const section = { mode: 'subagent' };
|
|
89
|
+
if (persona.model !== undefined) {
|
|
90
|
+
section.model = persona.model;
|
|
91
|
+
}
|
|
92
|
+
if (persona.opencode.permission.length > 0) {
|
|
93
|
+
const permission = {};
|
|
94
|
+
for (const category of persona.opencode.permission) {
|
|
95
|
+
const patterns = {};
|
|
96
|
+
for (const [resource, effect] of category.patterns) {
|
|
97
|
+
patterns[resource] = effect;
|
|
98
|
+
}
|
|
99
|
+
permission[category.key] = patterns;
|
|
100
|
+
}
|
|
101
|
+
section.permission = permission;
|
|
102
|
+
}
|
|
103
|
+
const frontmatter = {
|
|
104
|
+
name: persona.id,
|
|
105
|
+
targets: [target],
|
|
106
|
+
description: persona.purpose,
|
|
107
|
+
};
|
|
108
|
+
frontmatter[opencodeSectionKey(target)] = section;
|
|
109
|
+
return frontmatter;
|
|
110
|
+
}
|
|
111
|
+
export function opencodePersonaSourceFile(persona, target) {
|
|
112
|
+
const frontmatter = stringify(opencodePersonaFrontmatter(persona, target), { lineWidth: 0 });
|
|
113
|
+
return `---\n${frontmatter}---\n\n${personaBody(persona)}`;
|
|
114
|
+
}
|
|
115
|
+
/** The rulesync features one render of this source needs, never a wildcard. */
|
|
116
|
+
export function renderFeatures(target, source) {
|
|
117
|
+
if (target === 'claudecode') {
|
|
118
|
+
return ['subagents'];
|
|
119
|
+
}
|
|
120
|
+
const features = ['subagents'];
|
|
121
|
+
if (source.mcp.length > 0) {
|
|
122
|
+
features.push('mcp');
|
|
123
|
+
}
|
|
124
|
+
if (source.skills.length > 0) {
|
|
125
|
+
features.push('skills');
|
|
126
|
+
}
|
|
127
|
+
if (source.commands.length > 0) {
|
|
128
|
+
features.push('commands');
|
|
129
|
+
}
|
|
130
|
+
if (source.hooks.some((hook) => hook.carried)) {
|
|
131
|
+
features.push('hooks');
|
|
132
|
+
}
|
|
133
|
+
return features;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* rulesync's canonical environment reference. The OpenCode adapter converts it
|
|
137
|
+
* to `{env:NAME}`, so the emitted artefact carries a reference and this tool
|
|
138
|
+
* never reads the value.
|
|
139
|
+
*/
|
|
140
|
+
function envReference(value) {
|
|
141
|
+
if (typeof value === 'string') {
|
|
142
|
+
// The loader already refused a literal (F002); this branch cannot be
|
|
143
|
+
// reached from a validated source, and failing loudly is safer than
|
|
144
|
+
// writing a secret value.
|
|
145
|
+
throw new Error('internal invariant violated: a literal reached materialise');
|
|
146
|
+
}
|
|
147
|
+
return `\${${value.fromEnv}}`;
|
|
148
|
+
}
|
|
149
|
+
function referenceRecord(values) {
|
|
150
|
+
if (values === undefined) {
|
|
151
|
+
return undefined;
|
|
152
|
+
}
|
|
153
|
+
const converted = {};
|
|
154
|
+
for (const [key, value] of Object.entries(values)) {
|
|
155
|
+
converted[key] = envReference(value);
|
|
156
|
+
}
|
|
157
|
+
return converted;
|
|
158
|
+
}
|
|
159
|
+
async function writeOpencodeMcp(sourceRoot, source) {
|
|
160
|
+
if (source.mcp.length === 0) {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
const mcpServers = {};
|
|
164
|
+
for (const server of source.mcp) {
|
|
165
|
+
if (server.server.type === 'stdio') {
|
|
166
|
+
const env = referenceRecord(server.server.env);
|
|
167
|
+
mcpServers[server.id] = {
|
|
168
|
+
type: 'stdio',
|
|
169
|
+
command: server.server.command,
|
|
170
|
+
...(server.server.args === undefined ? {} : { args: server.server.args }),
|
|
171
|
+
...(env === undefined ? {} : { env }),
|
|
172
|
+
};
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
const headers = referenceRecord(server.server.headers);
|
|
176
|
+
mcpServers[server.id] = {
|
|
177
|
+
type: 'http',
|
|
178
|
+
url: server.server.url,
|
|
179
|
+
...(headers === undefined ? {} : { headers }),
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
await writeFile(join(sourceRoot, RULESYNC_MCP_FILE), `${JSON.stringify({ mcpServers }, null, 2)}\n`, 'utf8');
|
|
183
|
+
}
|
|
184
|
+
async function writeOpencodeSkills(sourceRoot, source) {
|
|
185
|
+
for (const skill of source.skills) {
|
|
186
|
+
const skillRoot = join(sourceRoot, SKILLS_DIR, skill.id);
|
|
187
|
+
await mkdir(skillRoot, { recursive: true });
|
|
188
|
+
const frontmatter = stringify({ name: skill.id, description: skill.description, targets: [source.target] }, { lineWidth: 0 });
|
|
189
|
+
await writeFile(join(skillRoot, SKILL_FILE_NAME), `---\n${frontmatter}---\n\n${resourceBody(skill.body)}\n`, 'utf8');
|
|
190
|
+
for (const file of skill.files) {
|
|
191
|
+
const absolute = join(skillRoot, ...file.path.split('/'));
|
|
192
|
+
await mkdir(dirname(absolute), { recursive: true });
|
|
193
|
+
await writeFile(absolute, file.text, 'utf8');
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
async function writeOpencodeCommands(sourceRoot, source) {
|
|
198
|
+
for (const command of source.commands) {
|
|
199
|
+
await mkdir(join(sourceRoot, COMMANDS_DIR), { recursive: true });
|
|
200
|
+
const frontmatter = stringify({
|
|
201
|
+
description: command.description,
|
|
202
|
+
targets: [source.target],
|
|
203
|
+
}, { lineWidth: 0 });
|
|
204
|
+
await writeFile(join(sourceRoot, COMMANDS_DIR, `${command.id}.md`), `---\n${frontmatter}---\n\n${resourceBody(command.body)}\n`, 'utf8');
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
const HOOK_EVENT_BY_PHASE = {
|
|
208
|
+
'before-tool': 'preToolUse',
|
|
209
|
+
'after-tool': 'postToolUse',
|
|
210
|
+
'session-start': 'sessionStart',
|
|
211
|
+
stop: 'stop',
|
|
212
|
+
};
|
|
213
|
+
async function writeOpencodeHooks(sourceRoot, source) {
|
|
214
|
+
const hooks = {};
|
|
215
|
+
for (const hook of source.hooks) {
|
|
216
|
+
if (!hook.carried) {
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
const event = HOOK_EVENT_BY_PHASE[hook.phase];
|
|
220
|
+
if (event === undefined) {
|
|
221
|
+
throw new Error(`internal invariant violated: carried hook phase ${hook.phase} has no event`);
|
|
222
|
+
}
|
|
223
|
+
const bucket = hooks[event] ?? [];
|
|
224
|
+
bucket.push({
|
|
225
|
+
...(hook.matcher === undefined ? {} : { matcher: hook.matcher }),
|
|
226
|
+
command: hook.command,
|
|
227
|
+
});
|
|
228
|
+
hooks[event] = bucket;
|
|
229
|
+
}
|
|
230
|
+
if (Object.keys(hooks).length === 0) {
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
await writeFile(join(sourceRoot, RULESYNC_HOOKS_FILE), `${JSON.stringify({ version: 1, hooks }, null, 2)}\n`, 'utf8');
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Write the rulesync-shaped source tree into the stage. One target is rendered
|
|
237
|
+
* per run, so the stage is already target-scoped.
|
|
238
|
+
*
|
|
239
|
+
* On Claude Code a persona is one subagent and nothing else is authored: a
|
|
240
|
+
* shared permission, MCP or hook block would leak one persona's restriction
|
|
241
|
+
* onto every other persona.
|
|
242
|
+
*
|
|
243
|
+
* On OpenCode the MCP server, skill, command and hook declarations are
|
|
244
|
+
* workspace-level, so they are authored once from the union of the live
|
|
245
|
+
* personas rather than per persona. Rules are never authored as a root file:
|
|
246
|
+
* the per-agent body is the only rule carrier.
|
|
247
|
+
*/
|
|
248
|
+
export async function materialiseSourceTree(sourceRoot, source) {
|
|
249
|
+
const subagents = join(sourceRoot, 'subagents');
|
|
250
|
+
await mkdir(subagents, { recursive: true });
|
|
251
|
+
for (const persona of source.personas) {
|
|
252
|
+
const contents = isOpencodeTarget(source.target)
|
|
253
|
+
? opencodePersonaSourceFile(persona, source.target)
|
|
254
|
+
: personaSourceFile(persona);
|
|
255
|
+
await writeFile(join(subagents, `${persona.id}.md`), contents, 'utf8');
|
|
256
|
+
}
|
|
257
|
+
if (!isOpencodeTarget(source.target)) {
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
await writeOpencodeMcp(sourceRoot, source);
|
|
261
|
+
await writeOpencodeSkills(sourceRoot, source);
|
|
262
|
+
await writeOpencodeCommands(sourceRoot, source);
|
|
263
|
+
await writeOpencodeHooks(sourceRoot, source);
|
|
264
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { type Warning } from '../report/warnings.js';
|
|
2
|
+
/**
|
|
3
|
+
* The product's permission vocabulary. This is the only
|
|
4
|
+
* place these words exist; the renderer source tree never receives one of them.
|
|
5
|
+
*/
|
|
6
|
+
export declare const PERMISSION_CATEGORIES: readonly ["read", "write", "edit", "shell", "network", "mcp", "task"];
|
|
7
|
+
export declare const PERMISSION_KEYS: readonly ["read", "write", "edit", "shell", "network", "mcp", "task", "*"];
|
|
8
|
+
export type PermissionCategory = (typeof PERMISSION_CATEGORIES)[number];
|
|
9
|
+
export type PermissionKey = (typeof PERMISSION_KEYS)[number];
|
|
10
|
+
export type PermissionValue = 'allow' | 'ask' | 'deny';
|
|
11
|
+
export type PermissionTools = Partial<Record<PermissionKey, PermissionValue>>;
|
|
12
|
+
export type PermissionPatterns = Partial<Record<PermissionCategory, Record<string, PermissionValue>>>;
|
|
13
|
+
/**
|
|
14
|
+
* The renderer source form for Claude Code's per-agent block is the harness's
|
|
15
|
+
* own tool name, and the emitted byte form is the same string. `Write` is its
|
|
16
|
+
* own tool, distinct from `Edit`; the subagent tool is `Agent` (the former
|
|
17
|
+
* `Task` name is a legacy alias). `network` and a bare `mcp` have no tool.
|
|
18
|
+
*
|
|
19
|
+
* W112 is not emitted here: `write` is native on Claude Code. The lossy
|
|
20
|
+
* `write` -> `edit` collapse belongs to OpenCode.
|
|
21
|
+
*/
|
|
22
|
+
export declare const CLAUDE_TOOL_BY_CATEGORY: Record<'read' | 'write' | 'edit' | 'shell' | 'task', string>;
|
|
23
|
+
export type PermissionContribution = {
|
|
24
|
+
/** The permission resource id, for attribution. */
|
|
25
|
+
id: string;
|
|
26
|
+
tools: PermissionTools;
|
|
27
|
+
patterns: PermissionPatterns;
|
|
28
|
+
/**
|
|
29
|
+
* True when the resource opts its persona into the target's `tools`
|
|
30
|
+
* allow-list. The default is a deny-list: a partial allow set is not an
|
|
31
|
+
* exhaustive allow-list.
|
|
32
|
+
*/
|
|
33
|
+
allowlist: boolean;
|
|
34
|
+
};
|
|
35
|
+
type Winner = {
|
|
36
|
+
value: PermissionValue;
|
|
37
|
+
source: string;
|
|
38
|
+
};
|
|
39
|
+
export type ResolvedPermissions = {
|
|
40
|
+
values: Partial<Record<PermissionCategory, Winner>>;
|
|
41
|
+
patterns: Partial<Record<PermissionCategory, Record<string, Winner>>>;
|
|
42
|
+
/** True when any contributing resource declared `allowlist: true`. */
|
|
43
|
+
allowlist: boolean;
|
|
44
|
+
};
|
|
45
|
+
export type ClaudePermissionEntries = {
|
|
46
|
+
allow: string[];
|
|
47
|
+
deny: string[];
|
|
48
|
+
};
|
|
49
|
+
export declare function emptyResolvedPermissions(): ResolvedPermissions;
|
|
50
|
+
/**
|
|
51
|
+
* Union one permission resource into a persona's resolved map. The stricter
|
|
52
|
+
* value wins and every disagreement is reported (W106).
|
|
53
|
+
*/
|
|
54
|
+
export declare function mergePermission(resolved: ResolvedPermissions, contribution: PermissionContribution, context: {
|
|
55
|
+
persona: string;
|
|
56
|
+
target: string;
|
|
57
|
+
warnings: Warning[];
|
|
58
|
+
}): void;
|
|
59
|
+
/**
|
|
60
|
+
* Refuse a category that has no mapping on the configured target, before
|
|
61
|
+
* anything is materialised. Emitting an inert string is the false negative this
|
|
62
|
+
* product exists to prevent, so an unmapped category is F011, never a
|
|
63
|
+
* passthrough.
|
|
64
|
+
*/
|
|
65
|
+
export declare function assertPermissionCategoriesMappable(resolved: ResolvedPermissions, context: {
|
|
66
|
+
target: string;
|
|
67
|
+
}): void;
|
|
68
|
+
/**
|
|
69
|
+
* Map a persona's resolved permission map onto Claude Code's exact byte form.
|
|
70
|
+
* Every unmapped category refuses with F011 before anything is materialised;
|
|
71
|
+
* `ask` becomes deny (W111). Every mapped category is native here, so no W112.
|
|
72
|
+
*/
|
|
73
|
+
export declare function mapPermissions(resolved: ResolvedPermissions, context: {
|
|
74
|
+
persona: string;
|
|
75
|
+
target: string;
|
|
76
|
+
}): {
|
|
77
|
+
entries: ClaudePermissionEntries;
|
|
78
|
+
allowlist: boolean;
|
|
79
|
+
warnings: Warning[];
|
|
80
|
+
};
|
|
81
|
+
export type OpencodePermissionEffect = 'allow' | 'deny';
|
|
82
|
+
/** One `{ action, resource, effect }` record OpenCode reads, last match wins. */
|
|
83
|
+
export type OpencodePermissionRecord = {
|
|
84
|
+
action: 'read' | 'edit' | 'shell' | 'subagent';
|
|
85
|
+
resource: string;
|
|
86
|
+
effect: OpencodePermissionEffect;
|
|
87
|
+
};
|
|
88
|
+
/** One canonical category as it is written into the rulesync source tree. */
|
|
89
|
+
export type OpencodePermissionCategory = {
|
|
90
|
+
key: 'read' | 'edit' | 'bash' | 'task';
|
|
91
|
+
patterns: Array<[string, OpencodePermissionEffect]>;
|
|
92
|
+
};
|
|
93
|
+
export type OpencodePermissionMapping = {
|
|
94
|
+
/** The rulesync `permission` map, in canonical order. */
|
|
95
|
+
source: OpencodePermissionCategory[];
|
|
96
|
+
/** The records rulesync emits from that map, in the same order. */
|
|
97
|
+
records: OpencodePermissionRecord[];
|
|
98
|
+
warnings: Warning[];
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* Map a persona's resolved permission map onto OpenCode's ordered permission
|
|
102
|
+
* records. Measured at rulesync 43.11.0: `bash` becomes `shell`, `task` becomes
|
|
103
|
+
* `subagent`, and `write` folds into `edit` (there is no write category). The
|
|
104
|
+
* fold is reported as W112 when a write-derived allow is emitted without a
|
|
105
|
+
* matching edit declaration. `ask` becomes deny (W111).
|
|
106
|
+
*
|
|
107
|
+
* OpenCode documents last-match-wins, so record order is semantic. The
|
|
108
|
+
* catch-all is always emitted first and the pattern resources keep the order
|
|
109
|
+
* they were declared in: sorting by codepoint could put an earlier allow after
|
|
110
|
+
* a later deny and silently turn a deny into an allow. The source map and the
|
|
111
|
+
* emitted records are produced together so the containment gate asserts the
|
|
112
|
+
* same order the renderer preserves.
|
|
113
|
+
*/
|
|
114
|
+
export declare function mapOpencodePermissions(resolved: ResolvedPermissions, context: {
|
|
115
|
+
persona: string;
|
|
116
|
+
target: string;
|
|
117
|
+
}): OpencodePermissionMapping;
|
|
118
|
+
/** The digest of one permission resource's declared content. */
|
|
119
|
+
export declare function permissionResourceDigest(tools: PermissionTools, patterns: PermissionPatterns | undefined, allowlist: boolean): string;
|
|
120
|
+
/**
|
|
121
|
+
* The canonical digest input: resolved values and patterns, sorted, plus the
|
|
122
|
+
* allow-list flag that actually decided emission. Passing the effective flag
|
|
123
|
+
* (never the raw opt-in) keeps the digest consistent with the artefact: an
|
|
124
|
+
* opt-in with nothing to allow emits no `tools`, so it must not change the
|
|
125
|
+
* digest either.
|
|
126
|
+
*/
|
|
127
|
+
export declare function permissionDigest(resolved: ResolvedPermissions, allowlist: boolean): string;
|
|
128
|
+
export {};
|