@meridian-flow/mars-schema 0.31.1 → 0.32.1

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.
Files changed (43) hide show
  1. package/README.md +16 -2
  2. package/fixtures/prepare/package-tools/expected.json +213 -0
  3. package/fixtures/prepare/package-tools/input/agents/a.md +7 -0
  4. package/fixtures/prepare/package-tools/input/agents/b.md +4 -0
  5. package/fixtures/prepare/package-tools/input/mars.toml +10 -0
  6. package/fixtures/prepare/package-tools/request.json +3 -0
  7. package/fixtures/prepare/package-tools-invalid/expected.json +112 -0
  8. package/fixtures/prepare/package-tools-invalid/input/agents/b.md +4 -0
  9. package/fixtures/prepare/package-tools-invalid/input/mars.toml +8 -0
  10. package/fixtures/prepare/package-tools-invalid/request.json +3 -0
  11. package/fixtures/project/aliases-reach-one-capability/expected.json +47 -0
  12. package/fixtures/project/aliases-reach-one-capability/request.json +15 -0
  13. package/fixtures/project/claude-allowlist-covered/expected.json +60 -0
  14. package/fixtures/project/claude-allowlist-covered/request.json +20 -0
  15. package/fixtures/project/claude-edit-beats-write/expected.json +53 -0
  16. package/fixtures/project/claude-edit-beats-write/request.json +15 -0
  17. package/fixtures/project/claude-scoped-file-rules/expected.json +68 -0
  18. package/fixtures/project/claude-scoped-file-rules/request.json +20 -0
  19. package/fixtures/project/codex-no-switch-and-absent/expected.json +49 -0
  20. package/fixtures/project/codex-no-switch-and-absent/request.json +20 -0
  21. package/fixtures/project/flow-allowlist/expected.json +44 -0
  22. package/fixtures/project/flow-allowlist/request.json +15 -0
  23. package/fixtures/project/flow-closed-tool-set/expected.json +75 -0
  24. package/fixtures/project/flow-closed-tool-set/request.json +10 -0
  25. package/fixtures/project/flow-gaps-and-ask/expected.json +57 -0
  26. package/fixtures/project/flow-gaps-and-ask/request.json +20 -0
  27. package/fixtures/project/flow-scoped-pattern/expected.json +23 -0
  28. package/fixtures/project/flow-scoped-pattern/request.json +10 -0
  29. package/fixtures/project/flow-write-deny/expected.json +29 -0
  30. package/fixtures/project/flow-write-deny/request.json +10 -0
  31. package/fixtures/project/key-with-pattern/expected.json +68 -0
  32. package/fixtures/project/key-with-pattern/request.json +8 -0
  33. package/fixtures/vocabulary/expected.json +54 -0
  34. package/index.d.ts +55 -0
  35. package/node/mars_schema_wasm.d.ts +7 -0
  36. package/node/mars_schema_wasm.js +27 -0
  37. package/node/mars_schema_wasm_bg.wasm +0 -0
  38. package/node/mars_schema_wasm_bg.wasm.d.ts +1 -0
  39. package/package.json +1 -1
  40. package/web/mars_schema_wasm.d.ts +8 -0
  41. package/web/mars_schema_wasm.js +26 -0
  42. package/web/mars_schema_wasm_bg.wasm +0 -0
  43. package/web/mars_schema_wasm_bg.wasm.d.ts +1 -0
package/index.d.ts CHANGED
@@ -88,6 +88,12 @@ export interface ToolRule {
88
88
  capability: string;
89
89
  pattern: string | null;
90
90
  action: "allow" | "deny" | "ask";
91
+ /**
92
+ * Where the rule came from: `"profile"` (the Agent's own `tools`) or `"package"` (the package's
93
+ * `[package.tools]`, added by `prepare` to an Agent that does not name the key). `read` of one
94
+ * file reports only `"profile"`; the launch bundle also has `"overlay"` and `"project"`.
95
+ */
96
+ origin: "profile" | "package" | "overlay" | "project";
91
97
  }
92
98
 
