@xenosystem/primitives 0.3.0 → 0.3.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.
- package/README.md +4 -0
- package/dist/cjs/dirs/migrate.js +32 -2
- package/dist/cjs/generated/contract.js +61 -1
- package/dist/esm/dirs/migrate.js +32 -2
- package/dist/esm/generated/contract.js +61 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -16,6 +16,10 @@ Authority: `XENO LOCAL HOME - SPEC.md` (LOCKED). Zero runtime dependencies. Prop
|
|
|
16
16
|
those versions wrote into `~/.xeno` (config, data, secrets and state; cache and run are reported, not copied; links are
|
|
17
17
|
never followed). `resolvePlatformNativeRoots` names the old locations for a product's own migration.
|
|
18
18
|
|
|
19
|
+
**Tree rules (0.3.1):** a product's migration rule may match a whole directory — `match: 'plugins/**'` with target
|
|
20
|
+
segments `['plugins', '{path}']` copies every file below `plugins/`, keeping the structure. Links inside are refused;
|
|
21
|
+
the rule must copy and name the remainder with exactly one `{path}` segment.
|
|
22
|
+
|
|
19
23
|
```ts
|
|
20
24
|
import { createDirs } from '@xenosystem/primitives/dirs';
|
|
21
25
|
import { createSecretStore, createOsKeyStore } from '@xenosystem/primitives/secrets';
|
package/dist/cjs/dirs/migrate.js
CHANGED
|
@@ -26,18 +26,47 @@ function globMatch(pattern, name) {
|
|
|
26
26
|
const re = new RegExp('^' + pattern.split('*').map((s) => s.replace(/[.+?^${}()|[\]\\]/g, '\\$&')).join('.*') + '$');
|
|
27
27
|
return re.test(name);
|
|
28
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* A rule whose `match` ends in `/**` matches every file below that prefix, at any depth (an installed plugin is a
|
|
31
|
+
* tree). Its target names the remainder with one whole `{path}` segment. Links are still never followed.
|
|
32
|
+
*/
|
|
33
|
+
const TREE = '**';
|
|
34
|
+
const PATH_TOKEN = '{path}';
|
|
29
35
|
function matchRule(rule, rel) {
|
|
30
36
|
const want = rule.match.split('/');
|
|
31
37
|
const got = rel.split('/');
|
|
38
|
+
if (want[want.length - 1] === TREE) {
|
|
39
|
+
const prefix = want.slice(0, -1);
|
|
40
|
+
if (got.length <= prefix.length)
|
|
41
|
+
return null;
|
|
42
|
+
for (let i = 0; i < prefix.length; i++)
|
|
43
|
+
if (prefix[i] !== got[i])
|
|
44
|
+
return null;
|
|
45
|
+
return { file: got[got.length - 1], rest: got.slice(prefix.length) };
|
|
46
|
+
}
|
|
32
47
|
if (want.length !== got.length)
|
|
33
48
|
return null;
|
|
34
49
|
for (let i = 0; i < want.length - 1; i++)
|
|
35
50
|
if (want[i] !== got[i])
|
|
36
51
|
return null;
|
|
37
52
|
const last = got[got.length - 1];
|
|
38
|
-
return globMatch(want[want.length - 1], last) ? { file: last } : null;
|
|
53
|
+
return globMatch(want[want.length - 1], last) ? { file: last, rest: [] } : null;
|
|
39
54
|
}
|
|
40
55
|
const fill = (s, file) => s.split('{file}').join(file);
|
|
56
|
+
/** A target's segments with `{file}` filled and a whole `{path}` segment expanded into the matched remainder. */
|
|
57
|
+
const expand = (segments, m) => segments.flatMap((x) => (x === PATH_TOKEN ? m.rest : [fill(x, m.file)]));
|
|
58
|
+
function assertRuleShape(r) {
|
|
59
|
+
const parts = r.match.split('/');
|
|
60
|
+
const tree = parts[parts.length - 1] === TREE;
|
|
61
|
+
if (parts.slice(0, -1).includes(TREE))
|
|
62
|
+
throw new errors_ts_1.DirsError('invalid-argument', `rule ${r.id}: '**' is allowed only as the last segment of match`);
|
|
63
|
+
if (!tree)
|
|
64
|
+
return;
|
|
65
|
+
if (r.action !== 'copy')
|
|
66
|
+
throw new errors_ts_1.DirsError('invalid-argument', `rule ${r.id}: a tree rule ('/**') must copy; a secret is one file`);
|
|
67
|
+
if (r.target.segments.filter((x) => x === PATH_TOKEN).length !== 1)
|
|
68
|
+
throw new errors_ts_1.DirsError('invalid-argument', `rule ${r.id}: a tree rule names the remainder with exactly one '{path}' segment`);
|
|
69
|
+
}
|
|
41
70
|
/** Deterministic id: the same plan (rules, sources, destinations) always has the same journal. */
|
|
42
71
|
function planId(entries) {
|
|
43
72
|
const lines = entries.map((e) => `${e.rule}\t${e.legacyHome}\t${e.sourceRel}\t${e.destRel}`).sort().join('\n');
|
|
@@ -56,6 +85,7 @@ function planMigration(options) {
|
|
|
56
85
|
if (seen.has(r.id))
|
|
57
86
|
throw new errors_ts_1.DirsError('invalid-argument', `duplicate migration rule id: ${r.id}`);
|
|
58
87
|
seen.add(r.id);
|
|
88
|
+
assertRuleShape(r);
|
|
59
89
|
}
|
|
60
90
|
const names = options.legacyHomes ?? contract_ts_1.INPUTS_JSON.legacyHomes;
|
|
61
91
|
const homes = [];
|
|
@@ -136,7 +166,7 @@ function planMigration(options) {
|
|
|
136
166
|
const { rule, m } = hits[0];
|
|
137
167
|
try {
|
|
138
168
|
if (rule.action === 'copy') {
|
|
139
|
-
const segs = rule.target.segments
|
|
169
|
+
const segs = expand(rule.target.segments, m);
|
|
140
170
|
const dest = options.dirs.path(rule.target.kind, rule.target.area, ...segs);
|
|
141
171
|
entries.push({ rule: rule.id, action: 'copy', legacyHome: name, sourceRel: r, source: abs, bytes: s.size, dest, destRel: [rule.target.area, ...segs].join('/'), destKind: rule.target.kind });
|
|
142
172
|
}
|
|
@@ -220,7 +220,7 @@ exports.INPUTS_JSON = {
|
|
|
220
220
|
"$comment2": "secretsKeyService/Account name the single OS-store entry that holds the per-machine master key (spec section 6). The service equals the locked bundle identifier."
|
|
221
221
|
};
|
|
222
222
|
exports.LEGACY_MAP_JSON = {
|
|
223
|
-
"$comment": "Built-in migration rules: legacy file -> registered location. Deliberately minimal: only mappings the ecosystem documents explicitly. Each product owner supplies the rest as rules; anything unmatched is reported as unplaced, never guessed (XENO LOCAL HOME - SPEC.md section 10.6). A 'copy' rule names kind+area+segments; a 'secret' rule names area+name and needs a secret sink. '{file}' stands for the matched file name; only the last path segment of 'match' may contain '*'.",
|
|
223
|
+
"$comment": "Built-in migration rules: legacy file -> registered location. Deliberately minimal: only mappings the ecosystem documents explicitly. Each product owner supplies the rest as rules; anything unmatched is reported as unplaced, never guessed (XENO LOCAL HOME - SPEC.md section 10.6). A 'copy' rule names kind+area+segments; a 'secret' rule names area+name and needs a secret sink. '{file}' stands for the matched file name; only the last path segment of 'match' may contain '*'. A 'match' ending in '/**' (0.3.1) is a tree rule: it matches every file below that prefix at any depth, must be a copy, and names the remainder with exactly one whole '{path}' target segment; links inside the tree are refused, never followed.",
|
|
224
224
|
"rules": [
|
|
225
225
|
{
|
|
226
226
|
"id": "shell-window-state",
|
|
@@ -235,6 +235,66 @@ exports.LEGACY_MAP_JSON = {
|
|
|
235
235
|
]
|
|
236
236
|
},
|
|
237
237
|
"source": "xeno-primitives/ADOPTION.md, xeno-shell row (~/.xeno/shell/state.json -> apps/shell); window state is kind state (LOCAL HOME spec section 5)"
|
|
238
|
+
},
|
|
239
|
+
{
|
|
240
|
+
"id": "extensions-plugins",
|
|
241
|
+
"legacyHome": ".xeno",
|
|
242
|
+
"match": "plugins/**",
|
|
243
|
+
"action": "copy",
|
|
244
|
+
"target": {
|
|
245
|
+
"kind": "data",
|
|
246
|
+
"area": "extensions",
|
|
247
|
+
"segments": [
|
|
248
|
+
"plugins",
|
|
249
|
+
"{path}"
|
|
250
|
+
]
|
|
251
|
+
},
|
|
252
|
+
"source": "XENO LOCAL HOME - SPEC.md section 5 (extensions: config, data, cache) and xeno-primitives/ADOPTION.md 0.3.1: the Agent host plugin/MCP store (xeno-agent-interface PluginMcpManagerService) moves from ~/.xeno/{plugins,mcp}; installed plugins, their registry, trust decisions and event log are one tree owned by the SDK plugin host"
|
|
253
|
+
},
|
|
254
|
+
{
|
|
255
|
+
"id": "extensions-mcp-servers",
|
|
256
|
+
"legacyHome": ".xeno",
|
|
257
|
+
"match": "mcp/servers.json",
|
|
258
|
+
"action": "copy",
|
|
259
|
+
"target": {
|
|
260
|
+
"kind": "config",
|
|
261
|
+
"area": "extensions",
|
|
262
|
+
"segments": [
|
|
263
|
+
"mcp",
|
|
264
|
+
"servers.json"
|
|
265
|
+
]
|
|
266
|
+
},
|
|
267
|
+
"source": "XENO LOCAL HOME - SPEC.md section 5 (extensions: config, data, cache) and xeno-primitives/ADOPTION.md 0.3.1: the Agent host plugin/MCP store (xeno-agent-interface PluginMcpManagerService) moves from ~/.xeno/{plugins,mcp}; MCP server definitions and policies are settings"
|
|
268
|
+
},
|
|
269
|
+
{
|
|
270
|
+
"id": "extensions-mcp-sdk-approvals",
|
|
271
|
+
"legacyHome": ".xeno",
|
|
272
|
+
"match": "mcp/sdk-approvals.json",
|
|
273
|
+
"action": "copy",
|
|
274
|
+
"target": {
|
|
275
|
+
"kind": "config",
|
|
276
|
+
"area": "extensions",
|
|
277
|
+
"segments": [
|
|
278
|
+
"mcp",
|
|
279
|
+
"sdk-approvals.json"
|
|
280
|
+
]
|
|
281
|
+
},
|
|
282
|
+
"source": "XENO LOCAL HOME - SPEC.md section 5 (extensions: config, data, cache) and xeno-primitives/ADOPTION.md 0.3.1: the Agent host plugin/MCP store (xeno-agent-interface PluginMcpManagerService) moves from ~/.xeno/{plugins,mcp}; hash-bound approvals for SDK-configured servers are settings"
|
|
283
|
+
},
|
|
284
|
+
{
|
|
285
|
+
"id": "extensions-mcp-approval-log",
|
|
286
|
+
"legacyHome": ".xeno",
|
|
287
|
+
"match": "mcp/approvals.jsonl",
|
|
288
|
+
"action": "copy",
|
|
289
|
+
"target": {
|
|
290
|
+
"kind": "data",
|
|
291
|
+
"area": "extensions",
|
|
292
|
+
"segments": [
|
|
293
|
+
"mcp",
|
|
294
|
+
"approvals.jsonl"
|
|
295
|
+
]
|
|
296
|
+
},
|
|
297
|
+
"source": "XENO LOCAL HOME - SPEC.md section 5 (extensions: config, data, cache) and xeno-primitives/ADOPTION.md 0.3.1: the Agent host plugin/MCP store (xeno-agent-interface PluginMcpManagerService) moves from ~/.xeno/{plugins,mcp}; the approval audit history cannot be re-created"
|
|
238
298
|
}
|
|
239
299
|
]
|
|
240
300
|
};
|
package/dist/esm/dirs/migrate.js
CHANGED
|
@@ -17,18 +17,47 @@ function globMatch(pattern, name) {
|
|
|
17
17
|
const re = new RegExp('^' + pattern.split('*').map((s) => s.replace(/[.+?^${}()|[\]\\]/g, '\\$&')).join('.*') + '$');
|
|
18
18
|
return re.test(name);
|
|
19
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* A rule whose `match` ends in `/**` matches every file below that prefix, at any depth (an installed plugin is a
|
|
22
|
+
* tree). Its target names the remainder with one whole `{path}` segment. Links are still never followed.
|
|
23
|
+
*/
|
|
24
|
+
const TREE = '**';
|
|
25
|
+
const PATH_TOKEN = '{path}';
|
|
20
26
|
function matchRule(rule, rel) {
|
|
21
27
|
const want = rule.match.split('/');
|
|
22
28
|
const got = rel.split('/');
|
|
29
|
+
if (want[want.length - 1] === TREE) {
|
|
30
|
+
const prefix = want.slice(0, -1);
|
|
31
|
+
if (got.length <= prefix.length)
|
|
32
|
+
return null;
|
|
33
|
+
for (let i = 0; i < prefix.length; i++)
|
|
34
|
+
if (prefix[i] !== got[i])
|
|
35
|
+
return null;
|
|
36
|
+
return { file: got[got.length - 1], rest: got.slice(prefix.length) };
|
|
37
|
+
}
|
|
23
38
|
if (want.length !== got.length)
|
|
24
39
|
return null;
|
|
25
40
|
for (let i = 0; i < want.length - 1; i++)
|
|
26
41
|
if (want[i] !== got[i])
|
|
27
42
|
return null;
|
|
28
43
|
const last = got[got.length - 1];
|
|
29
|
-
return globMatch(want[want.length - 1], last) ? { file: last } : null;
|
|
44
|
+
return globMatch(want[want.length - 1], last) ? { file: last, rest: [] } : null;
|
|
30
45
|
}
|
|
31
46
|
const fill = (s, file) => s.split('{file}').join(file);
|
|
47
|
+
/** A target's segments with `{file}` filled and a whole `{path}` segment expanded into the matched remainder. */
|
|
48
|
+
const expand = (segments, m) => segments.flatMap((x) => (x === PATH_TOKEN ? m.rest : [fill(x, m.file)]));
|
|
49
|
+
function assertRuleShape(r) {
|
|
50
|
+
const parts = r.match.split('/');
|
|
51
|
+
const tree = parts[parts.length - 1] === TREE;
|
|
52
|
+
if (parts.slice(0, -1).includes(TREE))
|
|
53
|
+
throw new DirsError('invalid-argument', `rule ${r.id}: '**' is allowed only as the last segment of match`);
|
|
54
|
+
if (!tree)
|
|
55
|
+
return;
|
|
56
|
+
if (r.action !== 'copy')
|
|
57
|
+
throw new DirsError('invalid-argument', `rule ${r.id}: a tree rule ('/**') must copy; a secret is one file`);
|
|
58
|
+
if (r.target.segments.filter((x) => x === PATH_TOKEN).length !== 1)
|
|
59
|
+
throw new DirsError('invalid-argument', `rule ${r.id}: a tree rule names the remainder with exactly one '{path}' segment`);
|
|
60
|
+
}
|
|
32
61
|
/** Deterministic id: the same plan (rules, sources, destinations) always has the same journal. */
|
|
33
62
|
export function planId(entries) {
|
|
34
63
|
const lines = entries.map((e) => `${e.rule}\t${e.legacyHome}\t${e.sourceRel}\t${e.destRel}`).sort().join('\n');
|
|
@@ -47,6 +76,7 @@ export function planMigration(options) {
|
|
|
47
76
|
if (seen.has(r.id))
|
|
48
77
|
throw new DirsError('invalid-argument', `duplicate migration rule id: ${r.id}`);
|
|
49
78
|
seen.add(r.id);
|
|
79
|
+
assertRuleShape(r);
|
|
50
80
|
}
|
|
51
81
|
const names = options.legacyHomes ?? INPUTS_JSON.legacyHomes;
|
|
52
82
|
const homes = [];
|
|
@@ -127,7 +157,7 @@ export function planMigration(options) {
|
|
|
127
157
|
const { rule, m } = hits[0];
|
|
128
158
|
try {
|
|
129
159
|
if (rule.action === 'copy') {
|
|
130
|
-
const segs = rule.target.segments
|
|
160
|
+
const segs = expand(rule.target.segments, m);
|
|
131
161
|
const dest = options.dirs.path(rule.target.kind, rule.target.area, ...segs);
|
|
132
162
|
entries.push({ rule: rule.id, action: 'copy', legacyHome: name, sourceRel: r, source: abs, bytes: s.size, dest, destRel: [rule.target.area, ...segs].join('/'), destKind: rule.target.kind });
|
|
133
163
|
}
|
|
@@ -217,7 +217,7 @@ export const INPUTS_JSON = {
|
|
|
217
217
|
"$comment2": "secretsKeyService/Account name the single OS-store entry that holds the per-machine master key (spec section 6). The service equals the locked bundle identifier."
|
|
218
218
|
};
|
|
219
219
|
export const LEGACY_MAP_JSON = {
|
|
220
|
-
"$comment": "Built-in migration rules: legacy file -> registered location. Deliberately minimal: only mappings the ecosystem documents explicitly. Each product owner supplies the rest as rules; anything unmatched is reported as unplaced, never guessed (XENO LOCAL HOME - SPEC.md section 10.6). A 'copy' rule names kind+area+segments; a 'secret' rule names area+name and needs a secret sink. '{file}' stands for the matched file name; only the last path segment of 'match' may contain '*'.",
|
|
220
|
+
"$comment": "Built-in migration rules: legacy file -> registered location. Deliberately minimal: only mappings the ecosystem documents explicitly. Each product owner supplies the rest as rules; anything unmatched is reported as unplaced, never guessed (XENO LOCAL HOME - SPEC.md section 10.6). A 'copy' rule names kind+area+segments; a 'secret' rule names area+name and needs a secret sink. '{file}' stands for the matched file name; only the last path segment of 'match' may contain '*'. A 'match' ending in '/**' (0.3.1) is a tree rule: it matches every file below that prefix at any depth, must be a copy, and names the remainder with exactly one whole '{path}' target segment; links inside the tree are refused, never followed.",
|
|
221
221
|
"rules": [
|
|
222
222
|
{
|
|
223
223
|
"id": "shell-window-state",
|
|
@@ -232,6 +232,66 @@ export const LEGACY_MAP_JSON = {
|
|
|
232
232
|
]
|
|
233
233
|
},
|
|
234
234
|
"source": "xeno-primitives/ADOPTION.md, xeno-shell row (~/.xeno/shell/state.json -> apps/shell); window state is kind state (LOCAL HOME spec section 5)"
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
"id": "extensions-plugins",
|
|
238
|
+
"legacyHome": ".xeno",
|
|
239
|
+
"match": "plugins/**",
|
|
240
|
+
"action": "copy",
|
|
241
|
+
"target": {
|
|
242
|
+
"kind": "data",
|
|
243
|
+
"area": "extensions",
|
|
244
|
+
"segments": [
|
|
245
|
+
"plugins",
|
|
246
|
+
"{path}"
|
|
247
|
+
]
|
|
248
|
+
},
|
|
249
|
+
"source": "XENO LOCAL HOME - SPEC.md section 5 (extensions: config, data, cache) and xeno-primitives/ADOPTION.md 0.3.1: the Agent host plugin/MCP store (xeno-agent-interface PluginMcpManagerService) moves from ~/.xeno/{plugins,mcp}; installed plugins, their registry, trust decisions and event log are one tree owned by the SDK plugin host"
|
|
250
|
+
},
|
|
251
|
+
{
|
|
252
|
+
"id": "extensions-mcp-servers",
|
|
253
|
+
"legacyHome": ".xeno",
|
|
254
|
+
"match": "mcp/servers.json",
|
|
255
|
+
"action": "copy",
|
|
256
|
+
"target": {
|
|
257
|
+
"kind": "config",
|
|
258
|
+
"area": "extensions",
|
|
259
|
+
"segments": [
|
|
260
|
+
"mcp",
|
|
261
|
+
"servers.json"
|
|
262
|
+
]
|
|
263
|
+
},
|
|
264
|
+
"source": "XENO LOCAL HOME - SPEC.md section 5 (extensions: config, data, cache) and xeno-primitives/ADOPTION.md 0.3.1: the Agent host plugin/MCP store (xeno-agent-interface PluginMcpManagerService) moves from ~/.xeno/{plugins,mcp}; MCP server definitions and policies are settings"
|
|
265
|
+
},
|
|
266
|
+
{
|
|
267
|
+
"id": "extensions-mcp-sdk-approvals",
|
|
268
|
+
"legacyHome": ".xeno",
|
|
269
|
+
"match": "mcp/sdk-approvals.json",
|
|
270
|
+
"action": "copy",
|
|
271
|
+
"target": {
|
|
272
|
+
"kind": "config",
|
|
273
|
+
"area": "extensions",
|
|
274
|
+
"segments": [
|
|
275
|
+
"mcp",
|
|
276
|
+
"sdk-approvals.json"
|
|
277
|
+
]
|
|
278
|
+
},
|
|
279
|
+
"source": "XENO LOCAL HOME - SPEC.md section 5 (extensions: config, data, cache) and xeno-primitives/ADOPTION.md 0.3.1: the Agent host plugin/MCP store (xeno-agent-interface PluginMcpManagerService) moves from ~/.xeno/{plugins,mcp}; hash-bound approvals for SDK-configured servers are settings"
|
|
280
|
+
},
|
|
281
|
+
{
|
|
282
|
+
"id": "extensions-mcp-approval-log",
|
|
283
|
+
"legacyHome": ".xeno",
|
|
284
|
+
"match": "mcp/approvals.jsonl",
|
|
285
|
+
"action": "copy",
|
|
286
|
+
"target": {
|
|
287
|
+
"kind": "data",
|
|
288
|
+
"area": "extensions",
|
|
289
|
+
"segments": [
|
|
290
|
+
"mcp",
|
|
291
|
+
"approvals.jsonl"
|
|
292
|
+
]
|
|
293
|
+
},
|
|
294
|
+
"source": "XENO LOCAL HOME - SPEC.md section 5 (extensions: config, data, cache) and xeno-primitives/ADOPTION.md 0.3.1: the Agent host plugin/MCP store (xeno-agent-interface PluginMcpManagerService) moves from ~/.xeno/{plugins,mcp}; the approval audit history cannot be re-created"
|
|
235
295
|
}
|
|
236
296
|
]
|
|
237
297
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xenosystem/primitives",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "XENO back-end rung 1 primitives: dirs (the XENO local home), secrets (envelope-encrypted credentials) and updates (the gated app updater).",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"type": "module",
|