@xenosystem/primitives 0.0.0-stage → 0.2.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.
Files changed (107) hide show
  1. package/README.md +29 -2
  2. package/dist/cjs/dirs/atomic.d.ts +9 -0
  3. package/dist/cjs/dirs/atomic.js +59 -0
  4. package/dist/cjs/dirs/check-cli.d.ts +2 -0
  5. package/dist/cjs/dirs/check-cli.js +50 -0
  6. package/dist/cjs/dirs/check.d.ts +49 -0
  7. package/dist/cjs/dirs/check.js +158 -0
  8. package/dist/cjs/dirs/cli.d.ts +2 -0
  9. package/dist/cjs/dirs/cli.js +72 -0
  10. package/dist/cjs/dirs/dirs.d.ts +57 -0
  11. package/dist/cjs/dirs/dirs.js +135 -0
  12. package/dist/cjs/dirs/doctor.d.ts +31 -0
  13. package/dist/cjs/dirs/doctor.js +80 -0
  14. package/dist/cjs/dirs/errors.d.ts +8 -0
  15. package/dist/cjs/dirs/errors.js +19 -0
  16. package/dist/cjs/dirs/host.d.ts +4 -0
  17. package/dist/cjs/dirs/host.js +26 -0
  18. package/dist/cjs/dirs/index.d.ts +13 -0
  19. package/dist/cjs/dirs/index.js +55 -0
  20. package/dist/cjs/dirs/inputs.d.ts +14 -0
  21. package/dist/cjs/dirs/inputs.js +14 -0
  22. package/dist/cjs/dirs/layout.d.ts +16 -0
  23. package/dist/cjs/dirs/layout.js +25 -0
  24. package/dist/cjs/dirs/lock.d.ts +38 -0
  25. package/dist/cjs/dirs/lock.js +128 -0
  26. package/dist/cjs/dirs/migrate.d.ts +134 -0
  27. package/dist/cjs/dirs/migrate.js +437 -0
  28. package/dist/cjs/dirs/procinfo.d.ts +10 -0
  29. package/dist/cjs/dirs/procinfo.js +67 -0
  30. package/dist/cjs/dirs/registry.d.ts +27 -0
  31. package/dist/cjs/dirs/registry.js +78 -0
  32. package/dist/cjs/dirs/roots.d.ts +23 -0
  33. package/dist/cjs/dirs/roots.js +114 -0
  34. package/dist/cjs/dirs/segments.d.ts +7 -0
  35. package/dist/cjs/dirs/segments.js +39 -0
  36. package/dist/cjs/generated/contract.d.ts +134 -0
  37. package/dist/cjs/generated/contract.js +233 -0
  38. package/dist/cjs/package.json +1 -0
  39. package/dist/cjs/secrets/envelope.d.ts +37 -0
  40. package/dist/cjs/secrets/envelope.js +90 -0
  41. package/dist/cjs/secrets/errors.d.ts +10 -0
  42. package/dist/cjs/secrets/errors.js +20 -0
  43. package/dist/cjs/secrets/index.d.ts +4 -0
  44. package/dist/cjs/secrets/index.js +17 -0
  45. package/dist/cjs/secrets/keystore.d.ts +37 -0
  46. package/dist/cjs/secrets/keystore.js +41 -0
  47. package/dist/cjs/secrets/os-stores.d.ts +17 -0
  48. package/dist/cjs/secrets/os-stores.js +195 -0
  49. package/dist/cjs/secrets/store.d.ts +32 -0
  50. package/dist/cjs/secrets/store.js +161 -0
  51. package/dist/cjs/secrets/testing.d.ts +5 -0
  52. package/dist/cjs/secrets/testing.js +20 -0
  53. package/dist/cjs/updates/index.d.ts +67 -0
  54. package/dist/cjs/updates/index.js +102 -0
  55. package/dist/esm/dirs/atomic.d.ts +9 -0
  56. package/dist/esm/dirs/atomic.js +56 -0
  57. package/dist/esm/dirs/check-cli.d.ts +2 -0
  58. package/dist/esm/dirs/check-cli.js +48 -0
  59. package/dist/esm/dirs/check.d.ts +49 -0
  60. package/dist/esm/dirs/check.js +152 -0
  61. package/dist/esm/dirs/cli.d.ts +2 -0
  62. package/dist/esm/dirs/cli.js +70 -0
  63. package/dist/esm/dirs/dirs.d.ts +57 -0
  64. package/dist/esm/dirs/dirs.js +129 -0
  65. package/dist/esm/dirs/doctor.d.ts +31 -0
  66. package/dist/esm/dirs/doctor.js +77 -0
  67. package/dist/esm/dirs/errors.d.ts +8 -0
  68. package/dist/esm/dirs/errors.js +14 -0
  69. package/dist/esm/dirs/host.d.ts +4 -0
  70. package/dist/esm/dirs/host.js +21 -0
  71. package/dist/esm/dirs/index.d.ts +13 -0
  72. package/dist/esm/dirs/index.js +13 -0
  73. package/dist/esm/dirs/inputs.d.ts +14 -0
  74. package/dist/esm/dirs/inputs.js +11 -0
  75. package/dist/esm/dirs/layout.d.ts +16 -0
  76. package/dist/esm/dirs/layout.js +21 -0
  77. package/dist/esm/dirs/lock.d.ts +38 -0
  78. package/dist/esm/dirs/lock.js +124 -0
  79. package/dist/esm/dirs/migrate.d.ts +134 -0
  80. package/dist/esm/dirs/migrate.js +428 -0
  81. package/dist/esm/dirs/procinfo.d.ts +10 -0
  82. package/dist/esm/dirs/procinfo.js +62 -0
  83. package/dist/esm/dirs/registry.d.ts +27 -0
  84. package/dist/esm/dirs/registry.js +71 -0
  85. package/dist/esm/dirs/roots.d.ts +23 -0
  86. package/dist/esm/dirs/roots.js +107 -0
  87. package/dist/esm/dirs/segments.d.ts +7 -0
  88. package/dist/esm/dirs/segments.js +35 -0
  89. package/dist/esm/generated/contract.d.ts +134 -0
  90. package/dist/esm/generated/contract.js +230 -0
  91. package/dist/esm/secrets/envelope.d.ts +37 -0
  92. package/dist/esm/secrets/envelope.js +81 -0
  93. package/dist/esm/secrets/errors.d.ts +10 -0
  94. package/dist/esm/secrets/errors.js +15 -0
  95. package/dist/esm/secrets/index.d.ts +4 -0
  96. package/dist/esm/secrets/index.js +4 -0
  97. package/dist/esm/secrets/keystore.d.ts +37 -0
  98. package/dist/esm/secrets/keystore.js +37 -0
  99. package/dist/esm/secrets/os-stores.d.ts +17 -0
  100. package/dist/esm/secrets/os-stores.js +189 -0
  101. package/dist/esm/secrets/store.d.ts +32 -0
  102. package/dist/esm/secrets/store.js +156 -0
  103. package/dist/esm/secrets/testing.d.ts +5 -0
  104. package/dist/esm/secrets/testing.js +12 -0
  105. package/dist/esm/updates/index.d.ts +67 -0
  106. package/dist/esm/updates/index.js +97 -0
  107. package/package.json +42 -4
