@corenel/config 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +93 -0
- package/dist/credential.d.ts +57 -0
- package/dist/credential.d.ts.map +1 -0
- package/dist/credential.js +147 -0
- package/dist/credential.js.map +1 -0
- package/dist/daemonConfig.d.ts +56 -0
- package/dist/daemonConfig.d.ts.map +1 -0
- package/dist/daemonConfig.js +78 -0
- package/dist/daemonConfig.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/package.json +40 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
Elastic License 2.0
|
|
2
|
+
|
|
3
|
+
URL: https://www.elastic.co/licensing/elastic-license
|
|
4
|
+
|
|
5
|
+
## Acceptance
|
|
6
|
+
|
|
7
|
+
By using the software, you agree to all of the terms and conditions below.
|
|
8
|
+
|
|
9
|
+
## Copyright License
|
|
10
|
+
|
|
11
|
+
The licensor grants you a non-exclusive, royalty-free, worldwide,
|
|
12
|
+
non-sublicensable, non-transferable license to use, copy, distribute, make
|
|
13
|
+
available, and prepare derivative works of the software, in each case subject to
|
|
14
|
+
the limitations and conditions below.
|
|
15
|
+
|
|
16
|
+
## Limitations
|
|
17
|
+
|
|
18
|
+
You may not provide the software to third parties as a hosted or managed
|
|
19
|
+
service, where the service provides users with access to any substantial set of
|
|
20
|
+
the features or functionality of the software.
|
|
21
|
+
|
|
22
|
+
You may not move, change, disable, or circumvent the license key functionality
|
|
23
|
+
in the software, and you may not remove or obscure any functionality in the
|
|
24
|
+
software that is protected by the license key.
|
|
25
|
+
|
|
26
|
+
You may not alter, remove, or obscure any licensing, copyright, or other notices
|
|
27
|
+
of the licensor in the software. Any use of the licensor's trademarks is subject
|
|
28
|
+
to applicable law.
|
|
29
|
+
|
|
30
|
+
## Patents
|
|
31
|
+
|
|
32
|
+
The licensor grants you a license, under any patent claims the licensor can
|
|
33
|
+
license, or becomes able to license, to make, have made, use, sell, offer for
|
|
34
|
+
sale, import and have imported the software, in each case subject to the
|
|
35
|
+
limitations and conditions in this license. This license does not cover any
|
|
36
|
+
patent claims that you cause to be infringed by modifications or additions to
|
|
37
|
+
the software. If you or your company make any written claim that the software
|
|
38
|
+
infringes or contributes to infringement of any patent, your patent license for
|
|
39
|
+
the software granted under these terms ends immediately. If your company makes
|
|
40
|
+
such a claim, your patent license ends immediately for work on behalf of your
|
|
41
|
+
company.
|
|
42
|
+
|
|
43
|
+
## Notices
|
|
44
|
+
|
|
45
|
+
You must ensure that anyone who gets a copy of any part of the software from you
|
|
46
|
+
also gets a copy of these terms.
|
|
47
|
+
|
|
48
|
+
If you modify the software, you must include in any modified copies of the
|
|
49
|
+
software prominent notices stating that you have modified the software.
|
|
50
|
+
|
|
51
|
+
## No Other Rights
|
|
52
|
+
|
|
53
|
+
These terms do not imply any licenses other than those expressly granted in
|
|
54
|
+
these terms.
|
|
55
|
+
|
|
56
|
+
## Termination
|
|
57
|
+
|
|
58
|
+
If you use the software in violation of these terms, such use is not licensed,
|
|
59
|
+
and your licenses will automatically terminate. If the licensor provides you
|
|
60
|
+
with a notice of your violation, and you cease all violation of this license no
|
|
61
|
+
later than 30 days after you receive that notice, your licenses will be
|
|
62
|
+
reinstated retroactively. However, if you violate these terms after such
|
|
63
|
+
reinstatement, any additional violation of these terms will cause your licenses
|
|
64
|
+
to terminate automatically and permanently.
|
|
65
|
+
|
|
66
|
+
## No Liability
|
|
67
|
+
|
|
68
|
+
*As far as the law allows, the software comes as is, without any warranty or
|
|
69
|
+
condition, and the licensor will not be liable to you for any damages arising out
|
|
70
|
+
of these terms or the use or nature of the software, under any kind of legal
|
|
71
|
+
claim.*
|
|
72
|
+
|
|
73
|
+
## Definitions
|
|
74
|
+
|
|
75
|
+
The **licensor** is the entity offering these terms, and the **software** is the
|
|
76
|
+
software the licensor makes available under these terms, including any portion of
|
|
77
|
+
it.
|
|
78
|
+
|
|
79
|
+
**you** refers to the individual or entity agreeing to these terms.
|
|
80
|
+
|
|
81
|
+
**your company** is any legal entity, sole proprietorship, or other kind of
|
|
82
|
+
organization that you work for, plus all organizations that have control over, are
|
|
83
|
+
under the control of, or are under common control with that organization.
|
|
84
|
+
**control** means ownership of substantially all the assets of an entity, or the
|
|
85
|
+
power to direct its management and policies by vote, contract, or otherwise.
|
|
86
|
+
Control can be direct or indirect.
|
|
87
|
+
|
|
88
|
+
**your licenses** are all the licenses granted to you for the software under these
|
|
89
|
+
terms.
|
|
90
|
+
|
|
91
|
+
**use** means anything you do with the software requiring one of your licenses.
|
|
92
|
+
|
|
93
|
+
**trademark** means trademarks, service marks, and similar rights.
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { type StoredCredential, type CredentialSource, type ResolvedCredential } from '@corenel/tools-node';
|
|
2
|
+
/** The environment variable that carries a headless credential (surface C). */
|
|
3
|
+
export declare const TOKEN_ENV = "CORENEL_TOKEN";
|
|
4
|
+
export type { StoredCredential, CredentialSource, ResolvedCredential };
|
|
5
|
+
/** The state dir. Delegates rather than recomputing `homedir()/.corenel`: the
|
|
6
|
+
* token file and auth.json are siblings inside it, so a `--state-dir` must
|
|
7
|
+
* move both or neither, and two copies of that arithmetic is precisely how the
|
|
8
|
+
* two stores drifted apart in the first place. */
|
|
9
|
+
export declare function authDir(stateDir?: string): string;
|
|
10
|
+
export declare function credentialPath(stateDir?: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* Persist the credential 0600, AND mirror the access token into the sibling
|
|
13
|
+
* token file.
|
|
14
|
+
*
|
|
15
|
+
* PRESERVES unknown top-level keys already in the file (exactly the posture
|
|
16
|
+
* `writeDaemonConfig` already takes for daemon.json), rather than replacing
|
|
17
|
+
* the file wholesale. Without this, every sign-in and every token refresh
|
|
18
|
+
* silently wiped any sibling section written into auth.json by something
|
|
19
|
+
* else -- e.g. mcp/config.ts's `mcp` credential map -- with no error and
|
|
20
|
+
* nothing to notice it happened. No key is special-cased: whatever is
|
|
21
|
+
* foreign to StoredCredential today, or added as a sibling tomorrow, survives
|
|
22
|
+
* the same way.
|
|
23
|
+
*
|
|
24
|
+
* The mirror is not redundancy for its own sake: the gateway client and
|
|
25
|
+
* @corenel/cli read `<dir>/token`, so a sign-in that only wrote auth.json would
|
|
26
|
+
* leave the daemon reporting an account it could not actually authenticate as —
|
|
27
|
+
* the exact divergence this module was rewritten to close. Writing both here,
|
|
28
|
+
* at the one choke point every sign-in passes through, means the two readers
|
|
29
|
+
* agree the moment login returns.
|
|
30
|
+
*
|
|
31
|
+
* Best-effort chmod, as elsewhere in this package (Windows has no POSIX mode).
|
|
32
|
+
*/
|
|
33
|
+
export declare function saveCredential(cred: StoredCredential, stateDir?: string): Promise<void>;
|
|
34
|
+
/** Read the stored credential, or null when there is none. A malformed file is
|
|
35
|
+
* treated as absent rather than fatal — a corrupt credential should send the
|
|
36
|
+
* user through sign-in, not wedge the daemon. */
|
|
37
|
+
export declare function loadCredential(stateDir?: string): Promise<StoredCredential | null>;
|
|
38
|
+
/** Sign out of BOTH stores. Clearing only auth.json would leave the gateway
|
|
39
|
+
* still authenticating from the token file while the operator believes they
|
|
40
|
+
* signed out — worse than the bug pointing the other way, because it is
|
|
41
|
+
* silent. */
|
|
42
|
+
export declare function clearCredential(stateDir?: string): Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* Resolve the credential to use — a thin adapter over the shared resolver so
|
|
45
|
+
* this daemon and the gateway client can never answer differently.
|
|
46
|
+
*
|
|
47
|
+
* The environment wins deliberately: it is how a container, a CI job or an SSH
|
|
48
|
+
* session supplies identity, and those are exactly the places where a stored
|
|
49
|
+
* file may be a stale artifact of some earlier image build. An explicit env var
|
|
50
|
+
* is a present-tense statement of intent; a file is not.
|
|
51
|
+
*
|
|
52
|
+
* An expired stored token is reported, not silently used — the caller decides
|
|
53
|
+
* whether to refresh or re-prompt, and a caller that ignores `expired` fails at
|
|
54
|
+
* the gateway rather than here.
|
|
55
|
+
*/
|
|
56
|
+
export declare function resolveCredential(env?: NodeJS.ProcessEnv, stateDir?: string, now?: () => number): Promise<ResolvedCredential>;
|
|
57
|
+
//# sourceMappingURL=credential.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credential.d.ts","sourceRoot":"","sources":["../src/credential.ts"],"names":[],"mappings":"AAgCA,OAAO,EAGL,KAAK,gBAAgB,EAAE,KAAK,gBAAgB,EAAE,KAAK,kBAAkB,EACtE,MAAM,qBAAqB,CAAC;AAE7B,+EAA+E;AAC/E,eAAO,MAAM,SAAS,kBAAiB,CAAC;AAExC,YAAY,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,CAAC;AAEvE;;;mDAGmD;AACnD,wBAAgB,OAAO,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAEjD;AAED,wBAAgB,cAAc,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAExD;AAqCD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAsB,cAAc,CAAC,IAAI,EAAE,gBAAgB,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAY7F;AAED;;iDAEiD;AACjD,wBAAsB,cAAc,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC,CAExF;AAED;;;cAGc;AACd,wBAAsB,eAAe,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAEtE;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,iBAAiB,CACrC,GAAG,GAAE,MAAM,CAAC,UAAwB,EACpC,QAAQ,CAAC,EAAE,MAAM,EACjB,GAAG,GAAE,MAAM,MAAiB,GAC3B,OAAO,CAAC,kBAAkB,CAAC,CAE7B"}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/* Where the user's sign-in credential lives, and how it is resolved.
|
|
2
|
+
*
|
|
3
|
+
* THREE AUTH SURFACES, per spec s8.3.1. Keeping them apart is the whole point of
|
|
4
|
+
* this module living separately from token.ts:
|
|
5
|
+
*
|
|
6
|
+
* A user identity who is this person? <- THIS FILE
|
|
7
|
+
* B pairing may this process talk to this
|
|
8
|
+
* sidecar's port? <- token.ts (daemon.token)
|
|
9
|
+
* C headless identity where no browser exists <- CORENEL_TOKEN, below
|
|
10
|
+
*
|
|
11
|
+
* Surface B is explicitly NOT authority: the pairing token authenticates a
|
|
12
|
+
* connection, it does not say who the user is. Merging the two would turn "can
|
|
13
|
+
* reach the port" into "is the account owner", which is a privilege escalation,
|
|
14
|
+
* not a simplification.
|
|
15
|
+
*
|
|
16
|
+
* Storage is a 0600 file under the state dir, matching how the pairing token,
|
|
17
|
+
* the sidecar id and the self-signed key are already stored. An OS keychain is
|
|
18
|
+
* the better home and the port below is shaped for one, but every cross-platform
|
|
19
|
+
* keychain route costs either a native dependency or shelling out to three
|
|
20
|
+
* different binaries — deferred deliberately rather than by omission.
|
|
21
|
+
*
|
|
22
|
+
* WHAT CHANGED, and why this file is now thin: surface A is written in TWO
|
|
23
|
+
* places on a real machine — this `auth.json`, and the `<dir>/token` file that
|
|
24
|
+
* `corenel login` writes and the gateway client reads. Resolving them
|
|
25
|
+
* independently is what let `corenel-sidecar auth` print "Not signed in" on a
|
|
26
|
+
* machine that was running models fine. So resolution, precedence and sign-out
|
|
27
|
+
* all live in @corenel/tools-node's auth module now (which the gateway client
|
|
28
|
+
* already depends on), and this file keeps only the auth.json format plus the
|
|
29
|
+
* mirroring that keeps the two stores from diverging in the first place. The
|
|
30
|
+
* precedence is documented there, once.
|
|
31
|
+
*/
|
|
32
|
+
import { promises as fs } from 'node:fs';
|
|
33
|
+
import { credentialDir, credentialFilePath, readCredentialFile, clearAllCredentials, resolveNodeCredential, writeAuthToken, TOKEN_ENV as NODE_TOKEN_ENV, } from '@corenel/tools-node';
|
|
34
|
+
/** The environment variable that carries a headless credential (surface C). */
|
|
35
|
+
export const TOKEN_ENV = NODE_TOKEN_ENV;
|
|
36
|
+
/** The state dir. Delegates rather than recomputing `homedir()/.corenel`: the
|
|
37
|
+
* token file and auth.json are siblings inside it, so a `--state-dir` must
|
|
38
|
+
* move both or neither, and two copies of that arithmetic is precisely how the
|
|
39
|
+
* two stores drifted apart in the first place. */
|
|
40
|
+
export function authDir(stateDir) {
|
|
41
|
+
return credentialDir(stateDir);
|
|
42
|
+
}
|
|
43
|
+
export function credentialPath(stateDir) {
|
|
44
|
+
return credentialFilePath(stateDir);
|
|
45
|
+
}
|
|
46
|
+
/** Every top-level field `StoredCredential` itself owns. Stripped from
|
|
47
|
+
* whatever is already on disk before the new credential is laid on top, so a
|
|
48
|
+
* field this sign-in no longer sets (e.g. a dropped `refreshToken`) does not
|
|
49
|
+
* survive as a stale leftover of the PREVIOUS credential. */
|
|
50
|
+
const STORED_CREDENTIAL_KEYS = ['accessToken', 'refreshToken', 'expiresAt', 'account', 'apiBase'];
|
|
51
|
+
/**
|
|
52
|
+
* The file's existing top-level keys that are NOT StoredCredential's own --
|
|
53
|
+
* i.e. everything a sibling writer (packages/sidecar/src/mcp/config.ts's `mcp`
|
|
54
|
+
* section, and whatever the next one is) has put there.
|
|
55
|
+
*
|
|
56
|
+
* Absent or unreadable is treated as "nothing to preserve", not an error --
|
|
57
|
+
* the same posture `loadCredential` already takes on a malformed file. A
|
|
58
|
+
* sign-in must never be the thing that fails because an unrelated section of
|
|
59
|
+
* this file got corrupted.
|
|
60
|
+
*/
|
|
61
|
+
async function readForeignAuthJson(path) {
|
|
62
|
+
let raw;
|
|
63
|
+
try {
|
|
64
|
+
raw = await fs.readFile(path, 'utf8');
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
return {};
|
|
68
|
+
}
|
|
69
|
+
try {
|
|
70
|
+
const parsed = JSON.parse(raw);
|
|
71
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed))
|
|
72
|
+
return {};
|
|
73
|
+
const obj = { ...parsed };
|
|
74
|
+
for (const k of STORED_CREDENTIAL_KEYS)
|
|
75
|
+
delete obj[k];
|
|
76
|
+
return obj;
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
return {};
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Persist the credential 0600, AND mirror the access token into the sibling
|
|
84
|
+
* token file.
|
|
85
|
+
*
|
|
86
|
+
* PRESERVES unknown top-level keys already in the file (exactly the posture
|
|
87
|
+
* `writeDaemonConfig` already takes for daemon.json), rather than replacing
|
|
88
|
+
* the file wholesale. Without this, every sign-in and every token refresh
|
|
89
|
+
* silently wiped any sibling section written into auth.json by something
|
|
90
|
+
* else -- e.g. mcp/config.ts's `mcp` credential map -- with no error and
|
|
91
|
+
* nothing to notice it happened. No key is special-cased: whatever is
|
|
92
|
+
* foreign to StoredCredential today, or added as a sibling tomorrow, survives
|
|
93
|
+
* the same way.
|
|
94
|
+
*
|
|
95
|
+
* The mirror is not redundancy for its own sake: the gateway client and
|
|
96
|
+
* @corenel/cli read `<dir>/token`, so a sign-in that only wrote auth.json would
|
|
97
|
+
* leave the daemon reporting an account it could not actually authenticate as —
|
|
98
|
+
* the exact divergence this module was rewritten to close. Writing both here,
|
|
99
|
+
* at the one choke point every sign-in passes through, means the two readers
|
|
100
|
+
* agree the moment login returns.
|
|
101
|
+
*
|
|
102
|
+
* Best-effort chmod, as elsewhere in this package (Windows has no POSIX mode).
|
|
103
|
+
*/
|
|
104
|
+
export async function saveCredential(cred, stateDir) {
|
|
105
|
+
const path = credentialPath(stateDir);
|
|
106
|
+
await fs.mkdir(authDir(stateDir), { recursive: true });
|
|
107
|
+
const foreign = await readForeignAuthJson(path);
|
|
108
|
+
const next = { ...foreign, ...cred };
|
|
109
|
+
await fs.writeFile(path, JSON.stringify(next, null, 2) + '\n', { mode: 0o600 });
|
|
110
|
+
try {
|
|
111
|
+
await fs.chmod(path, 0o600);
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
/* best effort on platforms without POSIX modes */
|
|
115
|
+
}
|
|
116
|
+
await writeAuthToken(cred.accessToken, stateDir);
|
|
117
|
+
}
|
|
118
|
+
/** Read the stored credential, or null when there is none. A malformed file is
|
|
119
|
+
* treated as absent rather than fatal — a corrupt credential should send the
|
|
120
|
+
* user through sign-in, not wedge the daemon. */
|
|
121
|
+
export async function loadCredential(stateDir) {
|
|
122
|
+
return await readCredentialFile(stateDir);
|
|
123
|
+
}
|
|
124
|
+
/** Sign out of BOTH stores. Clearing only auth.json would leave the gateway
|
|
125
|
+
* still authenticating from the token file while the operator believes they
|
|
126
|
+
* signed out — worse than the bug pointing the other way, because it is
|
|
127
|
+
* silent. */
|
|
128
|
+
export async function clearCredential(stateDir) {
|
|
129
|
+
await clearAllCredentials(stateDir);
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Resolve the credential to use — a thin adapter over the shared resolver so
|
|
133
|
+
* this daemon and the gateway client can never answer differently.
|
|
134
|
+
*
|
|
135
|
+
* The environment wins deliberately: it is how a container, a CI job or an SSH
|
|
136
|
+
* session supplies identity, and those are exactly the places where a stored
|
|
137
|
+
* file may be a stale artifact of some earlier image build. An explicit env var
|
|
138
|
+
* is a present-tense statement of intent; a file is not.
|
|
139
|
+
*
|
|
140
|
+
* An expired stored token is reported, not silently used — the caller decides
|
|
141
|
+
* whether to refresh or re-prompt, and a caller that ignores `expired` fails at
|
|
142
|
+
* the gateway rather than here.
|
|
143
|
+
*/
|
|
144
|
+
export async function resolveCredential(env = process.env, stateDir, now = Date.now) {
|
|
145
|
+
return await resolveNodeCredential({ env, now, ...(stateDir ? { stateDir } : {}) });
|
|
146
|
+
}
|
|
147
|
+
//# sourceMappingURL=credential.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credential.js","sourceRoot":"","sources":["../src/credential.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;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OAAO,MAAM,qBAAqB,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;AACtF,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
export declare const DAEMON_CONFIG_VERSION = 1;
|
|
2
|
+
export interface DaemonConfig {
|
|
3
|
+
version: number;
|
|
4
|
+
port?: number;
|
|
5
|
+
host?: string;
|
|
6
|
+
roots?: string[];
|
|
7
|
+
addUnder?: string[];
|
|
8
|
+
cloneUnder?: string[];
|
|
9
|
+
allowLan?: boolean;
|
|
10
|
+
allowOrigins?: string[];
|
|
11
|
+
tlsCert?: string;
|
|
12
|
+
tlsKey?: string;
|
|
13
|
+
selfSigned?: boolean;
|
|
14
|
+
tunnel?: string;
|
|
15
|
+
tunnelName?: string;
|
|
16
|
+
tunnelHostname?: string;
|
|
17
|
+
endpoint?: string;
|
|
18
|
+
allowShell?: boolean;
|
|
19
|
+
keepTranscripts?: boolean;
|
|
20
|
+
isolation?: string;
|
|
21
|
+
msbBin?: string;
|
|
22
|
+
guestImage?: string;
|
|
23
|
+
maxChainDepth?: number;
|
|
24
|
+
name?: string;
|
|
25
|
+
appUrl?: string;
|
|
26
|
+
defaultModel?: string;
|
|
27
|
+
/** {name,url} pairs only -- never a credential. See packages/sidecar/src/mcp/. */
|
|
28
|
+
mcpServers?: {
|
|
29
|
+
name: string;
|
|
30
|
+
url: string;
|
|
31
|
+
}[];
|
|
32
|
+
/** `mcp:<server>/<tool>` addresses the daemon's OWN agent loop may call --
|
|
33
|
+
* see `daemonTools.ts`'s module comment. Absent or empty grants NOTHING:
|
|
34
|
+
* `registerMcpTools` builds its policy by putting this list into
|
|
35
|
+
* `tools.allow` on top of `BUILTIN_POLICIES.standard`, which is
|
|
36
|
+
* deny-by-default, so a machine that never sets this is exactly as locked
|
|
37
|
+
* down as one that predates the key. A plain `string[]`, not its own
|
|
38
|
+
* command, so `corenel config add|remove|list mcpAllow` work for free. */
|
|
39
|
+
mcpAllow?: string[];
|
|
40
|
+
}
|
|
41
|
+
/** Keys this file must never carry. `--acp-auth` and tunnel credentials belong
|
|
42
|
+
* in auth.json: daemon.json is meant to be safe to paste into a support thread
|
|
43
|
+
* and to copy to another laptop, and it is neither the moment a secret can
|
|
44
|
+
* land in it. */
|
|
45
|
+
export declare const SECRET_KEYS: readonly string[];
|
|
46
|
+
/** Every key the config may carry — anything else is someone else's and is
|
|
47
|
+
* preserved untouched rather than dropped. */
|
|
48
|
+
export declare const KNOWN_KEYS: readonly (keyof DaemonConfig)[];
|
|
49
|
+
export declare function daemonConfigPath(stateDir: string): string;
|
|
50
|
+
export declare function readDaemonConfig(stateDir: string): Promise<{
|
|
51
|
+
config: DaemonConfig;
|
|
52
|
+
unknown: Record<string, unknown>;
|
|
53
|
+
corrupt: boolean;
|
|
54
|
+
}>;
|
|
55
|
+
export declare function writeDaemonConfig(stateDir: string, next: DaemonConfig, unknown?: Record<string, unknown>): Promise<void>;
|
|
56
|
+
//# sourceMappingURL=daemonConfig.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"daemonConfig.d.ts","sourceRoot":"","sources":["../src/daemonConfig.ts"],"names":[],"mappings":"AAgBA,eAAO,MAAM,qBAAqB,IAAI,CAAC;AAEvC,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,OAAO,CAAC,EAAE,MAAM,CAAC;IAC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EAClB,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GACpC,OAAO,CAAC,IAAI,CAAC,CAKf"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/* THE MACHINE'S OWN SETTINGS, as a file the operator can read.
|
|
2
|
+
*
|
|
3
|
+
* `args.ts` parses 32 flags and reads no file, so every durable fact about a
|
|
4
|
+
* machine -- its roots, its certificate, its name, its policy -- is retyped on
|
|
5
|
+
* every start, and nothing can report how a running daemon was configured.
|
|
6
|
+
* Roughly 24 of those flags describe a MACHINE rather than an invocation.
|
|
7
|
+
*
|
|
8
|
+
* Two rules hold this together. A read never throws: a daemon whose config is
|
|
9
|
+
* missing or corrupt starts on defaults rather than refusing to start. And a
|
|
10
|
+
* write merges: re-running setup with one new root leaves everything else
|
|
11
|
+
* exactly as it was, because a command that silently drops last month's
|
|
12
|
+
* settings is worse than the flag wall it replaces.
|
|
13
|
+
*/
|
|
14
|
+
import { readFile, writeFile, mkdir } from 'node:fs/promises';
|
|
15
|
+
import { dirname, join } from 'node:path';
|
|
16
|
+
export const DAEMON_CONFIG_VERSION = 1;
|
|
17
|
+
/** Keys this file must never carry. `--acp-auth` and tunnel credentials belong
|
|
18
|
+
* in auth.json: daemon.json is meant to be safe to paste into a support thread
|
|
19
|
+
* and to copy to another laptop, and it is neither the moment a secret can
|
|
20
|
+
* land in it. */
|
|
21
|
+
export const SECRET_KEYS = ['acpAuth', 'tunnelToken', 'token'];
|
|
22
|
+
/** Every key the config may carry — anything else is someone else's and is
|
|
23
|
+
* preserved untouched rather than dropped. */
|
|
24
|
+
export const KNOWN_KEYS = [
|
|
25
|
+
'version', 'port', 'host', 'roots', 'addUnder', 'cloneUnder', 'allowLan',
|
|
26
|
+
'allowOrigins', 'tlsCert', 'tlsKey', 'selfSigned', 'tunnel', 'tunnelName',
|
|
27
|
+
'tunnelHostname', 'endpoint', 'allowShell', 'keepTranscripts', 'isolation',
|
|
28
|
+
'msbBin', 'guestImage', 'maxChainDepth', 'name', 'appUrl',
|
|
29
|
+
'defaultModel', 'mcpServers', 'mcpAllow',
|
|
30
|
+
];
|
|
31
|
+
export function daemonConfigPath(stateDir) {
|
|
32
|
+
return join(stateDir, 'daemon.json');
|
|
33
|
+
}
|
|
34
|
+
export async function readDaemonConfig(stateDir) {
|
|
35
|
+
// `corrupt` is `false` for "no file yet" (the ordinary fresh-machine case) and
|
|
36
|
+
// `true` only when a file EXISTS but could not be trusted as-is (bad JSON, or
|
|
37
|
+
// valid JSON that isn't an object). Never throws either way -- a daemon must
|
|
38
|
+
// still start on defaults -- but the caller can now tell the two apart and
|
|
39
|
+
// say so, instead of a typo'd file silently vanishing into "just defaults".
|
|
40
|
+
const empty = (corrupt) => ({ config: { version: DAEMON_CONFIG_VERSION }, unknown: {}, corrupt });
|
|
41
|
+
let raw;
|
|
42
|
+
try {
|
|
43
|
+
raw = await readFile(daemonConfigPath(stateDir), 'utf8');
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return empty(false); // no file yet: the ordinary case on a fresh machine
|
|
47
|
+
}
|
|
48
|
+
let parsed;
|
|
49
|
+
try {
|
|
50
|
+
parsed = JSON.parse(raw);
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
return empty(true); // corrupt: start on defaults rather than not at all
|
|
54
|
+
}
|
|
55
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed))
|
|
56
|
+
return empty(true);
|
|
57
|
+
const src = parsed;
|
|
58
|
+
const config = { version: DAEMON_CONFIG_VERSION };
|
|
59
|
+
const unknown = {};
|
|
60
|
+
for (const [k, v] of Object.entries(src)) {
|
|
61
|
+
if (k === 'version')
|
|
62
|
+
continue;
|
|
63
|
+
if (KNOWN_KEYS.includes(k)) {
|
|
64
|
+
config[k] = v;
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
unknown[k] = v;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return { config, unknown, corrupt: false };
|
|
71
|
+
}
|
|
72
|
+
export async function writeDaemonConfig(stateDir, next, unknown = {}) {
|
|
73
|
+
const body = { ...unknown, ...next, version: DAEMON_CONFIG_VERSION };
|
|
74
|
+
const path = daemonConfigPath(stateDir);
|
|
75
|
+
await mkdir(dirname(path), { recursive: true });
|
|
76
|
+
await writeFile(path, `${JSON.stringify(body, null, 2)}\n`, 'utf8');
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=daemonConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"daemonConfig.js","sourceRoot":"","sources":["../src/daemonConfig.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAE1C,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC;AAuCvC;;;iBAGiB;AACjB,MAAM,CAAC,MAAM,WAAW,GAAsB,CAAC,SAAS,EAAE,aAAa,EAAE,OAAO,CAAC,CAAC;AAElF;8CAC8C;AAC9C,MAAM,CAAC,MAAM,UAAU,GAAoC;IACzD,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,UAAU;IACxE,cAAc,EAAE,SAAS,EAAE,QAAQ,EAAE,YAAY,EAAE,QAAQ,EAAE,YAAY;IACzE,gBAAgB,EAAE,UAAU,EAAE,YAAY,EAAE,iBAAiB,EAAE,WAAW;IAC1E,QAAQ,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,EAAE,QAAQ;IACzD,cAAc,EAAE,YAAY,EAAE,UAAU;CACzC,CAAC;AAEF,MAAM,UAAU,gBAAgB,CAAC,QAAgB;IAC/C,OAAO,IAAI,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAC;AACvC,CAAC;AAED,MAAM,CAAC,KAAK,UAAU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CAAC;QACxD,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;QACjB,CAAC;IACH,CAAC;IACD,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;AAC7C,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,QAAgB,EAChB,IAAkB,EAClB,UAAmC,EAAE;IAErC,MAAM,IAAI,GAAG,EAAE,GAAG,OAAO,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,qBAAqB,EAAE,CAAC;IACrE,MAAM,IAAI,GAAG,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IACxC,MAAM,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAChD,MAAM,SAAS,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;AACtE,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@corenel/config",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"license": "Elastic-2.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"description": "Corenel config — the single reader and writer of the dot-dir's daemon.json and auth.json. Two independent readers of one file drift, and the symptom is silence.",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"default": "./dist/index.js"
|
|
11
|
+
},
|
|
12
|
+
"./*": {
|
|
13
|
+
"types": "./dist/*.d.ts",
|
|
14
|
+
"default": "./dist/*.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@corenel/tools-node": "0.4.0"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@types/node": "^24.13.1",
|
|
25
|
+
"typescript": "^5.9.3"
|
|
26
|
+
},
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
},
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "git+https://github.com/Prompd/prompd-web.git",
|
|
33
|
+
"directory": "packages/config"
|
|
34
|
+
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"typecheck": "tsc --noEmit",
|
|
37
|
+
"prebuild": "pnpm --filter @corenel/tools-node build",
|
|
38
|
+
"build": "node build.mjs"
|
|
39
|
+
}
|
|
40
|
+
}
|