@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.
- package/README.md +29 -2
- package/dist/cjs/dirs/atomic.d.ts +9 -0
- package/dist/cjs/dirs/atomic.js +59 -0
- package/dist/cjs/dirs/check-cli.d.ts +2 -0
- package/dist/cjs/dirs/check-cli.js +50 -0
- package/dist/cjs/dirs/check.d.ts +49 -0
- package/dist/cjs/dirs/check.js +158 -0
- package/dist/cjs/dirs/cli.d.ts +2 -0
- package/dist/cjs/dirs/cli.js +72 -0
- package/dist/cjs/dirs/dirs.d.ts +57 -0
- package/dist/cjs/dirs/dirs.js +135 -0
- package/dist/cjs/dirs/doctor.d.ts +31 -0
- package/dist/cjs/dirs/doctor.js +80 -0
- package/dist/cjs/dirs/errors.d.ts +8 -0
- package/dist/cjs/dirs/errors.js +19 -0
- package/dist/cjs/dirs/host.d.ts +4 -0
- package/dist/cjs/dirs/host.js +26 -0
- package/dist/cjs/dirs/index.d.ts +13 -0
- package/dist/cjs/dirs/index.js +55 -0
- package/dist/cjs/dirs/inputs.d.ts +14 -0
- package/dist/cjs/dirs/inputs.js +14 -0
- package/dist/cjs/dirs/layout.d.ts +16 -0
- package/dist/cjs/dirs/layout.js +25 -0
- package/dist/cjs/dirs/lock.d.ts +38 -0
- package/dist/cjs/dirs/lock.js +128 -0
- package/dist/cjs/dirs/migrate.d.ts +134 -0
- package/dist/cjs/dirs/migrate.js +437 -0
- package/dist/cjs/dirs/procinfo.d.ts +10 -0
- package/dist/cjs/dirs/procinfo.js +67 -0
- package/dist/cjs/dirs/registry.d.ts +27 -0
- package/dist/cjs/dirs/registry.js +78 -0
- package/dist/cjs/dirs/roots.d.ts +23 -0
- package/dist/cjs/dirs/roots.js +114 -0
- package/dist/cjs/dirs/segments.d.ts +7 -0
- package/dist/cjs/dirs/segments.js +39 -0
- package/dist/cjs/generated/contract.d.ts +134 -0
- package/dist/cjs/generated/contract.js +233 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/secrets/envelope.d.ts +37 -0
- package/dist/cjs/secrets/envelope.js +90 -0
- package/dist/cjs/secrets/errors.d.ts +10 -0
- package/dist/cjs/secrets/errors.js +20 -0
- package/dist/cjs/secrets/index.d.ts +4 -0
- package/dist/cjs/secrets/index.js +17 -0
- package/dist/cjs/secrets/keystore.d.ts +37 -0
- package/dist/cjs/secrets/keystore.js +41 -0
- package/dist/cjs/secrets/os-stores.d.ts +17 -0
- package/dist/cjs/secrets/os-stores.js +195 -0
- package/dist/cjs/secrets/store.d.ts +32 -0
- package/dist/cjs/secrets/store.js +161 -0
- package/dist/cjs/secrets/testing.d.ts +5 -0
- package/dist/cjs/secrets/testing.js +20 -0
- package/dist/cjs/updates/index.d.ts +67 -0
- package/dist/cjs/updates/index.js +102 -0
- package/dist/esm/dirs/atomic.d.ts +9 -0
- package/dist/esm/dirs/atomic.js +56 -0
- package/dist/esm/dirs/check-cli.d.ts +2 -0
- package/dist/esm/dirs/check-cli.js +48 -0
- package/dist/esm/dirs/check.d.ts +49 -0
- package/dist/esm/dirs/check.js +152 -0
- package/dist/esm/dirs/cli.d.ts +2 -0
- package/dist/esm/dirs/cli.js +70 -0
- package/dist/esm/dirs/dirs.d.ts +57 -0
- package/dist/esm/dirs/dirs.js +129 -0
- package/dist/esm/dirs/doctor.d.ts +31 -0
- package/dist/esm/dirs/doctor.js +77 -0
- package/dist/esm/dirs/errors.d.ts +8 -0
- package/dist/esm/dirs/errors.js +14 -0
- package/dist/esm/dirs/host.d.ts +4 -0
- package/dist/esm/dirs/host.js +21 -0
- package/dist/esm/dirs/index.d.ts +13 -0
- package/dist/esm/dirs/index.js +13 -0
- package/dist/esm/dirs/inputs.d.ts +14 -0
- package/dist/esm/dirs/inputs.js +11 -0
- package/dist/esm/dirs/layout.d.ts +16 -0
- package/dist/esm/dirs/layout.js +21 -0
- package/dist/esm/dirs/lock.d.ts +38 -0
- package/dist/esm/dirs/lock.js +124 -0
- package/dist/esm/dirs/migrate.d.ts +134 -0
- package/dist/esm/dirs/migrate.js +428 -0
- package/dist/esm/dirs/procinfo.d.ts +10 -0
- package/dist/esm/dirs/procinfo.js +62 -0
- package/dist/esm/dirs/registry.d.ts +27 -0
- package/dist/esm/dirs/registry.js +71 -0
- package/dist/esm/dirs/roots.d.ts +23 -0
- package/dist/esm/dirs/roots.js +107 -0
- package/dist/esm/dirs/segments.d.ts +7 -0
- package/dist/esm/dirs/segments.js +35 -0
- package/dist/esm/generated/contract.d.ts +134 -0
- package/dist/esm/generated/contract.js +230 -0
- package/dist/esm/secrets/envelope.d.ts +37 -0
- package/dist/esm/secrets/envelope.js +81 -0
- package/dist/esm/secrets/errors.d.ts +10 -0
- package/dist/esm/secrets/errors.js +15 -0
- package/dist/esm/secrets/index.d.ts +4 -0
- package/dist/esm/secrets/index.js +4 -0
- package/dist/esm/secrets/keystore.d.ts +37 -0
- package/dist/esm/secrets/keystore.js +37 -0
- package/dist/esm/secrets/os-stores.d.ts +17 -0
- package/dist/esm/secrets/os-stores.js +189 -0
- package/dist/esm/secrets/store.d.ts +32 -0
- package/dist/esm/secrets/store.js +156 -0
- package/dist/esm/secrets/testing.d.ts +5 -0
- package/dist/esm/secrets/testing.js +12 -0
- package/dist/esm/updates/index.d.ts +67 -0
- package/dist/esm/updates/index.js +97 -0
- package/package.json +42 -4
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SEP = exports.KINDS = void 0;
|
|
4
|
+
exports.isAbsolutePath = isAbsolutePath;
|
|
5
|
+
exports.normalizeBase = normalizeBase;
|
|
6
|
+
exports.joinPath = joinPath;
|
|
7
|
+
exports.resolveRoots = resolveRoots;
|
|
8
|
+
const contract_ts_1 = require("../generated/contract.js");
|
|
9
|
+
const errors_ts_1 = require("./errors.js");
|
|
10
|
+
exports.KINDS = ['config', 'data', 'secrets', 'state', 'cache', 'run'];
|
|
11
|
+
exports.SEP = { windows: '\\', macos: '/', linux: '/' };
|
|
12
|
+
function isAbsolutePath(platform, p) {
|
|
13
|
+
if (platform === 'windows')
|
|
14
|
+
return /^[A-Za-z]:[\\/]/.test(p) || /^[\\/]{2}[^\\/]/.test(p);
|
|
15
|
+
return p.startsWith('/');
|
|
16
|
+
}
|
|
17
|
+
/** Normalises separators and drops trailing ones, so `base + sep + name` is always well formed. */
|
|
18
|
+
function normalizeBase(platform, p) {
|
|
19
|
+
if (platform === 'windows') {
|
|
20
|
+
const unc = /^[\\/]{2}/.test(p);
|
|
21
|
+
let q = p.replace(/[\\/]+/g, '\\');
|
|
22
|
+
if (unc)
|
|
23
|
+
q = '\\' + q;
|
|
24
|
+
return q.replace(/\\+$/, '');
|
|
25
|
+
}
|
|
26
|
+
return p.replace(/\/+$/, '');
|
|
27
|
+
}
|
|
28
|
+
function joinPath(platform, base, ...parts) {
|
|
29
|
+
return [base, ...parts].join(exports.SEP[platform]);
|
|
30
|
+
}
|
|
31
|
+
function getEnv(platform, env, name) {
|
|
32
|
+
if (platform !== 'windows')
|
|
33
|
+
return env[name];
|
|
34
|
+
if (env[name] !== undefined)
|
|
35
|
+
return env[name];
|
|
36
|
+
const lower = name.toLowerCase();
|
|
37
|
+
for (const k of Object.keys(env))
|
|
38
|
+
if (k.toLowerCase() === lower)
|
|
39
|
+
return env[k];
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
function resolveRoots(input) {
|
|
43
|
+
const { platform, home, env } = input;
|
|
44
|
+
const warnings = [];
|
|
45
|
+
const get = (n) => getEnv(platform, env, n);
|
|
46
|
+
const abs = (p) => isAbsolutePath(platform, p);
|
|
47
|
+
const sep = exports.SEP[platform];
|
|
48
|
+
const needHome = () => {
|
|
49
|
+
if (home && abs(home))
|
|
50
|
+
return normalizeBase(platform, home);
|
|
51
|
+
throw new errors_ts_1.DirsError('home-unresolvable', 'the home directory is unknown or relative, and no XENO_HOME override is set');
|
|
52
|
+
};
|
|
53
|
+
const override = get('XENO_HOME');
|
|
54
|
+
if (override !== undefined && override !== '') {
|
|
55
|
+
if (abs(override)) {
|
|
56
|
+
const base = normalizeBase(platform, override);
|
|
57
|
+
const roots = Object.fromEntries(exports.KINDS.map((k) => [k, base + sep + k]));
|
|
58
|
+
return { platform, roots, warnings: [], overridden: true };
|
|
59
|
+
}
|
|
60
|
+
warnings.push('xeno-home-relative-ignored');
|
|
61
|
+
}
|
|
62
|
+
// An absolute directory variable is used; a relative one is ignored with a warning; an empty one is unset.
|
|
63
|
+
const dirVar = (name, warnCode) => {
|
|
64
|
+
const v = get(name);
|
|
65
|
+
if (v === undefined || v === '')
|
|
66
|
+
return null;
|
|
67
|
+
if (abs(v))
|
|
68
|
+
return normalizeBase(platform, v);
|
|
69
|
+
warnings.push(`${warnCode}:${name}`);
|
|
70
|
+
return null;
|
|
71
|
+
};
|
|
72
|
+
let roots;
|
|
73
|
+
if (platform === 'windows') {
|
|
74
|
+
const roaming = dirVar('APPDATA', 'platform-dir-relative-ignored') ?? `${needHome()}\\AppData\\Roaming`;
|
|
75
|
+
const local = dirVar('LOCALAPPDATA', 'platform-dir-relative-ignored') ?? `${needHome()}\\AppData\\Local`;
|
|
76
|
+
const v = contract_ts_1.INPUTS_JSON.windowsVendorDir;
|
|
77
|
+
roots = {
|
|
78
|
+
config: `${roaming}\\${v}\\config`, data: `${roaming}\\${v}\\data`, secrets: `${roaming}\\${v}\\secrets`,
|
|
79
|
+
state: `${local}\\${v}\\state`, cache: `${local}\\${v}\\cache`, run: `${local}\\${v}\\run`,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
else if (platform === 'macos') {
|
|
83
|
+
const h = needHome();
|
|
84
|
+
const id = contract_ts_1.INPUTS_JSON.inputs.macosBundleId.value;
|
|
85
|
+
const support = `${h}/Library/Application Support/${id}`;
|
|
86
|
+
const tmp = get('TMPDIR');
|
|
87
|
+
let run;
|
|
88
|
+
if (tmp !== undefined && tmp !== '' && abs(tmp))
|
|
89
|
+
run = `${normalizeBase(platform, tmp)}/${id}`;
|
|
90
|
+
else {
|
|
91
|
+
warnings.push('run-dir-fallback:TMPDIR');
|
|
92
|
+
run = `${support}/state/run`;
|
|
93
|
+
}
|
|
94
|
+
roots = { config: `${support}/config`, data: `${support}/data`, secrets: `${support}/secrets`, state: `${support}/state`, cache: `${h}/Library/Caches/${id}`, run };
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
const n = contract_ts_1.INPUTS_JSON.linuxDirName;
|
|
98
|
+
const xdg = (name, rel) => `${dirVar(name, 'xdg-relative-ignored') ?? `${needHome()}/${rel}`}/${n}`;
|
|
99
|
+
const config = xdg('XDG_CONFIG_HOME', '.config');
|
|
100
|
+
const data = xdg('XDG_DATA_HOME', '.local/share');
|
|
101
|
+
const state = xdg('XDG_STATE_HOME', '.local/state');
|
|
102
|
+
const cache = xdg('XDG_CACHE_HOME', '.cache');
|
|
103
|
+
const rt = dirVar('XDG_RUNTIME_DIR', 'xdg-relative-ignored');
|
|
104
|
+
let run;
|
|
105
|
+
if (rt !== null)
|
|
106
|
+
run = `${rt}/${n}`;
|
|
107
|
+
else {
|
|
108
|
+
warnings.push('run-dir-fallback:XDG_RUNTIME_DIR');
|
|
109
|
+
run = `${state}/run`;
|
|
110
|
+
}
|
|
111
|
+
roots = { config, data, secrets: `${data}/secrets`, state, cache, run };
|
|
112
|
+
}
|
|
113
|
+
return { platform, roots, warnings: [...warnings].sort(), overridden: false };
|
|
114
|
+
}
|
|
@@ -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,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.segmentProblem = segmentProblem;
|
|
4
|
+
exports.assertSegment = assertSegment;
|
|
5
|
+
const errors_ts_1 = require("./errors.js");
|
|
6
|
+
const WINDOWS_DEVICE = /^(con|prn|aux|nul|conin\$|conout\$|com[0-9¹²³]|lpt[0-9¹²³])$/i;
|
|
7
|
+
// eslint-disable-next-line no-control-regex
|
|
8
|
+
const FORBIDDEN_CHARS = /[\u0000-\u001f\u007f<>:"|?*\\/]/;
|
|
9
|
+
/**
|
|
10
|
+
* One path segment below an area. The rules are the strictest of the three platforms on purpose: a layout is
|
|
11
|
+
* portable (spec section 3), so a name that is legal on Linux and illegal on Windows is a defect on both.
|
|
12
|
+
* Returns the reason, or null when the segment is valid.
|
|
13
|
+
*/
|
|
14
|
+
function segmentProblem(s) {
|
|
15
|
+
if (typeof s !== 'string')
|
|
16
|
+
return 'not a string';
|
|
17
|
+
if (s.length === 0)
|
|
18
|
+
return 'empty';
|
|
19
|
+
if (s.length > 255)
|
|
20
|
+
return 'longer than 255 characters';
|
|
21
|
+
if (s === '.' || s === '..')
|
|
22
|
+
return 'relative reference';
|
|
23
|
+
if (FORBIDDEN_CHARS.test(s))
|
|
24
|
+
return 'contains a separator, drive, stream or reserved character';
|
|
25
|
+
if (s.endsWith('.') || s.endsWith(' '))
|
|
26
|
+
return 'ends in a dot or space';
|
|
27
|
+
const stem = s.split('.')[0] ?? s;
|
|
28
|
+
if (WINDOWS_DEVICE.test(stem.trimEnd()))
|
|
29
|
+
return 'Windows device name';
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
function assertSegment(s, what = 'segment') {
|
|
33
|
+
const problem = segmentProblem(s);
|
|
34
|
+
if (problem !== null) {
|
|
35
|
+
// The value itself is never echoed: a segment can be a secret's name.
|
|
36
|
+
throw new errors_ts_1.DirsError('invalid-segment', `invalid ${what}: ${problem}`, { problem });
|
|
37
|
+
}
|
|
38
|
+
return s;
|
|
39
|
+
}
|
|
@@ -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,233 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LEGACY_MAP_JSON = exports.INPUTS_JSON = exports.REGISTRY_JSON = void 0;
|
|
4
|
+
// GENERATED by scripts/sync-contract.mjs from contract/*.json. Do not edit; change the contract and re-run.
|
|
5
|
+
/* eslint-disable */
|
|
6
|
+
exports.REGISTRY_JSON = {
|
|
7
|
+
"$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).",
|
|
8
|
+
"registryVersion": 1,
|
|
9
|
+
"kinds": {
|
|
10
|
+
"config": {
|
|
11
|
+
"lifecycle": "durable",
|
|
12
|
+
"backedUp": "yes",
|
|
13
|
+
"userDeletable": false,
|
|
14
|
+
"portable": true
|
|
15
|
+
},
|
|
16
|
+
"data": {
|
|
17
|
+
"lifecycle": "durable",
|
|
18
|
+
"backedUp": "yes",
|
|
19
|
+
"userDeletable": false,
|
|
20
|
+
"portable": true
|
|
21
|
+
},
|
|
22
|
+
"state": {
|
|
23
|
+
"lifecycle": "machine-local",
|
|
24
|
+
"backedUp": "optional",
|
|
25
|
+
"userDeletable": "with-consequence",
|
|
26
|
+
"portable": false
|
|
27
|
+
},
|
|
28
|
+
"cache": {
|
|
29
|
+
"lifecycle": "regenerable",
|
|
30
|
+
"backedUp": "never",
|
|
31
|
+
"userDeletable": true,
|
|
32
|
+
"portable": false
|
|
33
|
+
},
|
|
34
|
+
"run": {
|
|
35
|
+
"lifecycle": "ephemeral",
|
|
36
|
+
"backedUp": "never",
|
|
37
|
+
"userDeletable": true,
|
|
38
|
+
"portable": false
|
|
39
|
+
},
|
|
40
|
+
"secrets": {
|
|
41
|
+
"lifecycle": "encrypted",
|
|
42
|
+
"backedUp": "encrypted",
|
|
43
|
+
"userDeletable": false,
|
|
44
|
+
"portable": "escrow-only"
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
"reservedFiles": [
|
|
48
|
+
{
|
|
49
|
+
"id": "layout",
|
|
50
|
+
"kind": "data",
|
|
51
|
+
"path": "layout.json",
|
|
52
|
+
"owner": "dirs resolver",
|
|
53
|
+
"sensitivity": "normal",
|
|
54
|
+
"schema": 1
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
"id": "area-meta",
|
|
58
|
+
"kind": "*",
|
|
59
|
+
"path": "<area>/area.json",
|
|
60
|
+
"owner": "the area owner",
|
|
61
|
+
"sensitivity": "normal",
|
|
62
|
+
"schema": 1
|
|
63
|
+
}
|
|
64
|
+
],
|
|
65
|
+
"areas": [
|
|
66
|
+
{
|
|
67
|
+
"area": "identity",
|
|
68
|
+
"owner": "account SDK",
|
|
69
|
+
"responsibility": "the person's XENO account, device identity, sign-in state",
|
|
70
|
+
"uses": [
|
|
71
|
+
"config",
|
|
72
|
+
"state",
|
|
73
|
+
"secrets"
|
|
74
|
+
]
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
"area": "knowledge",
|
|
78
|
+
"owner": "Corpus engine",
|
|
79
|
+
"responsibility": "the user-level corpus: rules, skills, documents, claims, verdicts, history",
|
|
80
|
+
"uses": [
|
|
81
|
+
"data",
|
|
82
|
+
"state",
|
|
83
|
+
"cache"
|
|
84
|
+
]
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
"area": "agents/definitions",
|
|
88
|
+
"owner": "agent runtime",
|
|
89
|
+
"responsibility": "agent profiles and their configuration",
|
|
90
|
+
"uses": [
|
|
91
|
+
"config",
|
|
92
|
+
"data"
|
|
93
|
+
]
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
"area": "agents/environments",
|
|
97
|
+
"owner": "Spawn",
|
|
98
|
+
"responsibility": "installed agent versions, isolated agent homes",
|
|
99
|
+
"uses": [
|
|
100
|
+
"data",
|
|
101
|
+
"cache"
|
|
102
|
+
],
|
|
103
|
+
"kindNotes": {
|
|
104
|
+
"data": "durable profile and runtime identity, and acquisition metadata (what was pinned, from where, with which digest)",
|
|
105
|
+
"cache": "re-downloadable runtime bytes; deleting it must leave a product that re-acquires from the data record"
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
"area": "agents/sessions",
|
|
110
|
+
"owner": "agent runtime",
|
|
111
|
+
"responsibility": "conversations, runs, transcripts",
|
|
112
|
+
"uses": [
|
|
113
|
+
"state"
|
|
114
|
+
]
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
"area": "minds",
|
|
118
|
+
"owner": "Anima",
|
|
119
|
+
"responsibility": "Minds and Souls (single-writer, signed)",
|
|
120
|
+
"uses": [
|
|
121
|
+
"data",
|
|
122
|
+
"secrets"
|
|
123
|
+
]
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
"area": "workforce",
|
|
127
|
+
"owner": "Workforce host",
|
|
128
|
+
"responsibility": "local replicas of workspaces, teams and assignments",
|
|
129
|
+
"uses": [
|
|
130
|
+
"state",
|
|
131
|
+
"secrets"
|
|
132
|
+
]
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
"area": "extensions",
|
|
136
|
+
"owner": "extension host",
|
|
137
|
+
"responsibility": "installed plugins, MCP servers, tools",
|
|
138
|
+
"uses": [
|
|
139
|
+
"config",
|
|
140
|
+
"data",
|
|
141
|
+
"cache"
|
|
142
|
+
]
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
"area": "models",
|
|
146
|
+
"owner": "inference runtime",
|
|
147
|
+
"responsibility": "downloaded model weights",
|
|
148
|
+
"uses": [
|
|
149
|
+
"cache"
|
|
150
|
+
]
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
"area": "apps/<slug>",
|
|
154
|
+
"owner": "that app",
|
|
155
|
+
"responsibility": "one creative app's own settings, recent files, window state",
|
|
156
|
+
"uses": [
|
|
157
|
+
"config",
|
|
158
|
+
"state",
|
|
159
|
+
"cache"
|
|
160
|
+
],
|
|
161
|
+
"slugPattern": "^[a-z][a-z0-9-]{0,39}$"
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
"area": "platform",
|
|
165
|
+
"owner": "platform runtime",
|
|
166
|
+
"responsibility": "installed-product registry, updates, crash reports, running-service records",
|
|
167
|
+
"uses": [
|
|
168
|
+
"config",
|
|
169
|
+
"state",
|
|
170
|
+
"cache",
|
|
171
|
+
"run"
|
|
172
|
+
],
|
|
173
|
+
"kindNotes": {
|
|
174
|
+
"state": "includes migrations/ (the migration journal, spec section 10)",
|
|
175
|
+
"run": "running-service records (capability-servers/) and platform locks"
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
],
|
|
179
|
+
"locks": {
|
|
180
|
+
"$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.",
|
|
181
|
+
"kind": "run",
|
|
182
|
+
"suffix": ".lock"
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
exports.INPUTS_JSON = {
|
|
186
|
+
"$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.",
|
|
187
|
+
"layout": 1,
|
|
188
|
+
"inputs": {
|
|
189
|
+
"macosBundleId": {
|
|
190
|
+
"value": "ai.xenosystem",
|
|
191
|
+
"status": "locked",
|
|
192
|
+
"decided": "2026-10-11",
|
|
193
|
+
"source": "XENO LOCAL HOME - SPEC.md section 11.1"
|
|
194
|
+
},
|
|
195
|
+
"legacyFallbackReleases": {
|
|
196
|
+
"value": 3,
|
|
197
|
+
"status": "locked",
|
|
198
|
+
"decided": "2026-10-11",
|
|
199
|
+
"source": "XENO LOCAL HOME - SPEC.md section 11.2",
|
|
200
|
+
"note": "Releases after a product adopts the layout during which it still reads the legacy location. The legacy copy is never deleted automatically."
|
|
201
|
+
}
|
|
202
|
+
},
|
|
203
|
+
"legacyHomes": [
|
|
204
|
+
".xeno",
|
|
205
|
+
".xeno-agent",
|
|
206
|
+
".xeno-anima",
|
|
207
|
+
".xeno-code"
|
|
208
|
+
],
|
|
209
|
+
"windowsVendorDir": "XENO",
|
|
210
|
+
"linuxDirName": "xeno",
|
|
211
|
+
"secretsKeyService": "ai.xenosystem",
|
|
212
|
+
"secretsKeyAccount": "master-key",
|
|
213
|
+
"$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."
|
|
214
|
+
};
|
|
215
|
+
exports.LEGACY_MAP_JSON = {
|
|
216
|
+
"$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 '*'.",
|
|
217
|
+
"rules": [
|
|
218
|
+
{
|
|
219
|
+
"id": "shell-window-state",
|
|
220
|
+
"legacyHome": ".xeno",
|
|
221
|
+
"match": "shell/state.json",
|
|
222
|
+
"action": "copy",
|
|
223
|
+
"target": {
|
|
224
|
+
"kind": "state",
|
|
225
|
+
"area": "apps/shell",
|
|
226
|
+
"segments": [
|
|
227
|
+
"state.json"
|
|
228
|
+
]
|
|
229
|
+
},
|
|
230
|
+
"source": "xeno-primitives/ADOPTION.md, xeno-shell row (~/.xeno/shell/state.json -> apps/shell); window state is kind state (LOCAL HOME spec section 5)"
|
|
231
|
+
}
|
|
232
|
+
]
|
|
233
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -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;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.dataAad = exports.wrapAad = exports.KEY_BYTES = void 0;
|
|
4
|
+
exports.keyIdOf = keyIdOf;
|
|
5
|
+
exports.sealSecret = sealSecret;
|
|
6
|
+
exports.parseEnvelope = parseEnvelope;
|
|
7
|
+
exports.openSecret = openSecret;
|
|
8
|
+
const node_crypto_1 = require("node:crypto");
|
|
9
|
+
const errors_ts_1 = require("./errors.js");
|
|
10
|
+
exports.KEY_BYTES = 32;
|
|
11
|
+
const NONCE_BYTES = 12;
|
|
12
|
+
const TAG_BYTES = 16;
|
|
13
|
+
const wrapAad = (area, name) => Buffer.from(`xeno-secrets:v1:wrap:${area}:${name}`, 'utf8');
|
|
14
|
+
exports.wrapAad = wrapAad;
|
|
15
|
+
const dataAad = (area, name) => Buffer.from(`xeno-secrets:v1:data:${area}:${name}`, 'utf8');
|
|
16
|
+
exports.dataAad = dataAad;
|
|
17
|
+
/** 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. */
|
|
18
|
+
function keyIdOf(masterKey) {
|
|
19
|
+
return (0, node_crypto_1.createHash)('sha256').update(masterKey).digest('hex').slice(0, 16);
|
|
20
|
+
}
|
|
21
|
+
function seal(key, nonce, plaintext, aad) {
|
|
22
|
+
const c = (0, node_crypto_1.createCipheriv)('aes-256-gcm', key, nonce);
|
|
23
|
+
c.setAAD(aad);
|
|
24
|
+
const ct = Buffer.concat([c.update(plaintext), c.final()]);
|
|
25
|
+
return Buffer.concat([ct, c.getAuthTag()]);
|
|
26
|
+
}
|
|
27
|
+
function open(key, nonce, sealed, aad) {
|
|
28
|
+
if (sealed.length < TAG_BYTES)
|
|
29
|
+
return null;
|
|
30
|
+
try {
|
|
31
|
+
const d = (0, node_crypto_1.createDecipheriv)('aes-256-gcm', key, nonce);
|
|
32
|
+
d.setAAD(aad);
|
|
33
|
+
d.setAuthTag(sealed.subarray(sealed.length - TAG_BYTES));
|
|
34
|
+
return Buffer.concat([d.update(sealed.subarray(0, sealed.length - TAG_BYTES)), d.final()]);
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function sealSecret(masterKey, area, name, plaintext, options = {}) {
|
|
41
|
+
if (masterKey.length !== exports.KEY_BYTES)
|
|
42
|
+
throw new errors_ts_1.SecretsError('invalid-argument', 'the master key must be 32 bytes');
|
|
43
|
+
const dek = options.dek ?? (0, node_crypto_1.randomBytes)(exports.KEY_BYTES);
|
|
44
|
+
const wrapNonce = options.wrapNonce ?? (0, node_crypto_1.randomBytes)(NONCE_BYTES);
|
|
45
|
+
const dataNonce = options.dataNonce ?? (0, node_crypto_1.randomBytes)(NONCE_BYTES);
|
|
46
|
+
const file = {
|
|
47
|
+
v: 1,
|
|
48
|
+
alg: 'AES-256-GCM',
|
|
49
|
+
area,
|
|
50
|
+
name,
|
|
51
|
+
keyId: keyIdOf(masterKey),
|
|
52
|
+
wrap: { nonce: Buffer.from(wrapNonce).toString('base64'), ct: seal(masterKey, wrapNonce, dek, (0, exports.wrapAad)(area, name)).toString('base64') },
|
|
53
|
+
data: { nonce: Buffer.from(dataNonce).toString('base64'), ct: seal(dek, dataNonce, plaintext, (0, exports.dataAad)(area, name)).toString('base64') },
|
|
54
|
+
createdAt: options.createdAt ?? new Date().toISOString(),
|
|
55
|
+
};
|
|
56
|
+
if (options.dek === undefined)
|
|
57
|
+
dek.fill(0);
|
|
58
|
+
return file;
|
|
59
|
+
}
|
|
60
|
+
/** Parses and shape-checks an envelope file. Throws `malformed`; never echoes file content. */
|
|
61
|
+
function parseEnvelope(text) {
|
|
62
|
+
let v;
|
|
63
|
+
try {
|
|
64
|
+
v = JSON.parse(text);
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
throw new errors_ts_1.SecretsError('malformed', 'the secret file is not valid JSON');
|
|
68
|
+
}
|
|
69
|
+
const o = v;
|
|
70
|
+
const part = (p) => typeof p === 'object' && p !== null && typeof p.nonce === 'string' && typeof p.ct === 'string';
|
|
71
|
+
if (!o || o.v !== 1 || o.alg !== 'AES-256-GCM' || typeof o.area !== 'string' || typeof o.name !== 'string' || typeof o.keyId !== 'string' || !part(o.wrap) || !part(o.data)) {
|
|
72
|
+
throw new errors_ts_1.SecretsError('malformed', 'the secret file is not a version 1 envelope');
|
|
73
|
+
}
|
|
74
|
+
return o;
|
|
75
|
+
}
|
|
76
|
+
function openSecret(masterKey, file, area, name) {
|
|
77
|
+
if (file.area !== area || file.name !== name)
|
|
78
|
+
throw new errors_ts_1.SecretsError('decrypt-failed', `the secret file does not belong at ${area}/${name}`);
|
|
79
|
+
const dek = open(masterKey, Buffer.from(file.wrap.nonce, 'base64'), Buffer.from(file.wrap.ct, 'base64'), (0, exports.wrapAad)(area, name));
|
|
80
|
+
if (dek === null) {
|
|
81
|
+
throw keyIdOf(masterKey) !== file.keyId
|
|
82
|
+
? new errors_ts_1.SecretsError('key-mismatch', `${area}/${name} was sealed with a different master key`)
|
|
83
|
+
: new errors_ts_1.SecretsError('decrypt-failed', `${area}/${name} failed authentication (damaged or tampered)`);
|
|
84
|
+
}
|
|
85
|
+
const pt = open(dek, Buffer.from(file.data.nonce, 'base64'), Buffer.from(file.data.ct, 'base64'), (0, exports.dataAad)(area, name));
|
|
86
|
+
dek.fill(0);
|
|
87
|
+
if (pt === null)
|
|
88
|
+
throw new errors_ts_1.SecretsError('decrypt-failed', `${area}/${name} failed authentication (damaged or tampered)`);
|
|
89
|
+
return pt;
|
|
90
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type SecretsErrorCode = 'unprotected-store' | 'unsupported-platform' | 'key-unavailable' | 'key-mismatch' | 'decrypt-failed' | 'malformed' | 'invalid-argument';
|
|
2
|
+
/**
|
|
3
|
+
* Every error this family throws. Messages never contain a secret value; they may name the area and the secret's
|
|
4
|
+
* name (names are not secret). `code` is stable and is what callers branch on.
|
|
5
|
+
*/
|
|
6
|
+
export declare class SecretsError extends Error {
|
|
7
|
+
readonly code: SecretsErrorCode;
|
|
8
|
+
constructor(code: SecretsErrorCode, message: string);
|
|
9
|
+
}
|
|
10
|
+
export declare function isSecretsError(e: unknown, code?: SecretsErrorCode): e is SecretsError;
|