@@ -0,0 +1,71 @@
1
+ import { REGISTRY_JSON } from "../generated/contract.js";
2
+ import { DirsError } from "./errors.js";
3
+ import { KINDS } from "./roots.js";
4
+ import { assertSegment } from "./segments.js";
5
+ export const AREAS = REGISTRY_JSON.areas;
6
+ export const LOCK_SUFFIX = REGISTRY_JSON.locks.suffix;
7
+ const isKind = (k) => KINDS.includes(k);
8
+ /** Finds the registered entry for a concrete area name, or null. `apps/<slug>` matches by slug pattern. */
9
+ export function findArea(area) {
10
+ for (const entry of AREAS) {
11
+ if (entry.slugPattern !== undefined) {
12
+ const prefix = entry.area.slice(0, entry.area.indexOf('<'));
13
+ if (area.startsWith(prefix) && new RegExp(entry.slugPattern).test(area.slice(prefix.length)))
14
+ return entry;
15
+ }
16
+ else if (entry.area === area)
17
+ return entry;
18
+ }
19
+ return null;
20
+ }
21
+ /**
22
+ * Resolves (kind, area, segments) against the registry and returns the path relative to the kind root with `/`
23
+ * separators. Refuses anything unregistered. A `run` entry for an area that does not use `run` accepts locks only.
24
+ */
25
+ export function registeredRelativePath(kind, area, segments) {
26
+ if (!isKind(kind))
27
+ throw new DirsError('unregistered-area', 'unknown kind', { kind });
28
+ const entry = findArea(area);
29
+ if (entry === null)
30
+ throw new DirsError('unregistered-area', `area is not registered: ${JSON.stringify(area)}`, { area });
31
+ if (!entry.uses.includes(kind)) {
32
+ if (kind === 'run')
33
+ throw new DirsError('locks-only', `run/${area} holds lock files only; use lockPath`, { area });
34
+ throw new DirsError('kind-not-used', `area ${area} does not use kind ${kind}`, { area, kind });
35
+ }
36
+ for (const s of segments)
37
+ assertSegment(s);
38
+ return [area, ...segments].join('/');
39
+ }
40
+ /** Relative path of a lock file under the run root. Every registered area may hold locks (spec section 8). */
41
+ export function lockRelativePath(area, name) {
42
+ const entry = findArea(area);
43
+ if (entry === null)
44
+ throw new DirsError('unregistered-area', `area is not registered: ${JSON.stringify(area)}`, { area });
45
+ assertSegment(name, 'lock name');
46
+ return `${area}/${name}${LOCK_SUFFIX}`;
47
+ }
48
+ /** Top-level directory names a root may legitimately hold, derived from the registry (used by doctor). */
49
+ export function expectedTopLevel(kind) {
50
+ const names = new Set();
51
+ const nested = new Map();
52
+ let appSlugs = false;
53
+ for (const e of AREAS) {
54
+ if (!e.uses.includes(kind) && kind !== 'run')
55
+ continue;
56
+ const parts = e.area.split('/');
57
+ const top = parts[0];
58
+ if (e.slugPattern !== undefined) {
59
+ appSlugs = true;
60
+ names.add(top);
61
+ continue;
62
+ }
63
+ names.add(top);
64
+ if (parts.length > 1) {
65
+ const set = nested.get(top) ?? new Set();
66
+ set.add(parts.slice(1).join('/'));
67
+ nested.set(top, set);
68
+ }
69
+ }
70
+ return { names, appSlugs, nested };
71
+ }
@@ -0,0 +1,23 @@
1
+ export type Platform = 'windows' | 'macos' | 'linux';
2
+ export type Kind = 'config' | 'data' | 'secrets' | 'state' | 'cache' | 'run';
3
+ export declare const KINDS: readonly Kind[];
4
+ export interface ResolveInput {
5
+ platform: Platform;
6
+ /** The person's home directory. Only consulted when no override supplies a location. */
7
+ home: string;
8
+ env: Readonly<Record<string, string | undefined>>;
9
+ }
10
+ export interface ResolvedRoots {
11
+ platform: Platform;
12
+ roots: Readonly<Record<Kind, string>>;
13
+ /** Sorted, `code` or `code:detail`. */
14
+ warnings: readonly string[];
15
+ /** True when XENO_HOME supplied the layout. */
16
+ overridden: boolean;
17
+ }
18
+ export declare const SEP: Readonly<Record<Platform, string>>;
19
+ export declare function isAbsolutePath(platform: Platform, p: string): boolean;
20
+ /** Normalises separators and drops trailing ones, so `base + sep + name` is always well formed. */
21
+ export declare function normalizeBase(platform: Platform, p: string): string;
22
+ export declare function joinPath(platform: Platform, base: string, ...parts: string[]): string;
23
+ export declare function resolveRoots(input: ResolveInput): ResolvedRoots;
@@ -0,0 +1,107 @@
1
+ import { INPUTS_JSON } from "../generated/contract.js";
2
+ import { DirsError } from "./errors.js";
3
+ export const KINDS = ['config', 'data', 'secrets', 'state', 'cache', 'run'];
4
+ export const SEP = { windows: '\\', macos: '/', linux: '/' };
5
+ export function isAbsolutePath(platform, p) {
6
+ if (platform === 'windows')
7
+ return /^[A-Za-z]:[\\/]/.test(p) || /^[\\/]{2}[^\\/]/.test(p);
8
+ return p.startsWith('/');
9
+ }
10
+ /** Normalises separators and drops trailing ones, so `base + sep + name` is always well formed. */
11
+ export function normalizeBase(platform, p) {
12
+ if (platform === 'windows') {
13
+ const unc = /^[\\/]{2}/.test(p);
14
+ let q = p.replace(/[\\/]+/g, '\\');
15
+ if (unc)
16
+ q = '\\' + q;
17
+ return q.replace(/\\+$/, '');
18
+ }
19
+ return p.replace(/\/+$/, '');
20
+ }
21
+ export function joinPath(platform, base, ...parts) {
22
+ return [base, ...parts].join(SEP[platform]);
23
+ }
24
+ function getEnv(platform, env, name) {
25
+ if (platform !== 'windows')
26
+ return env[name];
27
+ if (env[name] !== undefined)
28
+ return env[name];
29
+ const lower = name.toLowerCase();
30
+ for (const k of Object.keys(env))
31
+ if (k.toLowerCase() === lower)
32
+ return env[k];
33
+ return undefined;
34
+ }
35
+ export function resolveRoots(input) {
36
+ const { platform, home, env } = input;
37
+ const warnings = [];
38
+ const get = (n) => getEnv(platform, env, n);
39
+ const abs = (p) => isAbsolutePath(platform, p);
40
+ const sep = SEP[platform];
41
+ const needHome = () => {
42
+ if (home && abs(home))
43
+ return normalizeBase(platform, home);
44
+ throw new DirsError('home-unresolvable', 'the home directory is unknown or relative, and no XENO_HOME override is set');
45
+ };
46
+ const override = get('XENO_HOME');
47
+ if (override !== undefined && override !== '') {
48
+ if (abs(override)) {
49
+ const base = normalizeBase(platform, override);
50
+ const roots = Object.fromEntries(KINDS.map((k) => [k, base + sep + k]));
51
+ return { platform, roots, warnings: [], overridden: true };
52
+ }
53
+ warnings.push('xeno-home-relative-ignored');
54
+ }
55
+ // An absolute directory variable is used; a relative one is ignored with a warning; an empty one is unset.
56
+ const dirVar = (name, warnCode) => {
57
+ const v = get(name);
58
+ if (v === undefined || v === '')
59
+ return null;
60
+ if (abs(v))
61
+ return normalizeBase(platform, v);
62
+ warnings.push(`${warnCode}:${name}`);
63
+ return null;
64
+ };
65
+ let roots;
66
+ if (platform === 'windows') {
67
+ const roaming = dirVar('APPDATA', 'platform-dir-relative-ignored') ?? `${needHome()}\\AppData\\Roaming`;
68
+ const local = dirVar('LOCALAPPDATA', 'platform-dir-relative-ignored') ?? `${needHome()}\\AppData\\Local`;
69
+ const v = INPUTS_JSON.windowsVendorDir;
70
+ roots = {
71
+ config: `${roaming}\\${v}\\config`, data: `${roaming}\\${v}\\data`, secrets: `${roaming}\\${v}\\secrets`,
72
+ state: `${local}\\${v}\\state`, cache: `${local}\\${v}\\cache`, run: `${local}\\${v}\\run`,
73
+ };
74
+ }
75
+ else if (platform === 'macos') {
76
+ const h = needHome();
77
+ const id = INPUTS_JSON.inputs.macosBundleId.value;
78
+ const support = `${h}/Library/Application Support/${id}`;
79
+ const tmp = get('TMPDIR');
80
+ let run;
81
+ if (tmp !== undefined && tmp !== '' && abs(tmp))
82
+ run = `${normalizeBase(platform, tmp)}/${id}`;
83
+ else {
84
+ warnings.push('run-dir-fallback:TMPDIR');
85
+ run = `${support}/state/run`;
86
+ }
87
+ roots = { config: `${support}/config`, data: `${support}/data`, secrets: `${support}/secrets`, state: `${support}/state`, cache: `${h}/Library/Caches/${id}`, run };
88
+ }
89
+ else {
90
+ const n = INPUTS_JSON.linuxDirName;
91
+ const xdg = (name, rel) => `${dirVar(name, 'xdg-relative-ignored') ?? `${needHome()}/${rel}`}/${n}`;
92
+ const config = xdg('XDG_CONFIG_HOME', '.config');
93
+ const data = xdg('XDG_DATA_HOME', '.local/share');
94
+ const state = xdg('XDG_STATE_HOME', '.local/state');
95
+ const cache = xdg('XDG_CACHE_HOME', '.cache');
96
+ const rt = dirVar('XDG_RUNTIME_DIR', 'xdg-relative-ignored');
97
+ let run;
98
+ if (rt !== null)
99
+ run = `${rt}/${n}`;
100
+ else {
101
+ warnings.push('run-dir-fallback:XDG_RUNTIME_DIR');
102
+ run = `${state}/run`;
103
+ }
104
+ roots = { config, data, secrets: `${data}/secrets`, state, cache, run };
105
+ }
106
+ return { platform, roots, warnings: [...warnings].sort(), overridden: false };
107
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * One path segment below an area. The rules are the strictest of the three platforms on purpose: a layout is
3
+ * portable (spec section 3), so a name that is legal on Linux and illegal on Windows is a defect on both.
4
+ * Returns the reason, or null when the segment is valid.
5
+ */
6
+ export declare function segmentProblem(s: unknown): string | null;
7
+ export declare function assertSegment(s: unknown, what?: string): string;
@@ -0,0 +1,35 @@
1
+ import { DirsError } from "./errors.js";
2
+ const WINDOWS_DEVICE = /^(con|prn|aux|nul|conin\$|conout\$|com[0-9¹²³]|lpt[0-9¹²³])$/i;
3
+ // eslint-disable-next-line no-control-regex
4
+ const FORBIDDEN_CHARS = /[\u0000-\u001f\u007f<>:"|?*\\/]/;
5
+ /**
6
+ * One path segment below an area. The rules are the strictest of the three platforms on purpose: a layout is
7
+ * portable (spec section 3), so a name that is legal on Linux and illegal on Windows is a defect on both.
8
+ * Returns the reason, or null when the segment is valid.
9
+ */
10
+ export function segmentProblem(s) {
11
+ if (typeof s !== 'string')
12
+ return 'not a string';
13
+ if (s.length === 0)
14
+ return 'empty';
15
+ if (s.length > 255)
16
+ return 'longer than 255 characters';
17
+ if (s === '.' || s === '..')
18
+ return 'relative reference';
19
+ if (FORBIDDEN_CHARS.test(s))
20
+ return 'contains a separator, drive, stream or reserved character';
21
+ if (s.endsWith('.') || s.endsWith(' '))
22
+ return 'ends in a dot or space';
23
+ const stem = s.split('.')[0] ?? s;
24
+ if (WINDOWS_DEVICE.test(stem.trimEnd()))
25
+ return 'Windows device name';
26
+ return null;
27
+ }
28
+ export function assertSegment(s, what = 'segment') {
29
+ const problem = segmentProblem(s);
30
+ if (problem !== null) {
31
+ // The value itself is never echoed: a segment can be a secret's name.
32
+ throw new DirsError('invalid-segment', `invalid ${what}: ${problem}`, { problem });
33
+ }
34
+ return s;
35
+ }
@@ -0,0 +1,134 @@
1
+ export declare const REGISTRY_JSON: {
2
+ $comment: string;
3
+ registryVersion: number;
4
+ kinds: {
5
+ config: {
6
+ lifecycle: string;
7
+ backedUp: string;
8
+ userDeletable: boolean;
9
+ portable: boolean;
10
+ };
11
+ data: {
12
+ lifecycle: string;
13
+ backedUp: string;
14
+ userDeletable: boolean;
15
+ portable: boolean;
16
+ };
17
+ state: {
18
+ lifecycle: string;
19
+ backedUp: string;
20
+ userDeletable: string;
21
+ portable: boolean;
22
+ };
23
+ cache: {
24
+ lifecycle: string;
25
+ backedUp: string;
26
+ userDeletable: boolean;
27
+ portable: boolean;
28
+ };
29
+ run: {
30
+ lifecycle: string;
31
+ backedUp: string;
32
+ userDeletable: boolean;
33
+ portable: boolean;
34
+ };
35
+ secrets: {
36
+ lifecycle: string;
37
+ backedUp: string;
38
+ userDeletable: boolean;
39
+ portable: string;
40
+ };
41
+ };
42
+ reservedFiles: {
43
+ id: string;
44
+ kind: string;
45
+ path: string;
46
+ owner: string;
47
+ sensitivity: string;
48
+ schema: number;
49
+ }[];
50
+ areas: ({
51
+ area: string;
52
+ owner: string;
53
+ responsibility: string;
54
+ uses: string[];
55
+ kindNotes?: undefined;
56
+ slugPattern?: undefined;
57
+ } | {
58
+ area: string;
59
+ owner: string;
60
+ responsibility: string;
61
+ uses: string[];
62
+ kindNotes: {
63
+ data: string;
64
+ cache: string;
65
+ state?: undefined;
66
+ run?: undefined;
67
+ };
68
+ slugPattern?: undefined;
69
+ } | {
70
+ area: string;
71
+ owner: string;
72
+ responsibility: string;
73
+ uses: string[];
74
+ slugPattern: string;
75
+ kindNotes?: undefined;
76
+ } | {
77
+ area: string;
78
+ owner: string;
79
+ responsibility: string;
80
+ uses: string[];
81
+ kindNotes: {
82
+ state: string;
83
+ run: string;
84
+ data?: undefined;
85
+ cache?: undefined;
86
+ };
87
+ slugPattern?: undefined;
88
+ })[];
89
+ locks: {
90
+ $comment: string;
91
+ kind: string;
92
+ suffix: string;
93
+ };
94
+ };
95
+ export declare const INPUTS_JSON: {
96
+ $comment: string;
97
+ layout: number;
98
+ inputs: {
99
+ macosBundleId: {
100
+ value: string;
101
+ status: string;
102
+ decided: string;
103
+ source: string;
104
+ };
105
+ legacyFallbackReleases: {
106
+ value: number;
107
+ status: string;
108
+ decided: string;
109
+ source: string;
110
+ note: string;
111
+ };
112
+ };
113
+ legacyHomes: string[];
114
+ windowsVendorDir: string;
115
+ linuxDirName: string;
116
+ secretsKeyService: string;
117
+ secretsKeyAccount: string;
118
+ $comment2: string;
119
+ };
120
+ export declare const LEGACY_MAP_JSON: {
121
+ $comment: string;
122
+ rules: {
123
+ id: string;
124
+ legacyHome: string;
125
+ match: string;
126
+ action: string;
127
+ target: {
128
+ kind: string;
129
+ area: string;
130
+ segments: string[];
131
+ };
132
+ source: string;
133
+ }[];
134
+ };
@@ -0,0 +1,230 @@
1
+ // GENERATED by scripts/sync-contract.mjs from contract/*.json. Do not edit; change the contract and re-run.
2
+ /* eslint-disable */
3
+ export const REGISTRY_JSON = {
4
+ "$comment": "Every allowed path. Areas are a CLOSED list (XENO LOCAL HOME - SPEC.md section 5); a new area is a spec change. Entries are registered per (kind, area); everything inside an area belongs to its owner. 'locks' entries are run-kind directories that may hold lock files only (spec section 8).",
5
+ "registryVersion": 1,
6
+ "kinds": {
7
+ "config": {
8
+ "lifecycle": "durable",
9
+ "backedUp": "yes",
10
+ "userDeletable": false,
11
+ "portable": true
12
+ },
13
+ "data": {
14
+ "lifecycle": "durable",
15
+ "backedUp": "yes",
16
+ "userDeletable": false,
17
+ "portable": true
18
+ },
19
+ "state": {
20
+ "lifecycle": "machine-local",
21
+ "backedUp": "optional",
22
+ "userDeletable": "with-consequence",
23
+ "portable": false
24
+ },
25
+ "cache": {
26
+ "lifecycle": "regenerable",
27
+ "backedUp": "never",
28
+ "userDeletable": true,
29
+ "portable": false
30
+ },
31
+ "run": {
32
+ "lifecycle": "ephemeral",
33
+ "backedUp": "never",
34
+ "userDeletable": true,
35
+ "portable": false
36
+ },
37
+ "secrets": {
38
+ "lifecycle": "encrypted",
39
+ "backedUp": "encrypted",
40
+ "userDeletable": false,
41
+ "portable": "escrow-only"
42
+ }
43
+ },
44
+ "reservedFiles": [
45
+ {
46
+ "id": "layout",
47
+ "kind": "data",
48
+ "path": "layout.json",
49
+ "owner": "dirs resolver",
50
+ "sensitivity": "normal",
51
+ "schema": 1
52
+ },
53
+ {
54
+ "id": "area-meta",
55
+ "kind": "*",
56
+ "path": "<area>/area.json",
57
+ "owner": "the area owner",
58
+ "sensitivity": "normal",
59
+ "schema": 1
60
+ }
61
+ ],
62
+ "areas": [
63
+ {
64
+ "area": "identity",
65
+ "owner": "account SDK",
66
+ "responsibility": "the person's XENO account, device identity, sign-in state",
67
+ "uses": [
68
+ "config",
69
+ "state",
70
+ "secrets"
71
+ ]
72
+ },
73
+ {
74
+ "area": "knowledge",
75
+ "owner": "Corpus engine",
76
+ "responsibility": "the user-level corpus: rules, skills, documents, claims, verdicts, history",
77
+ "uses": [
78
+ "data",
79
+ "state",
80
+ "cache"
81
+ ]
82
+ },
83
+ {
84
+ "area": "agents/definitions",
85
+ "owner": "agent runtime",
86
+ "responsibility": "agent profiles and their configuration",
87
+ "uses": [
88
+ "config",
89
+ "data"
90
+ ]
91
+ },
92
+ {
93
+ "area": "agents/environments",
94
+ "owner": "Spawn",
95
+ "responsibility": "installed agent versions, isolated agent homes",
96
+ "uses": [
97
+ "data",
98
+ "cache"
99
+ ],
100
+ "kindNotes": {
101
+ "data": "durable profile and runtime identity, and acquisition metadata (what was pinned, from where, with which digest)",
102
+ "cache": "re-downloadable runtime bytes; deleting it must leave a product that re-acquires from the data record"
103
+ }
104
+ },
105
+ {
106
+ "area": "agents/sessions",
107
+ "owner": "agent runtime",
108
+ "responsibility": "conversations, runs, transcripts",
109
+ "uses": [
110
+ "state"
111
+ ]
112
+ },
113
+ {
114
+ "area": "minds",
115
+ "owner": "Anima",
116
+ "responsibility": "Minds and Souls (single-writer, signed)",
117
+ "uses": [
118
+ "data",
119
+ "secrets"
120
+ ]
121
+ },
122
+ {
123
+ "area": "workforce",
124
+ "owner": "Workforce host",
125
+ "responsibility": "local replicas of workspaces, teams and assignments",
126
+ "uses": [
127
+ "state",
128
+ "secrets"
129
+ ]
130
+ },
131
+ {
132
+ "area": "extensions",
133
+ "owner": "extension host",
134
+ "responsibility": "installed plugins, MCP servers, tools",
135
+ "uses": [
136
+ "config",
137
+ "data",
138
+ "cache"
139
+ ]
140
+ },
141
+ {
142
+ "area": "models",
143
+ "owner": "inference runtime",
144
+ "responsibility": "downloaded model weights",
145
+ "uses": [
146
+ "cache"
147
+ ]
148
+ },
149
+ {
150
+ "area": "apps/<slug>",
151
+ "owner": "that app",
152
+ "responsibility": "one creative app's own settings, recent files, window state",
153
+ "uses": [
154
+ "config",
155
+ "state",
156
+ "cache"
157
+ ],
158
+ "slugPattern": "^[a-z][a-z0-9-]{0,39}$"
159
+ },
160
+ {
161
+ "area": "platform",
162
+ "owner": "platform runtime",
163
+ "responsibility": "installed-product registry, updates, crash reports, running-service records",
164
+ "uses": [
165
+ "config",
166
+ "state",
167
+ "cache",
168
+ "run"
169
+ ],
170
+ "kindNotes": {
171
+ "state": "includes migrations/ (the migration journal, spec section 10)",
172
+ "run": "running-service records (capability-servers/) and platform locks"
173
+ }
174
+ }
175
+ ],
176
+ "locks": {
177
+ "$comment": "Spec section 8: locks live in run/<area>/. Every area may hold locks regardless of its 'uses' list; a locks-only run entry accepts <name>.lock files and nothing else.",
178
+ "kind": "run",
179
+ "suffix": ".lock"
180
+ }
181
+ };
182
+ export const INPUTS_JSON = {
183
+ "$comment": "Owner-decided inputs to the contract. Source: XENO LOCAL HOME - SPEC.md section 11. Both implementations embed these values; a gate refuses a release while any input is not locked.",
184
+ "layout": 1,
185
+ "inputs": {
186
+ "macosBundleId": {
187
+ "value": "ai.xenosystem",
188
+ "status": "locked",
189
+ "decided": "2026-10-11",
190
+ "source": "XENO LOCAL HOME - SPEC.md section 11.1"
191
+ },
192
+ "legacyFallbackReleases": {
193
+ "value": 3,
194
+ "status": "locked",
195
+ "decided": "2026-10-11",
196
+ "source": "XENO LOCAL HOME - SPEC.md section 11.2",
197
+ "note": "Releases after a product adopts the layout during which it still reads the legacy location. The legacy copy is never deleted automatically."
198
+ }
199
+ },
200
+ "legacyHomes": [
201
+ ".xeno",
202
+ ".xeno-agent",
203
+ ".xeno-anima",
204
+ ".xeno-code"
205
+ ],
206
+ "windowsVendorDir": "XENO",
207
+ "linuxDirName": "xeno",
208
+ "secretsKeyService": "ai.xenosystem",
209
+ "secretsKeyAccount": "master-key",
210
+ "$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."
211
+ };
212
+ export const LEGACY_MAP_JSON = {
213
+ "$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 '*'.",
214
+ "rules": [
215
+ {
216
+ "id": "shell-window-state",
217
+ "legacyHome": ".xeno",
218
+ "match": "shell/state.json",
219
+ "action": "copy",
220
+ "target": {
221
+ "kind": "state",
222
+ "area": "apps/shell",
223
+ "segments": [
224
+ "state.json"
225
+ ]
226
+ },
227
+ "source": "xeno-primitives/ADOPTION.md, xeno-shell row (~/.xeno/shell/state.json -> apps/shell); window state is kind state (LOCAL HOME spec section 5)"
228
+ }
229
+ ]
230
+ };
@@ -0,0 +1,37 @@
1
+ /**
2
+ * The envelope (XENO LOCAL HOME - SPEC.md section 6). The OS store protects one master key (MK) per person per
3
+ * machine. Each secret gets its own random data key (DEK); the DEK encrypts the value and MK wraps the DEK, both
4
+ * AES-256-GCM with a 96-bit nonce. The associated data binds a ciphertext to its area and name, so a file copied to
5
+ * another name or area fails to open. `ct` is ciphertext || 16-byte tag. The wire format is shared with the Rust
6
+ * implementation and pinned by contract/vectors/secrets-envelope.json.
7
+ */
8
+ export interface SealedPart {
9
+ nonce: string;
10
+ ct: string;
11
+ }
12
+ export interface EnvelopeFile {
13
+ v: 1;
14
+ alg: 'AES-256-GCM';
15
+ area: string;
16
+ name: string;
17
+ keyId: string;
18
+ wrap: SealedPart;
19
+ data: SealedPart;
20
+ createdAt: string;
21
+ }
22
+ export declare const KEY_BYTES = 32;
23
+ export declare const wrapAad: (area: string, name: string) => Buffer;
24
+ export declare const dataAad: (area: string, name: string) => Buffer;
25
+ /** Identifier of a master key: first 8 bytes of its SHA-256, hex. Not secret; lets a wrong key be told from a tampered file. */
26
+ export declare function keyIdOf(masterKey: Uint8Array): string;
27
+ export interface SealOptions {
28
+ /** Fixed randomness for known-answer tests only. */
29
+ dek?: Uint8Array;
30
+ wrapNonce?: Uint8Array;
31
+ dataNonce?: Uint8Array;
32
+ createdAt?: string;
33
+ }
34
+ export declare function sealSecret(masterKey: Uint8Array, area: string, name: string, plaintext: Uint8Array, options?: SealOptions): EnvelopeFile;
35
+ /** Parses and shape-checks an envelope file. Throws `malformed`; never echoes file content. */
36
+ export declare function parseEnvelope(text: string): EnvelopeFile;
37
+ export declare function openSecret(masterKey: Uint8Array, file: EnvelopeFile, area: string, name: string): Buffer;