@skrr-ai/cli 0.1.162 → 0.1.164
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/dist/base-command.d.ts +5 -2
- package/dist/base-command.js +108 -39
- package/dist/commands/activity/list.d.ts +7 -0
- package/dist/commands/activity/list.js +17 -0
- package/dist/commands/activity/scan-older.d.ts +2 -2
- package/dist/commands/activity/scan-older.js +6 -5
- package/dist/commands/activity/show.d.ts +0 -2
- package/dist/commands/activity/show.js +21 -42
- package/dist/commands/agents/always-on/release-run.d.ts +3 -3
- package/dist/commands/agents/always-on/release-run.js +5 -6
- package/dist/commands/agents/mini-computer/app/reset.d.ts +1 -0
- package/dist/commands/agents/mini-computer/app/reset.js +5 -2
- package/dist/commands/agents/mini-computer/app/set.js +1 -1
- package/dist/commands/agents/mini-computer/show.js +10 -2
- package/dist/commands/agents/mini-computer/tasks-view.js +2 -2
- package/dist/commands/agents/supervision.d.ts +25 -0
- package/dist/commands/agents/supervision.js +129 -0
- package/dist/commands/agents/triggers/replay.js +1 -1
- package/dist/commands/agents/triggers/runs.d.ts +2 -3
- package/dist/commands/agents/triggers/runs.js +4 -5
- package/dist/commands/apps/auto-apply.js +31 -10
- package/dist/commands/apps/check.js +8 -0
- package/dist/commands/apps/data/batch.js +16 -5
- package/dist/commands/apps/data/collections.js +1 -1
- package/dist/commands/apps/data/delete.js +12 -4
- package/dist/commands/apps/data/patch.js +11 -4
- package/dist/commands/apps/data/put.js +13 -6
- package/dist/commands/apps/data/query.js +3 -3
- package/dist/commands/apps/install.js +24 -7
- package/dist/commands/apps/installations/events.d.ts +1 -0
- package/dist/commands/apps/installations/events.js +63 -10
- package/dist/commands/apps/installations/show.js +26 -5
- package/dist/commands/apps/installations/snapshot.js +1 -1
- package/dist/commands/apps/installations/versions.js +25 -9
- package/dist/commands/apps/logs.js +4 -1
- package/dist/commands/apps/push.js +10 -2
- package/dist/commands/apps/reconsent.js +7 -1
- package/dist/commands/apps/rollback.js +2 -2
- package/dist/commands/apps/settings/set.js +81 -4
- package/dist/commands/apps/settings/show.js +38 -7
- package/dist/commands/duties/action-proposal.js +19 -11
- package/dist/commands/duties/cadence-decisions.js +7 -0
- package/dist/commands/duties/status.js +20 -15
- package/dist/commands/duties/trigger-status.js +2 -2
- package/dist/commands/duties/wake-capabilities.js +12 -6
- package/dist/commands/outbox/drop.js +21 -15
- package/dist/commands/outbox/list.d.ts +2 -1
- package/dist/commands/outbox/list.js +20 -11
- package/dist/commands/outbox/retry.d.ts +8 -11
- package/dist/commands/outbox/retry.js +135 -92
- package/dist/commands/spaces/create.js +1 -1
- package/dist/commands/tasks/comments/add.js +1 -1
- package/dist/commands/triggers/audit.js +3 -5
- package/dist/commands/triggers/fire-detail.js +7 -1
- package/dist/commands/triggers/replay.js +1 -1
- package/dist/commands/triggers/runs.d.ts +2 -4
- package/dist/commands/triggers/runs.js +3 -5
- package/dist/generated/agent-guides.json +19 -19
- package/dist/lib/agent-activity.d.ts +21 -1
- package/dist/lib/agent-activity.js +98 -29
- package/dist/lib/api-fetch.d.ts +2 -0
- package/dist/lib/api-fetch.js +5 -5
- package/dist/lib/appData.d.ts +43 -5
- package/dist/lib/appData.js +117 -25
- package/dist/lib/appInstallations.d.ts +5 -5
- package/dist/lib/appInstallations.js +232 -74
- package/dist/lib/appSettings.d.ts +2 -0
- package/dist/lib/appSettings.js +36 -3
- package/dist/lib/apps-command.d.ts +9 -0
- package/dist/lib/apps-command.js +191 -7
- package/dist/lib/appsCheck.js +40 -3
- package/dist/lib/appsFs.d.ts +1 -1
- package/dist/lib/chat-supervision.d.ts +21 -0
- package/dist/lib/chat-supervision.js +37 -0
- package/dist/lib/duties.d.ts +4 -0
- package/dist/lib/json-output.d.ts +4 -0
- package/dist/lib/json-output.js +38 -0
- package/dist/lib/miniComputer.d.ts +1 -0
- package/dist/lib/miniComputer.js +16 -4
- package/dist/lib/miniComputerCommand.js +4 -1
- package/dist/lib/node-adapter.js +35 -2
- package/dist/lib/outbox.d.ts +20 -5
- package/dist/lib/outbox.js +233 -76
- package/dist/lib/rate-limit-retry.d.ts +3 -2
- package/dist/lib/rate-limit-retry.js +3 -2
- package/dist/lib/roles.d.ts +1 -1
- package/dist/lib/triggers.d.ts +3 -0
- package/dist/lib/triggers.js +10 -0
- package/dist/lib/widgetCheck.js +30 -4
- package/dist/lib/widgetStaticScan.d.ts +17 -6
- package/dist/lib/widgetStaticScan.js +336 -94
- package/dist/node_modules/@skrr-ai/data-provider/APP_HTML_PARSER_LICENSES.txt +36 -0
- package/dist/node_modules/@skrr-ai/data-provider/index.js +15543 -10133
- package/oclif.manifest.json +334 -47
- package/package.json +5 -3
package/dist/lib/node-adapter.js
CHANGED
|
@@ -22,6 +22,12 @@ require("./auth-core-init");
|
|
|
22
22
|
const rate_limit_retry_1 = require("./rate-limit-retry");
|
|
23
23
|
const RESOLVE_URL_RE = /^https?:\/\//i;
|
|
24
24
|
const RESOLVE_URL_RE_2 = /\/+$/;
|
|
25
|
+
// These routes do not yet have a server-side idempotency receipt. A generated
|
|
26
|
+
// request key alone cannot make an arbitrary gateway response safe to replay.
|
|
27
|
+
// A deployment can mount the API beneath a path prefix; a match at any
|
|
28
|
+
// segment is deliberately conservative even for a different origin.
|
|
29
|
+
const APP_DATA_PATH_RE = /\/api\/apps\/installations\/[^/]+\/data(?:\/|$)/;
|
|
30
|
+
const APP_SETTINGS_PATH_RE = /\/api\/apps\/installations\/[^/]+\/settings\/?$/;
|
|
25
31
|
// ---------------------------------------------------------------------
|
|
26
32
|
// Per-process credential override — set by BaseCommand.init().
|
|
27
33
|
// Pulled out of the closure so test harnesses or long-lived callers
|
|
@@ -163,6 +169,26 @@ function createNodeAdapter(opts = {}) {
|
|
|
163
169
|
}
|
|
164
170
|
return u.toString();
|
|
165
171
|
}
|
|
172
|
+
function isAppDataWrite(method, url) {
|
|
173
|
+
if (method === 'GET')
|
|
174
|
+
return false;
|
|
175
|
+
try {
|
|
176
|
+
return APP_DATA_PATH_RE.test(new URL(url).pathname);
|
|
177
|
+
}
|
|
178
|
+
catch {
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
function isAppSettingsWrite(method, url) {
|
|
183
|
+
if (method !== 'PUT')
|
|
184
|
+
return false;
|
|
185
|
+
try {
|
|
186
|
+
return APP_SETTINGS_PATH_RE.test(new URL(url).pathname);
|
|
187
|
+
}
|
|
188
|
+
catch {
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
166
192
|
/** The last 429's `Retry-After`, read off the response of the most recent attempt. */
|
|
167
193
|
let lastRetryAfterMs;
|
|
168
194
|
async function rawRequest(method, url, body, options, isFormData) {
|
|
@@ -191,7 +217,12 @@ function createNodeAdapter(opts = {}) {
|
|
|
191
217
|
const signal = timeoutSignal && callerSignal
|
|
192
218
|
? AbortSignal.any([timeoutSignal, callerSignal])
|
|
193
219
|
: timeoutSignal || callerSignal;
|
|
194
|
-
const
|
|
220
|
+
const appDataWrite = isAppDataWrite(method, finalUrl);
|
|
221
|
+
const appSettingsWrite = isAppSettingsWrite(method, finalUrl);
|
|
222
|
+
const noReplay = options?._disableAuthReplay === true;
|
|
223
|
+
const { response, retryAfterMs } = await (0, rate_limit_retry_1.fetchWithRateLimitRetry)(() => fetch(finalUrl, { method, headers, body: finalBody, ...(signal ? { signal } : {}),
|
|
224
|
+
...(appDataWrite || appSettingsWrite || noReplay ? { redirect: 'manual' } : (0, task_runtime_headers_1.taskRuntimeRedirectOptions)(headers)) }), { method, headers, ...(appDataWrite || appSettingsWrite || noReplay
|
|
225
|
+
? { maxRetries: 0 } : {}) });
|
|
195
226
|
lastRetryAfterMs = retryAfterMs;
|
|
196
227
|
return response;
|
|
197
228
|
}
|
|
@@ -344,10 +375,12 @@ function createNodeAdapter(opts = {}) {
|
|
|
344
375
|
headers: (0, data_provider_1.withIdempotencyKey)(options?.headers, { method, url, body }),
|
|
345
376
|
};
|
|
346
377
|
}
|
|
378
|
+
const appDataWrite = isAppDataWrite(method, resolveUrl(url));
|
|
379
|
+
const appSettingsWrite = isAppSettingsWrite(method, resolveUrl(url));
|
|
347
380
|
let res = await rawRequest(method, url, body, options, isFormData);
|
|
348
381
|
// Never retry auth endpoints themselves — prevents refresh recursion
|
|
349
382
|
// and lets login/logout/refresh surface their real errors.
|
|
350
|
-
if (res.status === 401 && !url.includes('/api/auth/')) {
|
|
383
|
+
if (res.status === 401 && !appDataWrite && !appSettingsWrite && options?._disableAuthReplay !== true && !url.includes('/api/auth/')) {
|
|
351
384
|
const refreshed = await refresh();
|
|
352
385
|
if (refreshed) {
|
|
353
386
|
res = await rawRequest(method, url, body, options, isFormData);
|
package/dist/lib/outbox.d.ts
CHANGED
|
@@ -27,6 +27,14 @@ export interface OutboxEntry {
|
|
|
27
27
|
/** ISO timestamp of the most recent failed replay, when there has been one. */
|
|
28
28
|
lastAttemptAt?: string;
|
|
29
29
|
lastError?: string;
|
|
30
|
+
/** A replay was started; a result ID is a response shape, not proof of the original target or effect. */
|
|
31
|
+
replay?: {
|
|
32
|
+
state: 'sending' | 'result_recorded';
|
|
33
|
+
attemptId: string;
|
|
34
|
+
startedAt: string;
|
|
35
|
+
fingerprint: string;
|
|
36
|
+
resultId?: string;
|
|
37
|
+
};
|
|
30
38
|
}
|
|
31
39
|
/**
|
|
32
40
|
* A replay that keeps failing is either a permanent server-side refusal or a
|
|
@@ -38,13 +46,16 @@ export interface OutboxEntry {
|
|
|
38
46
|
export declare const MAX_REPLAY_ATTEMPTS = 10;
|
|
39
47
|
export declare function isOutageFailure(err: unknown): boolean;
|
|
40
48
|
export declare function isRetryableWrite(err: unknown): boolean;
|
|
49
|
+
/** One replay at a time; unlike the short queue lock, this spans network calls. */
|
|
50
|
+
export declare function lockOutboxReplay(profile?: string): Promise<() => Promise<void>>;
|
|
51
|
+
export declare class OutboxFullError extends Error {
|
|
52
|
+
constructor();
|
|
53
|
+
}
|
|
41
54
|
export declare function enqueueWrite(input: Omit<OutboxEntry, 'id' | 'queuedAt' | 'attempts'>, profile?: string): OutboxEntry;
|
|
42
|
-
/**
|
|
43
|
-
* Read every intact entry. A truncated trailing line — the shape a crash
|
|
44
|
-
* mid-append leaves — is skipped, because losing the one entry that was still
|
|
45
|
-
* being written is strictly better than failing to read the ones that landed.
|
|
46
|
-
*/
|
|
55
|
+
/** Fail visibly when the queue is unreadable; never present damage as an empty queue. */
|
|
47
56
|
export declare function listWrites(profile?: string): OutboxEntry[];
|
|
57
|
+
/** Replay must fail before sending if the queue cannot be read intact. */
|
|
58
|
+
export declare function listReplayWrites(profile?: string): OutboxEntry[];
|
|
48
59
|
/**
|
|
49
60
|
* Rewrite the log with `entries`, atomically (tmp + rename).
|
|
50
61
|
*
|
|
@@ -52,6 +63,10 @@ export declare function listWrites(profile?: string): OutboxEntry[];
|
|
|
52
63
|
* append: it could lose entries that were never attempted.
|
|
53
64
|
*/
|
|
54
65
|
export declare function replaceWrites(entries: OutboxEntry[], profile?: string): void;
|
|
66
|
+
/** Persist a one-attempt claim before sending. Existing claims are never taken over. */
|
|
67
|
+
export declare function claimOutboxReplay(id: string, profile?: string): OutboxEntry | null;
|
|
68
|
+
/** Retain the content while recording the result of the exact claimed request. */
|
|
69
|
+
export declare function acknowledgeOutboxReplay(claim: OutboxEntry, resultId: string, profile?: string): void;
|
|
55
70
|
export declare function dropWrite(id: string, profile?: string): boolean;
|
|
56
71
|
export interface IncidentState {
|
|
57
72
|
/** ISO timestamp when the control plane was last observed failing. */
|
package/dist/lib/outbox.js
CHANGED
|
@@ -32,13 +32,20 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
32
32
|
return result;
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
35
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.MAX_REPLAY_ATTEMPTS = void 0;
|
|
39
|
+
exports.OutboxFullError = exports.MAX_REPLAY_ATTEMPTS = void 0;
|
|
37
40
|
exports.isOutageFailure = isOutageFailure;
|
|
38
41
|
exports.isRetryableWrite = isRetryableWrite;
|
|
42
|
+
exports.lockOutboxReplay = lockOutboxReplay;
|
|
39
43
|
exports.enqueueWrite = enqueueWrite;
|
|
40
44
|
exports.listWrites = listWrites;
|
|
45
|
+
exports.listReplayWrites = listReplayWrites;
|
|
41
46
|
exports.replaceWrites = replaceWrites;
|
|
47
|
+
exports.claimOutboxReplay = claimOutboxReplay;
|
|
48
|
+
exports.acknowledgeOutboxReplay = acknowledgeOutboxReplay;
|
|
42
49
|
exports.dropWrite = dropWrite;
|
|
43
50
|
exports.recordIncident = recordIncident;
|
|
44
51
|
exports.recordRecovery = recordRecovery;
|
|
@@ -71,9 +78,8 @@ exports.isIncidentActive = isIncidentActive;
|
|
|
71
78
|
* A script that treats it as done would be wrong; a human who sees "queued"
|
|
72
79
|
* knows their content is safe and the operation is still owed.
|
|
73
80
|
*
|
|
74
|
-
* 4.
|
|
75
|
-
*
|
|
76
|
-
* skipped on read rather than failing the whole file.
|
|
81
|
+
* 4. One JSON object per line, fsynced on append. A damaged or unreadable
|
|
82
|
+
* file is reported rather than silently treated as an empty queue.
|
|
77
83
|
*
|
|
78
84
|
* Scope note: this queues the INTENT (endpoint, payload, idempotency key), not
|
|
79
85
|
* a promise about ordering. Entries replay oldest-first but independently — the
|
|
@@ -84,6 +90,7 @@ const fs = __importStar(require("node:fs"));
|
|
|
84
90
|
const os = __importStar(require("node:os"));
|
|
85
91
|
const path = __importStar(require("node:path"));
|
|
86
92
|
const crypto = __importStar(require("node:crypto"));
|
|
93
|
+
const proper_lockfile_1 = __importDefault(require("proper-lockfile"));
|
|
87
94
|
const IS_OUTAGE_FAILURE_RE = /fetch failed|ECONNREFUSED|ENOTFOUND|ETIMEDOUT|ECONNRESET|socket hang up|network/i;
|
|
88
95
|
/**
|
|
89
96
|
* A replay that keeps failing is either a permanent server-side refusal or a
|
|
@@ -228,6 +235,99 @@ function ensureDir(profile) {
|
|
|
228
235
|
fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
229
236
|
return dir;
|
|
230
237
|
}
|
|
238
|
+
/** Serialize short disk transactions between cooperating CLI processes. */
|
|
239
|
+
function withQueueLock(profile, work) {
|
|
240
|
+
const dir = ensureDir(profile);
|
|
241
|
+
const lockKey = path.join(dir, '.queue');
|
|
242
|
+
const lockPath = path.join(dir, '.queue.lock');
|
|
243
|
+
let release;
|
|
244
|
+
const until = Date.now() + 2_000;
|
|
245
|
+
while (!release) {
|
|
246
|
+
try {
|
|
247
|
+
release = proper_lockfile_1.default.lockSync(lockKey, { lockfilePath: lockPath, realpath: false, stale: 120_000 });
|
|
248
|
+
}
|
|
249
|
+
catch (error) {
|
|
250
|
+
if (error.code !== 'ELOCKED' || Date.now() >= until)
|
|
251
|
+
throw error;
|
|
252
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 25);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
try {
|
|
256
|
+
return work();
|
|
257
|
+
}
|
|
258
|
+
finally {
|
|
259
|
+
release();
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
/** One replay at a time; unlike the short queue lock, this spans network calls. */
|
|
263
|
+
async function lockOutboxReplay(profile) {
|
|
264
|
+
const dir = ensureDir(profile);
|
|
265
|
+
try {
|
|
266
|
+
return await proper_lockfile_1.default.lock(path.join(dir, '.replay'), { lockfilePath: path.join(dir, '.replay.lock'), realpath: false, stale: 120_000 });
|
|
267
|
+
}
|
|
268
|
+
catch (error) {
|
|
269
|
+
if (error.code !== 'ELOCKED')
|
|
270
|
+
throw error;
|
|
271
|
+
throw Object.assign(new Error('Another outbox retry or drop is in progress. Wait for it to finish, then inspect the queue and reconcile any uncertain result before deciding whether to retry.'), {
|
|
272
|
+
code: 'OUTBOX_BUSY', retryable: false,
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
class OutboxCorruptError extends Error {
|
|
277
|
+
code = 'OUTBOX_CORRUPT';
|
|
278
|
+
retryable = false;
|
|
279
|
+
constructor() {
|
|
280
|
+
super('The local outbox is damaged or incomplete. Its file was not changed; preserve it before attempting repair.');
|
|
281
|
+
this.name = 'OutboxCorruptError';
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
/** A mutation must never turn an unreadable or damaged queue into an empty one. */
|
|
285
|
+
function readWritesStrict(profile) {
|
|
286
|
+
let raw;
|
|
287
|
+
try {
|
|
288
|
+
raw = fs.readFileSync(outboxPath(profile), 'utf8');
|
|
289
|
+
}
|
|
290
|
+
catch (error) {
|
|
291
|
+
if (error.code === 'ENOENT')
|
|
292
|
+
return [];
|
|
293
|
+
throw error;
|
|
294
|
+
}
|
|
295
|
+
const seen = new Set();
|
|
296
|
+
return raw.split('\n').filter((line) => line.trim()).map((line) => {
|
|
297
|
+
let value;
|
|
298
|
+
try {
|
|
299
|
+
value = JSON.parse(line);
|
|
300
|
+
}
|
|
301
|
+
catch {
|
|
302
|
+
throw new OutboxCorruptError();
|
|
303
|
+
}
|
|
304
|
+
const entry = value;
|
|
305
|
+
if (!entry || typeof entry !== 'object' || typeof entry.id !== 'string' || !entry.id ||
|
|
306
|
+
seen.has(entry.id) || typeof entry.idempotencyKey !== 'string' || !entry.idempotencyKey ||
|
|
307
|
+
typeof entry.command !== 'string' || typeof entry.summary !== 'string' ||
|
|
308
|
+
!['post', 'put', 'patch', 'delete'].includes(entry.method) ||
|
|
309
|
+
(entry.method !== 'delete' && !Object.prototype.hasOwnProperty.call(entry, 'body')) ||
|
|
310
|
+
typeof entry.url !== 'string' || !entry.url || typeof entry.queuedAt !== 'string' ||
|
|
311
|
+
!entry.reason || typeof entry.reason !== 'object' || typeof entry.reason.message !== 'string' ||
|
|
312
|
+
!Number.isInteger(entry.attempts) || entry.attempts < 0 ||
|
|
313
|
+
(entry.replay !== undefined && (!entry.replay || typeof entry.replay !== 'object' ||
|
|
314
|
+
!['sending', 'result_recorded'].includes(entry.replay.state) ||
|
|
315
|
+
typeof entry.replay.attemptId !== 'string' || !entry.replay.attemptId ||
|
|
316
|
+
typeof entry.replay.startedAt !== 'string' || !entry.replay.startedAt ||
|
|
317
|
+
typeof entry.replay.fingerprint !== 'string' || !/^[0-9a-f]{64}$/.test(entry.replay.fingerprint) ||
|
|
318
|
+
(entry.replay.state === 'result_recorded' && (typeof entry.replay.resultId !== 'string' || !entry.replay.resultId))))) {
|
|
319
|
+
throw new OutboxCorruptError();
|
|
320
|
+
}
|
|
321
|
+
seen.add(entry.id);
|
|
322
|
+
return entry;
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
function replayFingerprint(entry) {
|
|
326
|
+
return crypto.createHash('sha256').update(JSON.stringify({
|
|
327
|
+
id: entry.id, key: entry.idempotencyKey, command: entry.command, method: entry.method,
|
|
328
|
+
url: entry.url, body: entry.body, workspaceId: entry.workspaceId ?? null,
|
|
329
|
+
})).digest('hex');
|
|
330
|
+
}
|
|
231
331
|
/**
|
|
232
332
|
* Append one entry, fsynced before returning.
|
|
233
333
|
*
|
|
@@ -243,79 +343,72 @@ function ensureDir(profile) {
|
|
|
243
343
|
* grows for as long as nobody is looking, which is exactly the situation a
|
|
244
344
|
* queue exists for.
|
|
245
345
|
*
|
|
246
|
-
*
|
|
247
|
-
* authored and still remembers, and losing that is the more visible failure.
|
|
346
|
+
* A full queue refuses the new entry; it never discards an older write.
|
|
248
347
|
*/
|
|
249
348
|
const MAX_QUEUED_WRITES = 200;
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
// Without this, a command that retries against a persistent 401 appends a
|
|
255
|
-
// fresh `obx_<uuid>` every attempt, and the queue fills with duplicates of
|
|
256
|
-
// one intent. They would all replay, and the idempotency key would make the
|
|
257
|
-
// server collapse them — but only after the CLI had stored, drained and sent
|
|
258
|
-
// each copy, and only if the server side is actually enforcing it.
|
|
259
|
-
//
|
|
260
|
-
// Matching on `idempotencyKey` is what makes this safe: it is caller-minted
|
|
261
|
-
// and stable for the logical write (see `idempotencyKeyFor`), so two entries
|
|
262
|
-
// sharing one are the same intent by construction, not by coincidence.
|
|
263
|
-
if (input.idempotencyKey) {
|
|
264
|
-
const existing = listWrites(profile).find((e) => e.idempotencyKey === input.idempotencyKey);
|
|
265
|
-
if (existing)
|
|
266
|
-
return existing;
|
|
349
|
+
class OutboxFullError extends Error {
|
|
350
|
+
constructor() {
|
|
351
|
+
super(`The local queue already contains ${MAX_QUEUED_WRITES} writes.`);
|
|
352
|
+
this.name = 'OutboxFullError';
|
|
267
353
|
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
//
|
|
277
|
-
//
|
|
278
|
-
//
|
|
279
|
-
|
|
354
|
+
}
|
|
355
|
+
exports.OutboxFullError = OutboxFullError;
|
|
356
|
+
function enqueueWrite(input, profile) {
|
|
357
|
+
return withQueueLock(profile, () => {
|
|
358
|
+
const current = readWritesStrict(profile);
|
|
359
|
+
// Same logical write, already queued → return the existing entry.
|
|
360
|
+
//
|
|
361
|
+
// Without this, a command that retries against a persistent 401 appends a
|
|
362
|
+
// fresh `obx_<uuid>` every attempt, and the queue fills with duplicates of
|
|
363
|
+
// one intent. They would all replay, and the idempotency key would make the
|
|
364
|
+
// server collapse them — but only after the CLI had stored, drained and sent
|
|
365
|
+
// each copy, and only if the server side is actually enforcing it.
|
|
366
|
+
//
|
|
367
|
+
// Matching on `idempotencyKey` is what makes this safe: it is caller-minted
|
|
368
|
+
// and stable for the logical write (see `idempotencyKeyFor`), so two entries
|
|
369
|
+
// sharing one are the same intent by construction, not by coincidence.
|
|
370
|
+
if (input.idempotencyKey) {
|
|
371
|
+
const existing = current.find((e) => e.idempotencyKey === input.idempotencyKey);
|
|
372
|
+
if (existing)
|
|
373
|
+
return existing;
|
|
374
|
+
}
|
|
375
|
+
const entry = {
|
|
376
|
+
...input,
|
|
377
|
+
id: `obx_${crypto.randomUUID()}`,
|
|
378
|
+
queuedAt: new Date().toISOString(),
|
|
379
|
+
attempts: 0,
|
|
380
|
+
};
|
|
381
|
+
if (current.length >= MAX_QUEUED_WRITES) {
|
|
382
|
+
throw new OutboxFullError();
|
|
383
|
+
}
|
|
384
|
+
const fd = fs.openSync(outboxPath(profile), 'a', 0o600);
|
|
385
|
+
try {
|
|
386
|
+
fs.writeFileSync(fd, `${JSON.stringify(entry)}\n`);
|
|
387
|
+
fs.fsyncSync(fd);
|
|
388
|
+
}
|
|
389
|
+
finally {
|
|
390
|
+
fs.closeSync(fd);
|
|
391
|
+
}
|
|
280
392
|
return entry;
|
|
281
|
-
}
|
|
282
|
-
const fd = fs.openSync(outboxPath(profile), 'a', 0o600);
|
|
283
|
-
try {
|
|
284
|
-
fs.writeSync(fd, `${JSON.stringify(entry)}\n`);
|
|
285
|
-
fs.fsyncSync(fd);
|
|
286
|
-
}
|
|
287
|
-
finally {
|
|
288
|
-
fs.closeSync(fd);
|
|
289
|
-
}
|
|
290
|
-
return entry;
|
|
393
|
+
});
|
|
291
394
|
}
|
|
292
|
-
/**
|
|
293
|
-
* Read every intact entry. A truncated trailing line — the shape a crash
|
|
294
|
-
* mid-append leaves — is skipped, because losing the one entry that was still
|
|
295
|
-
* being written is strictly better than failing to read the ones that landed.
|
|
296
|
-
*/
|
|
395
|
+
/** Fail visibly when the queue is unreadable; never present damage as an empty queue. */
|
|
297
396
|
function listWrites(profile) {
|
|
298
|
-
|
|
397
|
+
// Avoid creating an empty queue just to list it, while serializing reads of
|
|
398
|
+
// an existing queue with an append or rename in another process.
|
|
299
399
|
try {
|
|
300
|
-
|
|
400
|
+
fs.statSync(outboxDir(profile));
|
|
301
401
|
}
|
|
302
|
-
catch {
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
for (const line of raw.split('\n')) {
|
|
307
|
-
if (!line.trim())
|
|
308
|
-
continue;
|
|
309
|
-
try {
|
|
310
|
-
const parsed = JSON.parse(line);
|
|
311
|
-
if (parsed && typeof parsed.id === 'string')
|
|
312
|
-
entries.push(parsed);
|
|
313
|
-
}
|
|
314
|
-
catch {
|
|
315
|
-
/* torn trailing line — see the docblock */
|
|
316
|
-
}
|
|
402
|
+
catch (error) {
|
|
403
|
+
if (error.code === 'ENOENT')
|
|
404
|
+
return [];
|
|
405
|
+
throw error;
|
|
317
406
|
}
|
|
318
|
-
return
|
|
407
|
+
return withQueueLock(profile, () => readWritesStrict(profile));
|
|
408
|
+
}
|
|
409
|
+
/** Replay must fail before sending if the queue cannot be read intact. */
|
|
410
|
+
function listReplayWrites(profile) {
|
|
411
|
+
return withQueueLock(profile, () => readWritesStrict(profile));
|
|
319
412
|
}
|
|
320
413
|
/**
|
|
321
414
|
* Rewrite the log with `entries`, atomically (tmp + rename).
|
|
@@ -326,18 +419,82 @@ function listWrites(profile) {
|
|
|
326
419
|
function replaceWrites(entries, profile) {
|
|
327
420
|
ensureDir(profile);
|
|
328
421
|
const file = outboxPath(profile);
|
|
329
|
-
const tmp = `${file}.tmp.${process.pid}`;
|
|
422
|
+
const tmp = `${file}.tmp.${process.pid}.${crypto.randomUUID()}`;
|
|
330
423
|
const payload = entries.map((e) => JSON.stringify(e)).join('\n');
|
|
331
|
-
fs.
|
|
424
|
+
const fd = fs.openSync(tmp, 'wx', 0o600);
|
|
425
|
+
try {
|
|
426
|
+
fs.writeFileSync(fd, payload ? `${payload}\n` : '');
|
|
427
|
+
fs.fsyncSync(fd);
|
|
428
|
+
}
|
|
429
|
+
finally {
|
|
430
|
+
fs.closeSync(fd);
|
|
431
|
+
}
|
|
332
432
|
fs.renameSync(tmp, file);
|
|
333
433
|
}
|
|
434
|
+
/** A claim must reach the directory before a network request can start. */
|
|
435
|
+
function durableReplayReplace(entries, profile) {
|
|
436
|
+
const dir = ensureDir(profile);
|
|
437
|
+
let fd;
|
|
438
|
+
try {
|
|
439
|
+
fd = fs.openSync(dir, 'r');
|
|
440
|
+
// Fail before sending if this filesystem cannot sync its directory.
|
|
441
|
+
fs.fsyncSync(fd);
|
|
442
|
+
replaceWrites(entries, profile);
|
|
443
|
+
fs.fsyncSync(fd);
|
|
444
|
+
}
|
|
445
|
+
catch {
|
|
446
|
+
throw Object.assign(new Error('The outbox could not confirm durable replay state. No further requests were sent; inspect the queue and reconcile any uncertain result.'), {
|
|
447
|
+
code: 'OUTBOX_DURABILITY_UNAVAILABLE', retryable: false,
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
finally {
|
|
451
|
+
if (fd !== undefined)
|
|
452
|
+
fs.closeSync(fd);
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
/** Persist a one-attempt claim before sending. Existing claims are never taken over. */
|
|
456
|
+
function claimOutboxReplay(id, profile) {
|
|
457
|
+
return withQueueLock(profile, () => {
|
|
458
|
+
const entries = readWritesStrict(profile);
|
|
459
|
+
const index = entries.findIndex((entry) => entry.id === id);
|
|
460
|
+
if (index < 0 || entries[index].replay !== undefined)
|
|
461
|
+
return null;
|
|
462
|
+
const now = new Date().toISOString();
|
|
463
|
+
const claimed = {
|
|
464
|
+
...entries[index], attempts: entries[index].attempts + 1, lastAttemptAt: now,
|
|
465
|
+
replay: { state: 'sending', attemptId: crypto.randomUUID(), startedAt: now, fingerprint: replayFingerprint(entries[index]) },
|
|
466
|
+
};
|
|
467
|
+
entries[index] = claimed;
|
|
468
|
+
durableReplayReplace(entries, profile);
|
|
469
|
+
return claimed;
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
/** Retain the content while recording the result of the exact claimed request. */
|
|
473
|
+
function acknowledgeOutboxReplay(claim, resultId, profile) {
|
|
474
|
+
withQueueLock(profile, () => {
|
|
475
|
+
const entries = readWritesStrict(profile);
|
|
476
|
+
const current = entries.find((entry) => entry.id === claim.id);
|
|
477
|
+
if (!claim.replay || !current || current.replay?.attemptId !== claim.replay.attemptId ||
|
|
478
|
+
current.replay.state !== 'sending' || current.replay.fingerprint !== replayFingerprint(current) ||
|
|
479
|
+
current.replay.fingerprint !== claim.replay.fingerprint || !resultId) {
|
|
480
|
+
throw Object.assign(new Error('The outbox entry changed during replay; inspect and reconcile it before trying again.'), {
|
|
481
|
+
code: 'OUTBOX_REPLAY_CHANGED', retryable: false,
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
const updated = entries.map((entry) => entry.id === claim.id
|
|
485
|
+
? { ...entry, replay: { ...claim.replay, state: 'result_recorded', resultId } } : entry);
|
|
486
|
+
durableReplayReplace(updated, profile);
|
|
487
|
+
});
|
|
488
|
+
}
|
|
334
489
|
function dropWrite(id, profile) {
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
490
|
+
return withQueueLock(profile, () => {
|
|
491
|
+
const entries = readWritesStrict(profile);
|
|
492
|
+
const remaining = entries.filter((e) => e.id !== id);
|
|
493
|
+
if (remaining.length === entries.length)
|
|
494
|
+
return false;
|
|
495
|
+
replaceWrites(remaining, profile);
|
|
496
|
+
return true;
|
|
497
|
+
});
|
|
341
498
|
}
|
|
342
499
|
/**
|
|
343
500
|
* Record that the control plane is failing.
|
|
@@ -7,8 +7,9 @@
|
|
|
7
7
|
* 429 as terminal, so a burst of keyed creates failed on the first refusal.
|
|
8
8
|
*
|
|
9
9
|
* Retried only when replay is provably safe: a GET, or a write that carries an
|
|
10
|
-
* `X-Idempotency-Key` (every `request.ts` / adapter write does).
|
|
11
|
-
*
|
|
10
|
+
* `X-Idempotency-Key` (every `request.ts` / adapter write does). Callers must
|
|
11
|
+
* disable retries for routes without server-side replay protection: a client
|
|
12
|
+
* header or a 429 from an intermediary does not prove the write did not run.
|
|
12
13
|
*
|
|
13
14
|
* Never retried when the body says it cannot help: a 429 that declares
|
|
14
15
|
* `retryable: false` (a follow-up budget refusal, which says the day resets at
|
|
@@ -8,8 +8,9 @@
|
|
|
8
8
|
* 429 as terminal, so a burst of keyed creates failed on the first refusal.
|
|
9
9
|
*
|
|
10
10
|
* Retried only when replay is provably safe: a GET, or a write that carries an
|
|
11
|
-
* `X-Idempotency-Key` (every `request.ts` / adapter write does).
|
|
12
|
-
*
|
|
11
|
+
* `X-Idempotency-Key` (every `request.ts` / adapter write does). Callers must
|
|
12
|
+
* disable retries for routes without server-side replay protection: a client
|
|
13
|
+
* header or a 429 from an intermediary does not prove the write did not run.
|
|
13
14
|
*
|
|
14
15
|
* Never retried when the body says it cannot help: a 429 that declares
|
|
15
16
|
* `retryable: false` (a follow-up budget refusal, which says the day resets at
|
package/dist/lib/roles.d.ts
CHANGED
|
@@ -53,7 +53,7 @@ export declare const roleApi: {
|
|
|
53
53
|
config?: Record<string, unknown> | undefined;
|
|
54
54
|
}[];
|
|
55
55
|
sources: {
|
|
56
|
-
source: "space" | "tasks" | "memory" | "daemon" | "email" | "goal" | "files" | "local" | "browser" | "metrics" | "monitor" | "github" | "conversations" | "agent_initiatives" | "messages" | "
|
|
56
|
+
source: "space" | "docs" | "tasks" | "memory" | "daemon" | "email" | "goal" | "files" | "local" | "browser" | "metrics" | "monitor" | "github" | "conversations" | "agent_initiatives" | "messages" | "documents" | "slack" | "calendar" | "product_metrics" | "business_metrics" | "state_monitor" | "agent_run" | "chat_execution";
|
|
57
57
|
enabled: boolean;
|
|
58
58
|
config?: Record<string, unknown> | undefined;
|
|
59
59
|
}[];
|
package/dist/lib/triggers.d.ts
CHANGED
|
@@ -206,6 +206,7 @@ export interface TriggerDefinition {
|
|
|
206
206
|
updatedAt?: string;
|
|
207
207
|
}
|
|
208
208
|
export interface TriggerFireRecord {
|
|
209
|
+
publicProjection?: string;
|
|
209
210
|
_id?: string;
|
|
210
211
|
triggerId?: string;
|
|
211
212
|
occurrenceId?: string;
|
|
@@ -876,6 +877,8 @@ export declare function policyAuditExplanation(fire: {
|
|
|
876
877
|
* server wrote it.
|
|
877
878
|
*/
|
|
878
879
|
export declare function fireReasonText(reason: string): string;
|
|
880
|
+
/** This is a provenance restriction on replay, not a new verdict on the recorded run. */
|
|
881
|
+
export declare function unverifiedReplayExplanation(): string;
|
|
879
882
|
export declare function renderFireAudit(fires: TriggerFireRecord[], log: (line: string) => void, waiting?: TriggerAuditResponse['waiting'], options?: {
|
|
880
883
|
timeZone?: string;
|
|
881
884
|
}): void;
|
package/dist/lib/triggers.js
CHANGED
|
@@ -74,6 +74,7 @@ exports.scheduleStartLagSentence = scheduleStartLagSentence;
|
|
|
74
74
|
exports.policyCardSentence = policyCardSentence;
|
|
75
75
|
exports.policyAuditExplanation = policyAuditExplanation;
|
|
76
76
|
exports.fireReasonText = fireReasonText;
|
|
77
|
+
exports.unverifiedReplayExplanation = unverifiedReplayExplanation;
|
|
77
78
|
exports.renderFireAudit = renderFireAudit;
|
|
78
79
|
exports.describeTriggerBudget = describeTriggerBudget;
|
|
79
80
|
const data_provider_1 = require("@skrr-ai/data-provider");
|
|
@@ -2201,6 +2202,10 @@ function fireReasonText(reason) {
|
|
|
2201
2202
|
return reason;
|
|
2202
2203
|
}
|
|
2203
2204
|
}
|
|
2205
|
+
/** This is a provenance restriction on replay, not a new verdict on the recorded run. */
|
|
2206
|
+
function unverifiedReplayExplanation() {
|
|
2207
|
+
return 'Replay is unavailable because this historical fire cannot be linked with certainty to the current trigger. The recorded outcome is unchanged. Inspect the current action with `skrr triggers show <trigger-id>` before requesting a separate manual run with `skrr triggers fire <trigger-id>`. A manual fire can bypass a disabled trigger and quiet hours, and is not a replay of the original event; permissions and required inputs still apply.';
|
|
2208
|
+
}
|
|
2204
2209
|
function renderFireAudit(fires, log, waiting, options = {}) {
|
|
2205
2210
|
// An armed one-shot whose time passed has no fire record yet. "No records" alone reads as
|
|
2206
2211
|
// "not yet", so say that it is late and what it is waiting for.
|
|
@@ -2211,6 +2216,11 @@ function renderFireAudit(fires, log, waiting, options = {}) {
|
|
|
2211
2216
|
log('No fire audit records.');
|
|
2212
2217
|
return;
|
|
2213
2218
|
}
|
|
2219
|
+
if (fires.some((fire) => fire.publicProjection === 'source_unverified' ||
|
|
2220
|
+
fire.metadata?.replayBlockedReason === 'event_not_authorized'))
|
|
2221
|
+
log('Restricted fire summaries: historical physical Trigger identity is unverified.');
|
|
2222
|
+
if (fires.some((fire) => fire.metadata?.replayBlockedReason === 'source_identity_unverified'))
|
|
2223
|
+
log(unverifiedReplayExplanation());
|
|
2214
2224
|
(0, format_1.renderTable)(fires.map((fire) => ({
|
|
2215
2225
|
trigger: fire.triggerId ?? '',
|
|
2216
2226
|
firedAt: options.timeZone ? (0, format_1.zonedTime)(fire.firedAt, options.timeZone, { seconds: false }) : (fire.firedAt ?? '-'),
|
package/dist/lib/widgetCheck.js
CHANGED
|
@@ -198,7 +198,7 @@ function errorMessage(err) {
|
|
|
198
198
|
const message = err?.message;
|
|
199
199
|
return typeof message === 'string' ? message : String(err);
|
|
200
200
|
}
|
|
201
|
-
function syntaxIssue(script, section, firstLine) {
|
|
201
|
+
function syntaxIssue(script, section, firstLine, sourceLines) {
|
|
202
202
|
try {
|
|
203
203
|
// Compile only. `vm.Script` parses and reports early errors; it never runs the code.
|
|
204
204
|
new vm.Script(script, { filename: 'widget.js' });
|
|
@@ -215,7 +215,9 @@ function syntaxIssue(script, section, firstLine) {
|
|
|
215
215
|
source: 'syntax',
|
|
216
216
|
code: 'syntax/js',
|
|
217
217
|
section,
|
|
218
|
-
line:
|
|
218
|
+
line: sourceLines === undefined
|
|
219
|
+
? firstLine + (at ? Number(at[1]) - 1 : 0)
|
|
220
|
+
: sourceLines?.[(at ? Number(at[1]) : 1) - 1],
|
|
219
221
|
message: `JavaScript syntax error: ${message}. The script would stop before running.`,
|
|
220
222
|
...(fix ? { fix } : {}),
|
|
221
223
|
};
|
|
@@ -242,9 +244,33 @@ function contentIssues(parts) {
|
|
|
242
244
|
issues.push(syntax);
|
|
243
245
|
}
|
|
244
246
|
}
|
|
245
|
-
|
|
247
|
+
let scan;
|
|
248
|
+
try {
|
|
249
|
+
scan = (0, widgetStaticScan_1.scanWidgetSource)(parts);
|
|
250
|
+
}
|
|
251
|
+
catch {
|
|
252
|
+
issues.push({
|
|
253
|
+
severity: 'error',
|
|
254
|
+
source: 'static',
|
|
255
|
+
code: 'static/scanner-unavailable',
|
|
256
|
+
message: 'The static scan could not finish; static findings and inline script syntax checks may be incomplete.',
|
|
257
|
+
fix: 'Simplify the widget markup or try the check again.',
|
|
258
|
+
heuristic: true,
|
|
259
|
+
});
|
|
260
|
+
return issues;
|
|
261
|
+
}
|
|
262
|
+
if (scan.inlineCoverageComplete === false) {
|
|
263
|
+
issues.push({
|
|
264
|
+
severity: 'warn',
|
|
265
|
+
source: 'static',
|
|
266
|
+
code: 'static/template-script-unchecked',
|
|
267
|
+
section: 'html',
|
|
268
|
+
message: 'Scripts in templates do not run at initial load; if widget code activates them later, their syntax and static findings have not been checked.',
|
|
269
|
+
heuristic: true,
|
|
270
|
+
});
|
|
271
|
+
}
|
|
246
272
|
for (const script of scan.inlineScripts) {
|
|
247
|
-
const syntax = syntaxIssue(script.content, 'html', script.line);
|
|
273
|
+
const syntax = syntaxIssue(script.content, 'html', script.line, script.sourceLines);
|
|
248
274
|
if (syntax) {
|
|
249
275
|
issues.push(syntax);
|
|
250
276
|
}
|