93
99
  export interface ModelPolicyRule {
@@ -245,6 +251,55 @@ export interface Vocabulary {
245
251
 
246
252
  export function vocabulary(): Vocabulary;
247
253
 
254
+ // ---------------------------------------------------------------------------------------
255
+ // project
256
+ // ---------------------------------------------------------------------------------------
257
+
258
+ export type Host = Harness | "meridian-flow";
259
+
260
+ /** One rule's lowering on a host. */
261
+ export interface ProjectedRule {
262
+ /** The rule as given, in the shape `read` reports it. `origin` is the input's, `"profile"` when it gave none. */
263
+ rule: ToolRule;
264
+ /**
265
+ * `known`: Mars names the tool; `absent`: the host has no such tool; `unknown`: Mars cannot
266
+ * name it (the host has no switch for it, Mars has no row, or it is not a tool Mars knows),
267
+ * with the reason in `note`; `unscopable`: the rule has a pattern and the host's tool takes
268
+ * none. `null` for `*`, which names no tool.
269
+ */
270
+ status: "known" | "absent" | "unknown" | "unscopable" | null;
271
+ /** The permission names the rule keeps. Empty for a gap, and when a stricter rule won every name. */
272
+ native: string[];
273
+ /** The unscoped tool names behind `native`. */
274
+ native_tools: string[];
275
+ /** Why the rule is not applied as written: the gap's reason, or the overlap with a stricter rule. */
276
+ note: string | null;
277
+ /** The stricter rule (`deny bash`) that wins every call or name this rule has. */
278
+ covered_by: { action: "allow" | "deny" | "ask"; key: string } | null;
279
+ }
280
+
281
+ export interface ToolProjection {
282
+ host: Host;
283
+ /** What a tool no rule names gets: the strictest `*` rule's action, or `null` without one. */
284
+ default: "allow" | "deny" | "ask" | null;
285
+ /** In the order given. */
286
+ rules: ProjectedRule[];
287
+ /** The native names that end up allowed, denied and asked, after stricter rules win shared names. */
288
+ allow: string[];
289
+ deny: string[];
290
+ ask: string[];
291
+ /** Every allow and ask rule's names before conflicts were resolved: what an allowlist keeps available. */
292
+ available: string[];
293
+ }
294
+
295
+ /**
296
+ * Lower tool rules (an Agent's `tools` as `prepare` reports it) onto a host, the way `mars sync`
297
+ * does for a harness. Throws `input.invalid` for an unknown host or a rule that does not parse.
298
+ * A consumer must refuse a rule whose `status` is `unscopable` or `unknown` rather than read only
299
+ * `allow`/`deny`/`ask`: an unscopable `read(src/**): deny` leaves `allow: ["read"]` granting every read.
300
+ */
301
+ export function project(rules: { /** A capability, or a whole key such as `bash(git *)` or `Bash(git push:*)` when `pattern` is absent. */ capability: string; pattern?: string | null; action: "allow" | "deny" | "ask"; origin?: ToolRule["origin"] }[], host: Host): ToolProjection;
302
+
248
303
  // ---------------------------------------------------------------------------------------
249
304
  // prepare, inspect, normalize
250
305
  // ---------------------------------------------------------------------------------------
@@ -27,6 +27,13 @@ export function normalize(argument: any): any;
27
27
  */
28
28
  export function prepare(argument: any): any;
29
29
 
30
+ /**
31
+ * Lower tool rules onto a host (`claude`, `codex`, `pi`, `opencode`, `cursor` or
32
+ * `meridian-flow`): the native names per action, each rule's gap or coverage, and how the
33
+ * host handles `ask`. The same code `mars sync` lowers an agent's tools with.
34
+ */
35
+ export function project(rules: any, host: string): any;
36
+
30
37
  /**
31
38
  * Read one schema file. `path` is package-relative and picks the reader: `mars.toml`,
32
39
  * `agents/<slug>.md` or `skills/<slug>/SKILL.md`. Any other path throws.
@@ -104,6 +104,33 @@ function prepare(argument) {
104
104
  }
105
105
  exports.prepare = prepare;
106
106
 
107
+ /**
108
+ * Lower tool rules onto a host (`claude`, `codex`, `pi`, `opencode`, `cursor` or
109
+ * `meridian-flow`): the native names per action, each rule's gap or coverage, and how the
110
+ * host handles `ask`. The same code `mars sync` lowers an agent's tools with.
111
+ * @param {any} rules
112
+ * @param {string} host
113
+ * @returns {any}
114
+ */
115
+ function project(rules, host) {
116
+ try {
117
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
118
+ const ptr0 = passStringToWasm0(host, wasm.__wbindgen_export, wasm.__wbindgen_export2);
119
+ const len0 = WASM_VECTOR_LEN;
120
+ wasm.project(retptr, addHeapObject(rules), ptr0, len0);
121
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
122
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
123
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
124
+ if (r2) {
125
+ throw takeObject(r1);
126
+ }
127
+ return takeObject(r0);
128
+ } finally {
129
+ wasm.__wbindgen_add_to_stack_pointer(16);
130
+ }
131
+ }
132
+ exports.project = project;
133
+
107
134
  /**
108
135
  * Read one schema file. `path` is package-relative and picks the reader: `mars.toml`,
109
136
  * `agents/<slug>.md` or `skills/<slug>/SKILL.md`. Any other path throws.
Binary file
@@ -5,6 +5,7 @@ export const emitValue: (a: number, b: number, c: number) => void;
5
5
  export const inspect: (a: number, b: number) => void;
6
6
  export const normalize: (a: number, b: number) => void;
7
7
  export const prepare: (a: number, b: number) => void;
8
+ export const project: (a: number, b: number, c: number, d: number) => void;
8
9
  export const read: (a: number, b: number, c: number, d: number, e: number) => void;
9
10
  export const renderHooks: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
10
11
  export const rewriteBlock: (a: number, b: number) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meridian-flow/mars-schema",
3
- "version": "0.31.1",
3
+ "version": "0.32.1",
4
4
  "description": "Mars agent schema reader and lossless editor",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -27,6 +27,13 @@ export function normalize(argument: any): any;
27
27
  */
28
28
  export function prepare(argument: any): any;
29
29
 
30
+ /**
31
+ * Lower tool rules onto a host (`claude`, `codex`, `pi`, `opencode`, `cursor` or
32
+ * `meridian-flow`): the native names per action, each rule's gap or coverage, and how the
33
+ * host handles `ask`. The same code `mars sync` lowers an agent's tools with.
34
+ */
35
+ export function project(rules: any, host: string): any;
36
+
30
37
  /**
31
38
  * Read one schema file. `path` is package-relative and picks the reader: `mars.toml`,
32
39
  * `agents/<slug>.md` or `skills/<slug>/SKILL.md`. Any other path throws.
@@ -95,6 +102,7 @@ export interface InitOutput {
95
102
  readonly inspect: (a: number, b: number) => void;
96
103
  readonly normalize: (a: number, b: number) => void;
97
104
  readonly prepare: (a: number, b: number) => void;
105
+ readonly project: (a: number, b: number, c: number, d: number) => void;
98
106
  readonly read: (a: number, b: number, c: number, d: number, e: number) => void;
99
107
  readonly renderHooks: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
100
108
  readonly rewriteBlock: (a: number, b: number) => void;
@@ -100,6 +100,32 @@ export function prepare(argument) {
100
100
  }
101
101
  }
102
102
 
103
+ /**
104
+ * Lower tool rules onto a host (`claude`, `codex`, `pi`, `opencode`, `cursor` or
105
+ * `meridian-flow`): the native names per action, each rule's gap or coverage, and how the
106
+ * host handles `ask`. The same code `mars sync` lowers an agent's tools with.
107
+ * @param {any} rules
108
+ * @param {string} host
109
+ * @returns {any}
110
+ */
111
+ export function project(rules, host) {
112
+ try {
113
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
114
+ const ptr0 = passStringToWasm0(host, wasm.__wbindgen_export, wasm.__wbindgen_export2);
115
+ const len0 = WASM_VECTOR_LEN;
116
+ wasm.project(retptr, addHeapObject(rules), ptr0, len0);
117
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
118
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
119
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
120
+ if (r2) {
121
+ throw takeObject(r1);
122
+ }
123
+ return takeObject(r0);
124
+ } finally {
125
+ wasm.__wbindgen_add_to_stack_pointer(16);
126
+ }
127
+ }
128
+
103
129
  /**
104
130
  * Read one schema file. `path` is package-relative and picks the reader: `mars.toml`,
105
131
  * `agents/<slug>.md` or `skills/<slug>/SKILL.md`. Any other path throws.
Binary file
@@ -5,6 +5,7 @@ export const emitValue: (a: number, b: number, c: number) => void;
5
5
  export const inspect: (a: number, b: number) => void;
6
6
  export const normalize: (a: number, b: number) => void;
7
7
  export const prepare: (a: number, b: number) => void;
8
+ export const project: (a: number, b: number, c: number, d: number) => void;
8
9
  export const read: (a: number, b: number, c: number, d: number, e: number) => void;
9
10
  export const renderHooks: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
10
11
  export const rewriteBlock: (a: number, b: number) => void;