@solidactions/cli 3.24.0 → 3.26.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 +2 -0
- package/dist/command-manifest.json +115 -1
- package/dist/commands/connection-connect.js +77 -0
- package/dist/commands/connection-list.js +26 -16
- package/dist/commands/connection-wait.js +234 -0
- package/dist/commands/device-login.js +24 -16
- package/dist/commands/doc-pull.js +674 -172
- package/dist/index.js +18 -0
- package/dist/utils/api.js +17 -3
- package/dist/utils/connect-link.js +63 -0
- package/dist/utils/doc-pull-writes.js +342 -0
- package/dist/utils/docs-manifest.js +22 -3
- package/dist/utils/mutating-commands.js +3 -0
- package/dist/utils/output.js +22 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -73,6 +73,8 @@ const oauth_action_search_1 = require("./commands/oauth-action-search");
|
|
|
73
73
|
const oauth_action_list_1 = require("./commands/oauth-action-list");
|
|
74
74
|
const oauth_action_view_1 = require("./commands/oauth-action-view");
|
|
75
75
|
const oauth_action_platforms_1 = require("./commands/oauth-action-platforms");
|
|
76
|
+
const connection_connect_1 = require("./commands/connection-connect");
|
|
77
|
+
const connection_wait_1 = require("./commands/connection-wait");
|
|
76
78
|
const connection_list_1 = require("./commands/connection-list");
|
|
77
79
|
const workspaces_1 = require("./commands/workspaces");
|
|
78
80
|
const skill_push_1 = require("./commands/skill-push");
|
|
@@ -904,6 +906,22 @@ connection
|
|
|
904
906
|
.action(() => {
|
|
905
907
|
(0, connection_list_1.connectionList)();
|
|
906
908
|
});
|
|
909
|
+
connection
|
|
910
|
+
.command('connect [platform]')
|
|
911
|
+
.description('Mint a connect link a person clicks to connect an app, then print it and the wait command')
|
|
912
|
+
.option('--name <name>', 'Name of the new connection')
|
|
913
|
+
.option('--reconnect <name>', 'Refresh an existing connection instead (its platform is looked up when omitted)')
|
|
914
|
+
.option('--bind <project:var>', 'Bind a project variable to the connection once it is connected (repeatable, up to 10)', (value, previous = []) => [...previous, value], [])
|
|
915
|
+
.action((platform, options) => {
|
|
916
|
+
(0, connection_connect_1.connectionConnect)(platform, options);
|
|
917
|
+
});
|
|
918
|
+
connection
|
|
919
|
+
.command('wait <request-id>')
|
|
920
|
+
.description('Wait until a connect link is used: exit 0 connected, 1 expired, cancelled or failed, 2 still open at --timeout, 130 on Ctrl-C')
|
|
921
|
+
.option('--timeout <duration>', 'How long to wait, e.g. 30s, 15m, 1h', '15m')
|
|
922
|
+
.action((requestId, options) => {
|
|
923
|
+
(0, connection_wait_1.connectionWait)(requestId, options);
|
|
924
|
+
});
|
|
907
925
|
// =============================================================================
|
|
908
926
|
// ai <subcommand>
|
|
909
927
|
// =============================================================================
|
package/dist/utils/api.js
CHANGED
|
@@ -149,9 +149,10 @@ function augmentWorkspaceForbiddenMessage(error) {
|
|
|
149
149
|
return error;
|
|
150
150
|
}
|
|
151
151
|
/**
|
|
152
|
-
* Existing device tokens predate the coarse `databases`
|
|
153
|
-
*
|
|
154
|
-
*
|
|
152
|
+
* Existing device tokens predate the coarse `databases`, `env:reveal` and
|
|
153
|
+
* `connections:request` abilities. Turn the app's stable missing-ability
|
|
154
|
+
* response into a re-login instruction while preserving its original message.
|
|
155
|
+
* Other ability failures retain their existing behavior.
|
|
155
156
|
*/
|
|
156
157
|
function augmentTokenMissingAbilityMessage(error) {
|
|
157
158
|
const response = error?.response;
|
|
@@ -184,6 +185,19 @@ function augmentTokenMissingAbilityMessage(error) {
|
|
|
184
185
|
response.data.message = `${message}\n\n${hint}`;
|
|
185
186
|
}
|
|
186
187
|
}
|
|
188
|
+
if (response?.status === 403
|
|
189
|
+
&& response.data?.code === 'token_missing_ability'
|
|
190
|
+
&& requiredAbility === 'connections:request') {
|
|
191
|
+
const hint = "Connect links need the 'connections:request' ability. "
|
|
192
|
+
+ 'Run `solidactions login --device` again to get it, or create an API key with '
|
|
193
|
+
+ "'connections:request' checked at Settings → API keys and `solidactions login` with that key.";
|
|
194
|
+
const message = typeof response.data.message === 'string' && response.data.message.length > 0
|
|
195
|
+
? response.data.message
|
|
196
|
+
: "This session does not have the 'connections:request' ability.";
|
|
197
|
+
if (!message.includes('Connect links need')) {
|
|
198
|
+
response.data.message = `${message}\n\n${hint}`;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
187
201
|
return error;
|
|
188
202
|
}
|
|
189
203
|
axios_1.default.interceptors.response.use((response) => response, (error) => Promise.reject(augmentTokenMissingAbilityMessage(augmentWorkspaceForbiddenMessage(augmentNotFoundMessage(augmentSandboxEgressMessage(error))))));
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CONNECT_LINK_MAX_BINDINGS = void 0;
|
|
4
|
+
exports.parseBinding = parseBinding;
|
|
5
|
+
exports.plainText = plainText;
|
|
6
|
+
exports.shellArg = shellArg;
|
|
7
|
+
exports.waitCommandLine = waitCommandLine;
|
|
8
|
+
exports.formatExpiry = formatExpiry;
|
|
9
|
+
exports.connectLinkFailureLine = connectLinkFailureLine;
|
|
10
|
+
const api_1 = require("./api");
|
|
11
|
+
exports.CONNECT_LINK_MAX_BINDINGS = 10;
|
|
12
|
+
/** 'PROJECT:VAR' → {project, var}; split at the first ':'; both sides trimmed and non-empty, else throws Error with a one-line message. */
|
|
13
|
+
function parseBinding(value) {
|
|
14
|
+
const index = value.indexOf(':');
|
|
15
|
+
const project = index === -1 ? '' : value.slice(0, index).trim();
|
|
16
|
+
const variable = index === -1 ? '' : value.slice(index + 1).trim();
|
|
17
|
+
if (project === '' || variable === '') {
|
|
18
|
+
throw new Error(`--bind must be PROJECT:VAR (got "${plainText(value)}")`);
|
|
19
|
+
}
|
|
20
|
+
return { project, var: variable };
|
|
21
|
+
}
|
|
22
|
+
/** Removes C0/C1 control characters (U+0000-U+0008, U+000B-U+001F, U+007F-U+009F), keeping '\n' and '\t'. */
|
|
23
|
+
function plainText(value) {
|
|
24
|
+
return value.replace(/[\u0000-\u0008\u000B-\u001F\u007F-\u009F]/g, '');
|
|
25
|
+
}
|
|
26
|
+
const SHELL_SAFE = /^[A-Za-z0-9_@%+=:,.\/-]+$/;
|
|
27
|
+
/**
|
|
28
|
+
* Quote a value for pasting into a POSIX shell command line. Values of
|
|
29
|
+
* letters, digits and a few safe punctuation marks stay bare; anything else
|
|
30
|
+
* (spaces, quotes, `;`, `&`, …) is single-quoted (`'` → `'\''`), so the
|
|
31
|
+
* suggestion still parses as the same single argument.
|
|
32
|
+
*/
|
|
33
|
+
function shellArg(value) {
|
|
34
|
+
if (SHELL_SAFE.test(value)) {
|
|
35
|
+
return value;
|
|
36
|
+
}
|
|
37
|
+
return `'${value.replace(/'/g, `'\\''`)}'`;
|
|
38
|
+
}
|
|
39
|
+
/** 'solidactions connection wait <id>' (the id is quoted unless it is shell-safe, e.g. a ULID). */
|
|
40
|
+
function waitCommandLine(id) {
|
|
41
|
+
return `solidactions connection wait ${shellArg(id)}`;
|
|
42
|
+
}
|
|
43
|
+
/** '2026-10-29T19:00:00Z' → '2026-10-29 19:00 UTC' (the server's own `text` format); a value Date cannot parse → plainText(value); a non-string → 'unknown'. */
|
|
44
|
+
function formatExpiry(iso) {
|
|
45
|
+
if (typeof iso !== 'string') {
|
|
46
|
+
return 'unknown';
|
|
47
|
+
}
|
|
48
|
+
const d = new Date(iso);
|
|
49
|
+
if (Number.isNaN(d.getTime())) {
|
|
50
|
+
return plainText(iso);
|
|
51
|
+
}
|
|
52
|
+
return `${d.toISOString().slice(0, 10)} ${d.toISOString().slice(11, 16)} UTC`;
|
|
53
|
+
}
|
|
54
|
+
/** The one line for a failed request: 401 → authFailedLine(host); a response → formatApiFailure(status, data); none → 'Connection failed: <message>'. */
|
|
55
|
+
function connectLinkFailureLine(error, host) {
|
|
56
|
+
if (error?.response?.status === 401) {
|
|
57
|
+
return (0, api_1.authFailedLine)(host);
|
|
58
|
+
}
|
|
59
|
+
if (error?.response) {
|
|
60
|
+
return (0, api_1.formatApiFailure)(error.response.status, error.response.data);
|
|
61
|
+
}
|
|
62
|
+
return `Connection failed: ${error?.message ?? String(error)}`;
|
|
63
|
+
}
|
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.LockHeldError = exports.UnsupportedTargetError = exports.WriteStepError = exports.PublicationRefusedError = exports.LinkOnTheWayError = exports.nameKey = exports.lockNameFor = void 0;
|
|
7
|
+
exports.isReservedName = isReservedName;
|
|
8
|
+
exports.faultsFromEnv = faultsFromEnv;
|
|
9
|
+
exports.ensureRealDirs = ensureRealDirs;
|
|
10
|
+
exports.writeAll = writeAll;
|
|
11
|
+
exports.acquireLock = acquireLock;
|
|
12
|
+
exports.releaseLock = releaseLock;
|
|
13
|
+
exports.writeFileAtomic = writeFileAtomic;
|
|
14
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
15
|
+
const fs_1 = __importDefault(require("fs"));
|
|
16
|
+
const path_1 = __importDefault(require("path"));
|
|
17
|
+
/**
|
|
18
|
+
* doc pull's write path (cli#168, cli#188, cli#182; spec §1, PM ruling 12). The pull stops at the first error and
|
|
19
|
+
* records exactly what it wrote: each file is written to a sibling temp file (opened O_WRONLY|O_CREAT|O_EXCL|O_NOFOLLOW)
|
|
20
|
+
* and renamed into place, after the target is re-checked against the state the preflight saw; the caller then writes the
|
|
21
|
+
* manifest once. A rename replaces the directory entry, so a hard link's other names keep their bytes and a link at the
|
|
22
|
+
* final name is replaced, not followed. The pull never deletes, moves or restores anything it did not create in this run
|
|
23
|
+
* (its own temp file, and its own lock file, are the only things it removes here), so there is nothing to roll back.
|
|
24
|
+
* One O_EXCL lock file in the destination root keeps two pulls apart. Node has no openat: a directory component swapped
|
|
25
|
+
* for a link, or a final component changed between its check and its rename, is a documented residual race in the
|
|
26
|
+
* user's own folder (spec §1.6). No power-loss durability is claimed.
|
|
27
|
+
*/
|
|
28
|
+
const O_NOFOLLOW = fs_1.default.constants.O_NOFOLLOW ?? 0;
|
|
29
|
+
const NEW_FILE_FLAGS = fs_1.default.constants.O_WRONLY | fs_1.default.constants.O_CREAT | fs_1.default.constants.O_EXCL | O_NOFOLLOW;
|
|
30
|
+
/** The name prefix of writeFileAtomic's temp files; reserved with the manifest and its lock (spec §1.3 Names). */
|
|
31
|
+
const TEMP_PREFIX = '.sa-write-';
|
|
32
|
+
/** The lock file's name beside a manifest. */
|
|
33
|
+
const lockNameFor = (manifestName) => `${manifestName}.lock`;
|
|
34
|
+
exports.lockNameFor = lockNameFor;
|
|
35
|
+
/**
|
|
36
|
+
* The key two names are compared by: composed (NFC) and lower-cased, so spellings one filesystem or
|
|
37
|
+
* another treats as one entry get one key (spec §1.3, cli#168).
|
|
38
|
+
*/
|
|
39
|
+
const nameKey = (name) => name.normalize('NFC').toLowerCase().normalize('NFC');
|
|
40
|
+
exports.nameKey = nameKey;
|
|
41
|
+
/** A name doc pull keeps for itself at every level: the manifest, its lock, and the temp-file prefix (spec §1.3). */
|
|
42
|
+
function isReservedName(name, manifestName) {
|
|
43
|
+
const key = (0, exports.nameKey)(name);
|
|
44
|
+
return key === (0, exports.nameKey)(manifestName) || key === (0, exports.nameKey)((0, exports.lockNameFor)(manifestName)) || key.startsWith((0, exports.nameKey)(TEMP_PREFIX));
|
|
45
|
+
}
|
|
46
|
+
class LinkOnTheWayError extends Error {
|
|
47
|
+
component;
|
|
48
|
+
constructor(component) {
|
|
49
|
+
super(`${component} is a symbolic link or not a directory`);
|
|
50
|
+
this.component = component;
|
|
51
|
+
this.name = 'LinkOnTheWayError';
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.LinkOnTheWayError = LinkOnTheWayError;
|
|
55
|
+
class PublicationRefusedError extends Error {
|
|
56
|
+
relPath;
|
|
57
|
+
constructor(relPath) {
|
|
58
|
+
super(`${relPath} changed after doc pull checked it`);
|
|
59
|
+
this.relPath = relPath;
|
|
60
|
+
this.name = 'PublicationRefusedError';
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.PublicationRefusedError = PublicationRefusedError;
|
|
64
|
+
class WriteStepError extends Error {
|
|
65
|
+
relPath;
|
|
66
|
+
cause;
|
|
67
|
+
constructor(relPath, cause) {
|
|
68
|
+
super(cause instanceof Error ? cause.message : String(cause));
|
|
69
|
+
this.relPath = relPath;
|
|
70
|
+
this.cause = cause;
|
|
71
|
+
this.name = 'WriteStepError';
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
exports.WriteStepError = WriteStepError;
|
|
75
|
+
/** Ruling 9: a folder (or any entry that is neither a file nor a link) at a target is never moved or deleted. */
|
|
76
|
+
class UnsupportedTargetError extends Error {
|
|
77
|
+
relPath;
|
|
78
|
+
constructor(relPath) {
|
|
79
|
+
super(`${relPath} is a folder now`);
|
|
80
|
+
this.relPath = relPath;
|
|
81
|
+
this.name = 'UnsupportedTargetError';
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
exports.UnsupportedTargetError = UnsupportedTargetError;
|
|
85
|
+
/** The lock file is already there: another pull may be writing to the destination, or a killed one left it (spec §1.4). */
|
|
86
|
+
class LockHeldError extends Error {
|
|
87
|
+
lockName;
|
|
88
|
+
constructor(lockName) {
|
|
89
|
+
super(`${lockName} exists`);
|
|
90
|
+
this.lockName = lockName;
|
|
91
|
+
this.name = 'LockHeldError';
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
exports.LockHeldError = LockHeldError;
|
|
95
|
+
const sha256 = (data) => crypto_1.default.createHash('sha256').update(data).digest('hex');
|
|
96
|
+
const segments = (rel) => rel.split('/');
|
|
97
|
+
function ioFault(what) {
|
|
98
|
+
return Object.assign(new Error(`EIO: i/o error, ${what} (test hook)`), { code: 'EIO' });
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Test-only injected failures (spec §1.8, sanctioned by PM ruling 7). Inert unless
|
|
102
|
+
* SOLIDACTIONS_TEST_HOOKS=1. Never documented for users.
|
|
103
|
+
*/
|
|
104
|
+
function faultsFromEnv(env = process.env) {
|
|
105
|
+
const none = {
|
|
106
|
+
beforeManifestTemp: () => undefined,
|
|
107
|
+
beforeManifestRename: () => undefined,
|
|
108
|
+
afterChecks: () => undefined,
|
|
109
|
+
beforeWrites: () => undefined,
|
|
110
|
+
afterWrites: () => undefined,
|
|
111
|
+
beforeRename: () => undefined,
|
|
112
|
+
afterRename: () => undefined,
|
|
113
|
+
};
|
|
114
|
+
if (env.SOLIDACTIONS_TEST_HOOKS !== '1')
|
|
115
|
+
return none;
|
|
116
|
+
const faults = { ...none };
|
|
117
|
+
// A comma-separated list combines faults, e.g. "fail-rename:2,create-before-commit:a.md".
|
|
118
|
+
for (const spec of (env.SOLIDACTIONS_DOC_PULL_TEST_FAULT ?? '').split(',')) {
|
|
119
|
+
const [name, arg = ''] = spec.split(/:(.*)/s);
|
|
120
|
+
switch (name) {
|
|
121
|
+
case 'fail-rename':
|
|
122
|
+
faults.beforeRename = (n) => { if (n === Number(arg))
|
|
123
|
+
throw ioFault('rename'); };
|
|
124
|
+
break;
|
|
125
|
+
case 'fail-manifest-temp':
|
|
126
|
+
faults.beforeManifestTemp = () => { throw ioFault('open manifest temp'); };
|
|
127
|
+
break;
|
|
128
|
+
case 'fail-manifest-rename':
|
|
129
|
+
faults.beforeManifestRename = () => { throw ioFault('rename manifest'); };
|
|
130
|
+
break;
|
|
131
|
+
case 'kill-after-renames':
|
|
132
|
+
faults.afterRename = (n) => { if (n === Number(arg))
|
|
133
|
+
process.kill(process.pid, 'SIGKILL'); };
|
|
134
|
+
break;
|
|
135
|
+
case 'create-after-checks':
|
|
136
|
+
faults.afterChecks = (destination) => {
|
|
137
|
+
const abs = path_1.default.join(destination, ...segments(arg));
|
|
138
|
+
fs_1.default.mkdirSync(path_1.default.dirname(abs), { recursive: true });
|
|
139
|
+
fs_1.default.writeFileSync(abs, 'RACE');
|
|
140
|
+
};
|
|
141
|
+
break;
|
|
142
|
+
case 'create-before-commit':
|
|
143
|
+
faults.beforeWrites = (destination) => fs_1.default.writeFileSync(path_1.default.join(destination, ...segments(arg)), 'RACE');
|
|
144
|
+
break;
|
|
145
|
+
case 'mkdir-before-commit':
|
|
146
|
+
faults.beforeWrites = (destination) => {
|
|
147
|
+
const dir = path_1.default.join(destination, ...segments(arg));
|
|
148
|
+
fs_1.default.mkdirSync(dir);
|
|
149
|
+
fs_1.default.writeFileSync(path_1.default.join(dir, 'user.txt'), 'USER');
|
|
150
|
+
};
|
|
151
|
+
break;
|
|
152
|
+
case 'change-after-writes':
|
|
153
|
+
faults.afterWrites = (destination) => fs_1.default.writeFileSync(path_1.default.join(destination, ...segments(arg)), 'CHANGED');
|
|
154
|
+
break;
|
|
155
|
+
case 'break-after-writes': {
|
|
156
|
+
// `<how>:<rel>`: the entry at <rel> is made uninspectable before the outcomes are decided (cli#168 FR5).
|
|
157
|
+
const [how, rel = ''] = arg.split(/:(.*)/s);
|
|
158
|
+
faults.afterWrites = (destination) => {
|
|
159
|
+
const abs = path_1.default.join(destination, ...segments(rel));
|
|
160
|
+
if (how === 'chmod0') {
|
|
161
|
+
fs_1.default.chmodSync(abs, 0o000);
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
fs_1.default.rmSync(abs, { recursive: true, force: true });
|
|
165
|
+
if (how === 'folder')
|
|
166
|
+
fs_1.default.mkdirSync(abs);
|
|
167
|
+
else if (how === 'file')
|
|
168
|
+
fs_1.default.writeFileSync(abs, 'BLOCKER');
|
|
169
|
+
else if (how === 'loop')
|
|
170
|
+
fs_1.default.symlinkSync(path_1.default.basename(abs), abs);
|
|
171
|
+
};
|
|
172
|
+
break;
|
|
173
|
+
}
|
|
174
|
+
case 'link-before-commit': {
|
|
175
|
+
const [linkRel, linkTarget] = arg.split('>');
|
|
176
|
+
faults.beforeWrites = (destination) => fs_1.default.symlinkSync(linkTarget, path_1.default.join(destination, ...segments(linkRel)));
|
|
177
|
+
break;
|
|
178
|
+
}
|
|
179
|
+
default:
|
|
180
|
+
break;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return faults;
|
|
184
|
+
}
|
|
185
|
+
function lstatOrNull(abs) {
|
|
186
|
+
try {
|
|
187
|
+
return fs_1.default.lstatSync(abs);
|
|
188
|
+
}
|
|
189
|
+
catch (error) {
|
|
190
|
+
if (error.code === 'ENOENT')
|
|
191
|
+
return null;
|
|
192
|
+
throw error;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
/** True when the regular file at `targetAbs` already holds exactly `data`; a file that cannot be read does not. */
|
|
196
|
+
function holdsBytes(targetAbs, data) {
|
|
197
|
+
try {
|
|
198
|
+
return sha256(fs_1.default.readFileSync(targetAbs)) === sha256(data);
|
|
199
|
+
}
|
|
200
|
+
catch {
|
|
201
|
+
return false;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Whether the target is still in a state the checks allowed the pull to replace. Rule 5 (spec §1.1): a regular file that
|
|
206
|
+
* already holds the bytes about to be written is never a conflict, whatever it was authorized as.
|
|
207
|
+
*/
|
|
208
|
+
function stillAuthorized(targetAbs, authorized, data) {
|
|
209
|
+
if (authorized.kind === 'any')
|
|
210
|
+
return true;
|
|
211
|
+
const stat = lstatOrNull(targetAbs);
|
|
212
|
+
if (authorized.kind === 'absent')
|
|
213
|
+
return stat === null || (stat.isFile() && holdsBytes(targetAbs, data));
|
|
214
|
+
if (stat === null || !stat.isFile())
|
|
215
|
+
return false;
|
|
216
|
+
const current = sha256(fs_1.default.readFileSync(targetAbs));
|
|
217
|
+
return current === authorized.sha256 || current === sha256(data);
|
|
218
|
+
}
|
|
219
|
+
/** Every folder of `dirRel` under `destination`, created where missing; a link or a file on the way refuses (cli#182). Returns the folder's path. */
|
|
220
|
+
function ensureRealDirs(destination, dirRel) {
|
|
221
|
+
const parts = dirRel === '' ? [] : segments(dirRel);
|
|
222
|
+
let current = destination;
|
|
223
|
+
for (let i = 0; i < parts.length; i++) {
|
|
224
|
+
current = path_1.default.join(current, parts[i]);
|
|
225
|
+
let stat = lstatOrNull(current);
|
|
226
|
+
if (stat === null) {
|
|
227
|
+
fs_1.default.mkdirSync(current);
|
|
228
|
+
stat = fs_1.default.lstatSync(current);
|
|
229
|
+
}
|
|
230
|
+
if (stat.isSymbolicLink() || !stat.isDirectory()) {
|
|
231
|
+
throw new LinkOnTheWayError(parts.slice(0, i + 1).join('/'));
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
return current;
|
|
235
|
+
}
|
|
236
|
+
/** Create `abs` (it must not exist) holding `data`; returns the new file's `dev:ino`. */
|
|
237
|
+
function writeNew(abs, data) {
|
|
238
|
+
const fd = fs_1.default.openSync(abs, NEW_FILE_FLAGS, 0o666);
|
|
239
|
+
try {
|
|
240
|
+
fs_1.default.writeFileSync(fd, data);
|
|
241
|
+
const stat = fs_1.default.fstatSync(fd);
|
|
242
|
+
return `${stat.dev}:${stat.ino}`;
|
|
243
|
+
}
|
|
244
|
+
finally {
|
|
245
|
+
fs_1.default.closeSync(fd);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Write every planned file in order, stopping at the first one that cannot be written or whose target is no longer in the
|
|
250
|
+
* state the preflight saw (spec §1.3). Nothing is deleted or restored: the files written before the stop stay, and are
|
|
251
|
+
* returned so the caller can record them.
|
|
252
|
+
*/
|
|
253
|
+
function writeAll(destination, writes, faults) {
|
|
254
|
+
faults.beforeWrites(destination);
|
|
255
|
+
const placed = [];
|
|
256
|
+
for (let i = 0; i < writes.length; i++) {
|
|
257
|
+
const write = writes[i];
|
|
258
|
+
const targetAbs = path_1.default.join(destination, ...segments(write.relPath));
|
|
259
|
+
let identity;
|
|
260
|
+
try {
|
|
261
|
+
const dirAbs = ensureRealDirs(destination, write.dirRel);
|
|
262
|
+
identity = writeFileAtomic(dirAbs, path_1.default.basename(targetAbs), write.data, () => {
|
|
263
|
+
const existing = lstatOrNull(targetAbs);
|
|
264
|
+
if (existing !== null && !existing.isFile() && !existing.isSymbolicLink())
|
|
265
|
+
throw new UnsupportedTargetError(write.relPath);
|
|
266
|
+
if (!stillAuthorized(targetAbs, write.authorized, write.data))
|
|
267
|
+
throw new PublicationRefusedError(write.relPath);
|
|
268
|
+
faults.beforeRename(i + 1);
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
catch (error) {
|
|
272
|
+
const typed = error instanceof LinkOnTheWayError || error instanceof PublicationRefusedError || error instanceof UnsupportedTargetError;
|
|
273
|
+
return { placed, stop: { write, error: typed ? error : new WriteStepError(write.relPath, error) } };
|
|
274
|
+
}
|
|
275
|
+
placed.push({ ...write, identity });
|
|
276
|
+
faults.afterRename(i + 1);
|
|
277
|
+
}
|
|
278
|
+
return { placed, stop: null };
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Create the destination's lock file, holding this pid (spec §1.4). Any existing entry of that name refuses, a link or a
|
|
282
|
+
* folder included; the file is never removed or liveness-tested except by the pull that created it (releaseLock).
|
|
283
|
+
*/
|
|
284
|
+
function acquireLock(destination, manifestName) {
|
|
285
|
+
const lockName = (0, exports.lockNameFor)(manifestName);
|
|
286
|
+
const lockAbs = path_1.default.join(destination, lockName);
|
|
287
|
+
let fd;
|
|
288
|
+
try {
|
|
289
|
+
fd = fs_1.default.openSync(lockAbs, NEW_FILE_FLAGS, 0o666);
|
|
290
|
+
}
|
|
291
|
+
catch (error) {
|
|
292
|
+
if (error.code === 'EEXIST')
|
|
293
|
+
throw new LockHeldError(lockName);
|
|
294
|
+
throw error;
|
|
295
|
+
}
|
|
296
|
+
try {
|
|
297
|
+
fs_1.default.writeFileSync(fd, `${process.pid}\n`);
|
|
298
|
+
}
|
|
299
|
+
catch (error) {
|
|
300
|
+
fs_1.default.closeSync(fd);
|
|
301
|
+
fs_1.default.unlinkSync(lockAbs); // the file this call just created
|
|
302
|
+
throw error;
|
|
303
|
+
}
|
|
304
|
+
fs_1.default.closeSync(fd);
|
|
305
|
+
}
|
|
306
|
+
/** Remove the lock this process created: only a regular file still holding this pid, so a lock someone else made is never touched. */
|
|
307
|
+
function releaseLock(destination, manifestName) {
|
|
308
|
+
const lockAbs = path_1.default.join(destination, (0, exports.lockNameFor)(manifestName));
|
|
309
|
+
try {
|
|
310
|
+
if (lstatOrNull(lockAbs)?.isFile() === true && fs_1.default.readFileSync(lockAbs, 'utf8') === `${process.pid}\n`)
|
|
311
|
+
fs_1.default.unlinkSync(lockAbs);
|
|
312
|
+
}
|
|
313
|
+
catch {
|
|
314
|
+
// already gone, or not ours to inspect
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Write `dir/name` through a sibling temp file and a rename: never half-written, never through a link at `name`.
|
|
319
|
+
* `beforeRename` runs after the temp file exists and just before the rename; if it throws, the temp file is removed.
|
|
320
|
+
* Returns the `dev:ino` of the file renamed in (a rename keeps the temp file's inode).
|
|
321
|
+
*/
|
|
322
|
+
function writeFileAtomic(dir, name, data, beforeRename) {
|
|
323
|
+
const tempAbs = path_1.default.join(dir, `${TEMP_PREFIX}${process.pid}-${crypto_1.default.randomBytes(6).toString('hex')}.tmp`);
|
|
324
|
+
const identity = writeNew(tempAbs, data);
|
|
325
|
+
try {
|
|
326
|
+
beforeRename?.();
|
|
327
|
+
const existing = lstatOrNull(path_1.default.join(dir, name));
|
|
328
|
+
if (existing !== null && existing.isFile())
|
|
329
|
+
fs_1.default.chmodSync(tempAbs, existing.mode & 0o7777);
|
|
330
|
+
fs_1.default.renameSync(tempAbs, path_1.default.join(dir, name));
|
|
331
|
+
}
|
|
332
|
+
catch (error) {
|
|
333
|
+
try {
|
|
334
|
+
fs_1.default.unlinkSync(tempAbs);
|
|
335
|
+
}
|
|
336
|
+
catch {
|
|
337
|
+
// already gone
|
|
338
|
+
}
|
|
339
|
+
throw error;
|
|
340
|
+
}
|
|
341
|
+
return identity;
|
|
342
|
+
}
|
|
@@ -9,6 +9,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
9
9
|
};
|
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
11
|
exports.DOCS_MANIFEST = void 0;
|
|
12
|
+
exports.docsFrom = docsFrom;
|
|
13
|
+
exports.entryAt = entryAt;
|
|
12
14
|
exports.sha256Hex = sha256Hex;
|
|
13
15
|
exports.readManifest = readManifest;
|
|
14
16
|
exports.writeManifest = writeManifest;
|
|
@@ -16,7 +18,19 @@ const fs_1 = __importDefault(require("fs"));
|
|
|
16
18
|
const path_1 = __importDefault(require("path"));
|
|
17
19
|
const crypto_1 = __importDefault(require("crypto"));
|
|
18
20
|
const chalk_1 = __importDefault(require("chalk"));
|
|
21
|
+
const doc_pull_writes_1 = require("./doc-pull-writes");
|
|
19
22
|
exports.DOCS_MANIFEST = '.solidactions-docs.json';
|
|
23
|
+
/** A `docs` dictionary holding `entries` in order: no prototype, so no name is inherited and none reaches a setter. */
|
|
24
|
+
function docsFrom(entries) {
|
|
25
|
+
const docs = Object.create(null);
|
|
26
|
+
for (const [relPath, entry] of entries)
|
|
27
|
+
docs[relPath] = entry;
|
|
28
|
+
return docs;
|
|
29
|
+
}
|
|
30
|
+
/** The entry `manifest` records at `relPath`: an own key only, never an inherited name. */
|
|
31
|
+
function entryAt(manifest, relPath) {
|
|
32
|
+
return manifest != null && Object.hasOwn(manifest.docs, relPath) ? manifest.docs[relPath] : undefined;
|
|
33
|
+
}
|
|
20
34
|
/** sha256 hex digest of the given bytes/string, as written to disk. */
|
|
21
35
|
function sha256Hex(data) {
|
|
22
36
|
return crypto_1.default.createHash('sha256').update(data).digest('hex');
|
|
@@ -34,7 +48,11 @@ function readManifest(dir, opts = {}) {
|
|
|
34
48
|
return null;
|
|
35
49
|
}
|
|
36
50
|
try {
|
|
37
|
-
|
|
51
|
+
const manifest = JSON.parse(fs_1.default.readFileSync(manifestPath, 'utf8'));
|
|
52
|
+
// JSON.parse makes every key an own one; the copy keeps it so for every later lookup and insertion.
|
|
53
|
+
if (manifest !== null && typeof manifest.docs === 'object' && manifest.docs !== null)
|
|
54
|
+
manifest.docs = docsFrom(Object.entries(manifest.docs));
|
|
55
|
+
return manifest;
|
|
38
56
|
}
|
|
39
57
|
catch {
|
|
40
58
|
if (opts.warnOnParseError) {
|
|
@@ -43,6 +61,7 @@ function readManifest(dir, opts = {}) {
|
|
|
43
61
|
return null;
|
|
44
62
|
}
|
|
45
63
|
}
|
|
46
|
-
|
|
47
|
-
|
|
64
|
+
/** `beforeRename` is doc pull's test seam (spec §1.8): it runs once the temp file exists, just before the rename. */
|
|
65
|
+
function writeManifest(dir, manifest, beforeRename) {
|
|
66
|
+
(0, doc_pull_writes_1.writeFileAtomic)(dir, exports.DOCS_MANIFEST, `${JSON.stringify(manifest, null, 2)}\n`, beforeRename);
|
|
48
67
|
}
|
|
@@ -100,6 +100,8 @@ exports.MUTATING_COMMANDS = new Set([
|
|
|
100
100
|
'role push',
|
|
101
101
|
'doc push',
|
|
102
102
|
'doc upload',
|
|
103
|
+
// POSTs a connect-link request (a row the workspace counts against its open-link limit).
|
|
104
|
+
'connection connect',
|
|
103
105
|
]);
|
|
104
106
|
/** Space-joined command paths that do not mutate server state. */
|
|
105
107
|
exports.READONLY_COMMANDS = new Set([
|
|
@@ -149,6 +151,7 @@ exports.READONLY_COMMANDS = new Set([
|
|
|
149
151
|
'oauth-action view',
|
|
150
152
|
'oauth-action platforms',
|
|
151
153
|
'connection list',
|
|
154
|
+
'connection wait',
|
|
152
155
|
'ai init',
|
|
153
156
|
'ai examples',
|
|
154
157
|
'skill pull',
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.out = out;
|
|
4
|
+
exports.err = err;
|
|
5
|
+
const connect_link_1 = require("./connect-link");
|
|
6
|
+
/**
|
|
7
|
+
* stdout: strip control bytes with plainText, then apply the optional style.
|
|
8
|
+
* The style runs after stripping so plainText never eats the style's own
|
|
9
|
+
* escape codes. This is the only stdout path the connection commands use.
|
|
10
|
+
*/
|
|
11
|
+
function out(text, style) {
|
|
12
|
+
const clean = (0, connect_link_1.plainText)(text);
|
|
13
|
+
console.log(style ? style(clean) : clean);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* stderr: strip control bytes with plainText, then apply the optional style.
|
|
17
|
+
* This is the only stderr path the connection commands use.
|
|
18
|
+
*/
|
|
19
|
+
function err(text, style) {
|
|
20
|
+
const clean = (0, connect_link_1.plainText)(text);
|
|
21
|
+
console.error(style ? style(clean) : clean);
|
|
22
|
+
}
|