@north-light/cli 0.3.708 → 0.3.709
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/api/contract.d.ts +1 -1
- package/dist/api/contract.js +1 -1
- package/dist/api/dto/crons.d.ts +3 -0
- package/dist/clients/attach/chrome/inbox-strip.js +1 -1
- package/dist/clients/attach/chrome/roster.js +6 -6
- package/dist/clients/attach/chrome/status-line.d.ts +1 -1
- package/dist/clients/attach/chrome/status-line.js +1 -1
- package/dist/clients/attach/input/capabilities.js +1 -1
- package/dist/clients/attach/input/controller.d.ts +4 -0
- package/dist/clients/attach/input/controller.js +3 -3
- package/dist/clients/attach/overlays/graph.d.ts +3 -2
- package/dist/clients/attach/overlays/graph.js +1 -1
- package/dist/clients/attach/render/chat-view.d.ts +2 -0
- package/dist/clients/attach/render/chat-view.js +1 -1
- package/dist/clients/attach/render/doc-links.d.ts +1 -1
- package/dist/clients/attach/session/chrome-refresh.js +1 -1
- package/dist/clients/attach/session/connection.d.ts +10 -9
- package/dist/clients/attach/session/connection.js +1 -1
- package/dist/clients/attach/session/context.d.ts +1 -1
- package/dist/clients/attach/session/document-links.d.ts +1 -1
- package/dist/clients/attach/session/document-links.js +1 -1
- package/dist/clients/attach/session/identity.d.ts +2 -0
- package/dist/clients/attach/session/identity.js +1 -1
- package/dist/clients/attach/session/input-wiring.d.ts +2 -0
- package/dist/clients/attach/session/input-wiring.js +1 -1
- package/dist/clients/attach/session/keys.d.ts +2 -0
- package/dist/clients/attach/session/keys.js +1 -1
- package/dist/clients/attach/session/pane-tag.d.ts +3 -1
- package/dist/clients/attach/session/pane-tag.js +1 -1
- package/dist/clients/attach/session/reconnect.js +1 -1
- package/dist/clients/attach/session/teardown.d.ts +2 -2
- package/dist/clients/attach/session/teardown.js +9 -7
- package/dist/clients/attach/viewer.d.ts +7 -5
- package/dist/clients/attach/viewer.js +540 -538
- package/dist/commands/node/wait.js +2 -6
- package/dist/core/broker-client/client.d.ts +6 -3
- package/dist/core/broker-client/client.js +1 -1
- package/dist/core/canvas/crons.d.ts +11 -1
- package/dist/core/canvas/crons.js +14 -14
- package/dist/core/canvas/executions.js +1 -1
- package/dist/core/canvas/schema-pg/026-cron-deadline-body.sql +9 -0
- package/dist/core/canvas/schema-pg/027-cron-fires.sql +4 -0
- package/dist/core/canvas/schema-version.d.ts +1 -1
- package/dist/core/canvas/schema-version.js +1 -1
- package/dist/core/command.js +5 -5
- package/dist/core/feed/messages.d.ts +5 -0
- package/dist/core/feed/messages.js +5 -5
- package/dist/core/runtime/bearings.js +4 -4
- package/dist/core/runtime/boot-root.js +4 -4
- package/dist/core/runtime/lifecycle.js +2 -2
- package/dist/core/runtime/revive.js +2 -2
- package/dist/core/runtime/runner/blaxel/client.d.ts +4 -0
- package/dist/core/runtime/runner/blaxel/client.js +1 -1
- package/dist/core/runtime/runner/blaxel/runner.d.ts +2 -3
- package/dist/core/runtime/runner/blaxel/runner.js +3 -3
- package/dist/core/runtime/runner/delete-sandboxes.d.ts +5 -0
- package/dist/core/runtime/runner/delete-sandboxes.js +6 -1
- package/dist/core/runtime/runner/types.d.ts +19 -3
- package/dist/daemon/api/bridge.d.ts +5 -0
- package/dist/daemon/api/bridge.js +3 -3
- package/dist/daemon/api/handlers/crons.d.ts +2 -0
- package/dist/daemon/api/handlers/crons.js +1 -1
- package/dist/daemon/api/handlers/nodes.js +1 -1
- package/dist/daemon/api/operations.js +1 -1
- package/dist/daemon/cron/ended.d.ts +3 -0
- package/dist/daemon/cron/ended.js +2 -2
- package/dist/daemon/cron/lease-recovery.js +1 -1
- package/dist/daemon/cron/machine-fire.d.ts +9 -2
- package/dist/daemon/cron/machine-fire.js +1 -1
- package/dist/daemon/cron/passes.js +1 -1
- package/dist/daemon/cron-run.js +2 -2
- package/dist/daemon/machine-link/client.js +1 -1
- package/dist/daemon/reconcilers/fault-retry-backstop.js +1 -1
- package/dist/daemon/reconcilers/idle-sandbox.d.ts +1 -1
- package/dist/daemon/reconcilers/idle-sandbox.js +2 -2
- package/dist/daemon/reconcilers/node-lifecycle/remote-wake.js +2 -2
- package/package.json +3 -3
- package/packages/crouter-api/dist/api/contract.js +1 -1
- package/packages/crouter-api/dist/clients/attach/chrome/inbox-strip.js +5 -5
- package/packages/crouter-api/dist/clients/attach/chrome/roster.js +8 -8
- package/packages/crouter-api/dist/clients/attach/chrome/status-line.js +1 -1
- package/packages/crouter-api/dist/clients/attach/input/capabilities.js +2 -1
- package/packages/crouter-api/dist/clients/attach/input/controller.js +17 -0
- package/packages/crouter-api/dist/clients/attach/overlays/graph.js +4 -3
- package/packages/crouter-api/dist/clients/attach/render/chat-view.js +9 -0
- package/packages/crouter-api/dist/clients/attach/session/chrome-refresh.js +6 -3
- package/packages/crouter-api/dist/clients/attach/session/connection.js +53 -53
- package/packages/crouter-api/dist/clients/attach/session/document-links.js +1 -1
- package/packages/crouter-api/dist/clients/attach/session/identity.js +1 -0
- package/packages/crouter-api/dist/clients/attach/session/input-wiring.js +4 -3
- package/packages/crouter-api/dist/clients/attach/session/keys.js +11 -4
- package/packages/crouter-api/dist/clients/attach/session/pane-tag.js +7 -1
- package/packages/crouter-api/dist/clients/attach/session/reconnect.js +3 -3
- package/packages/crouter-api/dist/clients/attach/session/teardown.js +7 -4
- package/packages/crouter-api/dist/clients/attach/viewer.js +77 -30
- package/packages/crouter-api/dist/commands/node/wait.js +2 -10
- package/packages/crouter-api/dist/core/broker-client/client.js +20 -10
- package/packages/crouter-api/dist/core/canvas/crons.js +26 -10
- package/packages/crouter-api/dist/core/canvas/executions.js +7 -2
- package/packages/crouter-api/dist/core/canvas/schema-version.js +1 -1
- package/packages/crouter-api/dist/core/command.js +3 -0
- package/packages/crouter-api/dist/core/feed/messages.js +15 -0
- package/packages/crouter-api/dist/core/runtime/bearings.js +2 -2
- package/packages/crouter-api/dist/core/runtime/lifecycle.js +3 -0
- package/packages/crouter-api/dist/core/runtime/revive.js +5 -25
- package/packages/crouter-api/dist/core/runtime/runner/blaxel/client.js +15 -8
- package/packages/crouter-api/dist/core/runtime/runner/blaxel/runner.js +60 -19
- package/packages/crouter-api/dist/core/runtime/runner/delete-sandboxes.js +18 -2
- package/packages/crouter-api/dist/daemon/api/operations.js +2 -2
- package/packages/crouter-api/dist/daemon/cron/ended.js +22 -11
- package/packages/crouter-api/dist/daemon/cron/machine-fire.js +69 -6
- package/packages/crouter-api/dist/daemon/reconcilers/node-lifecycle/remote-wake.js +2 -2
- package/packages/crouter-api/package.json +1 -1
- package/packages/crouter-identity/package.json +1 -1
- package/packages/crouter-plugin/package.json +3 -3
- package/runtime.lock.json +14 -14
- package/dist/core/runtime/starting-screen.d.ts +0 -12
- package/dist/core/runtime/starting-screen.js +0 -9
|
@@ -6,15 +6,16 @@
|
|
|
6
6
|
// command again. A scheduled fire whose machine has no live link at its due time is not claimed at all and stays due. A fire that was
|
|
7
7
|
// claimed stays owed under its run id across an outage of any length: it is sent again until the machine answers, and a control plane
|
|
8
8
|
// that crashed after claiming picks the same run id up from the cron row (`resumeMachineFire`) instead of calling the run crashed.
|
|
9
|
-
import { randomUUID } from 'node:crypto';
|
|
9
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
10
|
+
import { join } from 'node:path';
|
|
10
11
|
import { setTimeout as delay } from 'node:timers/promises';
|
|
11
12
|
import { openDb } from '../../core/canvas/db.js';
|
|
12
13
|
import { isCloudRole } from '../../core/canvas/person.js';
|
|
13
14
|
import { withCanvasWrite } from '../../core/canvas/db.js';
|
|
14
15
|
import { getNode } from '../../core/canvas/canvas.js';
|
|
16
|
+
import { runnerForEnvironment } from '../../core/runtime/runner/index.js';
|
|
15
17
|
import { callMachine } from '../../core/runtime/runner/machine/call.js';
|
|
16
18
|
import { machineEnvironmentOfNode } from '../../core/runtime/runner/machine/runner.js';
|
|
17
|
-
import { machineEnvironmentOfProfile } from '../../core/runtime/runner/machine/environment.js';
|
|
18
19
|
import { MachineCallFailedError, MachineLostError, MachineOfflineError } from '../../core/runtime/runner/machine/ops.js';
|
|
19
20
|
import { environmentSecrets } from '../../core/secrets/environment-secrets.js';
|
|
20
21
|
import { profileInApp } from '../../core/secrets/environment-owner.js';
|
|
@@ -22,18 +23,20 @@ import { getCron } from '../../core/canvas/crons.js';
|
|
|
22
23
|
import { emitEvent } from '../../core/events/emit.js';
|
|
23
24
|
import { runTokenFor } from './run-token.js';
|
|
24
25
|
import { parseArmedEnv } from './armed-context.js';
|
|
25
|
-
import { CRON_OUTPUT_HEAD_BYTES } from './capture.js';
|
|
26
|
+
import { CRON_OUTPUT_HEAD_BYTES, formatCronOutputHead } from './capture.js';
|
|
26
27
|
import { settleClosedRun, settleUnspawnedRun } from './closed.js';
|
|
27
28
|
import { clearLiveRun, registerLiveRun } from './live-runs.js';
|
|
28
29
|
import { advanceRecurrence } from './recurrence.js';
|
|
29
30
|
/** Seconds past the run's timeout a send waits for its answer. */
|
|
30
31
|
const ANSWER_SLACK_S = 15;
|
|
31
32
|
const RESEND_EVERY_MS = 2_000;
|
|
32
|
-
/**
|
|
33
|
-
|
|
33
|
+
/** Where a cron runs off this process: its profile's machine or Blaxel environment on a cloud role, or null when it runs here (a Mac's own
|
|
34
|
+
* daemon, a local runtime, a cron with no profile). */
|
|
35
|
+
export async function cronEnvironment(c) {
|
|
34
36
|
if (!isCloudRole() || c.profile == null)
|
|
35
37
|
return null;
|
|
36
|
-
|
|
38
|
+
const row = await (await openDb()).prepare('SELECT e.object AS id, e.kind AS kind FROM profiles p JOIN environments e ON e.object = p.environment_id WHERE p.id = ?').get(c.profile);
|
|
39
|
+
return row ?? null;
|
|
37
40
|
}
|
|
38
41
|
export async function machineLinkLive(environmentId) {
|
|
39
42
|
return (await (await openDb()).prepare('SELECT 1 AS live FROM machine_links WHERE environment = ? AND lease_expires_at > ?').get(environmentId, new Date().toISOString())) !== undefined;
|
|
@@ -175,3 +178,63 @@ async function driveFire(c, fire, prepared, admit) {
|
|
|
175
178
|
clearLiveRun(c.cron_id, runId);
|
|
176
179
|
}
|
|
177
180
|
}
|
|
181
|
+
/** Where a hosted node's files sit inside its sandbox: `CRTR_HOME` and the `apps/<app>/{home,nodes/<id>/context}` layout of scripts/sandbox-start.mjs. */
|
|
182
|
+
const SANDBOX_CRTR_HOME = '/var/lib/crtr';
|
|
183
|
+
/** Fire `c` in its anchor node's sandbox through the Blaxel runner and settle the run. The same run id names the sandbox process, so a
|
|
184
|
+
* control plane that recovers the run (`resume`) reads the first start instead of running the command again. */
|
|
185
|
+
export async function fireInSandbox(c, fire, admit, resume = false) {
|
|
186
|
+
const { runId, outOfBand, startedAtIso, startedAtMs } = fire;
|
|
187
|
+
let env;
|
|
188
|
+
let runner;
|
|
189
|
+
try {
|
|
190
|
+
runner = runnerForEnvironment('blaxel');
|
|
191
|
+
if (runner.cronRun === undefined || runner.cronCancel === undefined)
|
|
192
|
+
throw new Error('the registered Blaxel runner cannot run crons');
|
|
193
|
+
const apiUrl = process.env['CRTR_PUBLIC_API_URL'];
|
|
194
|
+
if (!apiUrl)
|
|
195
|
+
throw new Error('CRTR_PUBLIC_API_URL is not set, so a sandbox cron could not reach the API');
|
|
196
|
+
if (c.anchor_node == null)
|
|
197
|
+
throw new Error('a hosted cron runs in its anchor node\'s sandbox, and this cron has no anchor node');
|
|
198
|
+
if (c.isolated)
|
|
199
|
+
throw new Error('an isolated cron needs a root launcher, which a sandbox does not have');
|
|
200
|
+
const prepared = await prepareRun(c, runId);
|
|
201
|
+
const anchor = prepared.contextAnchor;
|
|
202
|
+
env = { ...prepared.env, CRTR_API_URL: apiUrl, HOME: join(SANDBOX_CRTR_HOME, 'apps', c.grantee.replace(/^app:/, ''), 'home'),
|
|
203
|
+
...(anchor !== null ? { CRTR_CONTEXT_DIR: join(SANDBOX_CRTR_HOME, 'apps', anchor.grantee.replace(/^app:/, ''), 'nodes', anchor.node, 'context') } : {}) };
|
|
204
|
+
// A recovered run's slot may already have moved past this start; advancing again is a no-op then.
|
|
205
|
+
if (!outOfBand && c.recur != null && (!resume || Date.parse(c.fire_at) <= startedAtMs)) {
|
|
206
|
+
const recurrenceError = await advanceRecurrence(c, startedAtMs);
|
|
207
|
+
if (recurrenceError !== null)
|
|
208
|
+
throw recurrenceError;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
catch (err) {
|
|
212
|
+
return await settleUnspawnedRun(c, fire, 'run could not be armed', err);
|
|
213
|
+
}
|
|
214
|
+
const anchorNode = c.anchor_node;
|
|
215
|
+
const live = { runId, replaced: false, selfCanceled: false, kill: () => {
|
|
216
|
+
void runner.cronCancel(anchorNode, runId).catch((error) => {
|
|
217
|
+
emitEvent({ level: 'error', event: 'cron.sandbox.cancel_failed', error, fields: { cron_id: c.cron_id, run_id: runId } });
|
|
218
|
+
});
|
|
219
|
+
} };
|
|
220
|
+
registerLiveRun(c.cron_id, live);
|
|
221
|
+
admit();
|
|
222
|
+
try {
|
|
223
|
+
let result;
|
|
224
|
+
try {
|
|
225
|
+
result = await runner.cronRun(anchorNode, { runId, command: c.command, cwd: c.cwd, env, timeoutS: c.run_timeout_s, startedAtMs });
|
|
226
|
+
}
|
|
227
|
+
catch (err) {
|
|
228
|
+
return await settleUnspawnedRun(c, fire, 'run failed in the sandbox', err);
|
|
229
|
+
}
|
|
230
|
+
const head = (text) => text.length > CRON_OUTPUT_HEAD_BYTES ? formatCronOutputHead(text.slice(0, CRON_OUTPUT_HEAD_BYTES), true) : text;
|
|
231
|
+
return await settleClosedRun(c, {
|
|
232
|
+
runId, outOfBand, startedAtIso, startedAtMs, finishedAtMs: Date.now(), code: result.exitCode, timedOut: result.timedOut, processError: result.error === undefined ? null : new Error(result.error),
|
|
233
|
+
stdoutHead: head(result.stdout), stderrHead: head(result.stderr), stdoutSha256: createHash('sha256').update(result.stdout).digest('hex'),
|
|
234
|
+
wasReplaced: live.replaced, wasSelfCanceled: live.selfCanceled,
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
finally {
|
|
238
|
+
clearLiveRun(c.cron_id, runId);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
@@ -150,8 +150,8 @@ export async function recoverLaunching(nodeId, now) {
|
|
|
150
150
|
await publishNotice(nodeId, 'notice.crash', wake, { reason: 'child-crashed', child: nodeId });
|
|
151
151
|
}
|
|
152
152
|
}
|
|
153
|
-
// The failed
|
|
154
|
-
await runner.
|
|
153
|
+
// The failed launch's sandbox is not reused: the next start creates the node's sandbox afresh. It goes last, once the verdict is recorded.
|
|
154
|
+
await runner.delete(execution.nodeId);
|
|
155
155
|
return true;
|
|
156
156
|
}
|
|
157
157
|
// gone: the next wake is attempt + 1, and the lane does not count it as a respawn failure.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@north-light/api",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.709",
|
|
4
4
|
"description": "Typed crtrd /v1 API contract — DTOs, route builders, the error contract, the CrtrClient, and the command-plugin manifest format. Zero runtime dependencies.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/api/index.js",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@north-light/plugin",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.709",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"postpack": "node ../../scripts/pack-minify.mjs postpack packages/crouter-plugin"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@north-light/api": "0.3.
|
|
31
|
-
"@north-light/identity": "0.3.
|
|
30
|
+
"@north-light/api": "0.3.709",
|
|
31
|
+
"@north-light/identity": "0.3.709"
|
|
32
32
|
},
|
|
33
33
|
"license": "UNLICENSED",
|
|
34
34
|
"publishConfig": {
|
package/runtime.lock.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@north-light/cli",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.709",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@north-light/cli",
|
|
9
|
-
"version": "0.3.
|
|
9
|
+
"version": "0.3.709",
|
|
10
10
|
"hasInstallScript": true,
|
|
11
11
|
"license": "UNLICENSED",
|
|
12
12
|
"workspaces": [
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
"@milkdown/preset-gfm": "^7.22.3",
|
|
29
29
|
"@milkdown/prose": "^7.22.3",
|
|
30
30
|
"@milkdown/utils": "^7.22.3",
|
|
31
|
-
"@north-light/identity": "0.3.
|
|
32
|
-
"@north-light/plugin": "0.3.
|
|
31
|
+
"@north-light/identity": "0.3.709",
|
|
32
|
+
"@north-light/plugin": "0.3.709",
|
|
33
33
|
"cron-parser": "^5.6.0",
|
|
34
34
|
"esbuild": "0.28.2",
|
|
35
35
|
"jose": "^6.2.12",
|
|
@@ -11902,17 +11902,17 @@
|
|
|
11902
11902
|
},
|
|
11903
11903
|
"packages/crouter-api": {
|
|
11904
11904
|
"name": "@north-light/api",
|
|
11905
|
-
"version": "0.3.
|
|
11905
|
+
"version": "0.3.709",
|
|
11906
11906
|
"license": "UNLICENSED"
|
|
11907
11907
|
},
|
|
11908
11908
|
"packages/crouter-env-docker": {
|
|
11909
11909
|
"name": "@north-light/env-docker",
|
|
11910
|
-
"version": "0.3.
|
|
11910
|
+
"version": "0.3.709",
|
|
11911
11911
|
"license": "UNLICENSED"
|
|
11912
11912
|
},
|
|
11913
11913
|
"packages/crouter-identity": {
|
|
11914
11914
|
"name": "@north-light/identity",
|
|
11915
|
-
"version": "0.3.
|
|
11915
|
+
"version": "0.3.709",
|
|
11916
11916
|
"license": "UNLICENSED",
|
|
11917
11917
|
"dependencies": {
|
|
11918
11918
|
"jose": "^6.2.1"
|
|
@@ -11920,21 +11920,21 @@
|
|
|
11920
11920
|
},
|
|
11921
11921
|
"packages/crouter-plugin": {
|
|
11922
11922
|
"name": "@north-light/plugin",
|
|
11923
|
-
"version": "0.3.
|
|
11923
|
+
"version": "0.3.709",
|
|
11924
11924
|
"license": "UNLICENSED",
|
|
11925
11925
|
"dependencies": {
|
|
11926
|
-
"@north-light/api": "0.3.
|
|
11927
|
-
"@north-light/identity": "0.3.
|
|
11926
|
+
"@north-light/api": "0.3.709",
|
|
11927
|
+
"@north-light/identity": "0.3.709"
|
|
11928
11928
|
}
|
|
11929
11929
|
},
|
|
11930
11930
|
"packages/crouter-sdk": {
|
|
11931
11931
|
"name": "@north-light/sdk",
|
|
11932
|
-
"version": "0.3.
|
|
11932
|
+
"version": "0.3.709",
|
|
11933
11933
|
"license": "UNLICENSED",
|
|
11934
11934
|
"dependencies": {
|
|
11935
|
-
"@north-light/api": "0.3.
|
|
11936
|
-
"@north-light/identity": "0.3.
|
|
11937
|
-
"@north-light/plugin": "0.3.
|
|
11935
|
+
"@north-light/api": "0.3.709",
|
|
11936
|
+
"@north-light/identity": "0.3.709",
|
|
11937
|
+
"@north-light/plugin": "0.3.709",
|
|
11938
11938
|
"jose": "^6.2.1"
|
|
11939
11939
|
},
|
|
11940
11940
|
"bin": {
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export interface StartingInfo {
|
|
2
|
-
version?: string;
|
|
3
|
-
profile?: string;
|
|
4
|
-
cwd?: string;
|
|
5
|
-
}
|
|
6
|
-
export interface StartingScreen {
|
|
7
|
-
/** Erase the screen and give the terminal back (cursor shown, raw mode off). */
|
|
8
|
-
stop(): void;
|
|
9
|
-
/** Record the created node so an interrupt can say how to reopen it. */
|
|
10
|
-
setNode(nodeId: string): void;
|
|
11
|
-
}
|
|
12
|
-
export declare function showStartingScreen(info: StartingInfo): StartingScreen;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
var R=Object.defineProperty;var e=(s,t)=>R(s,"name",{value:t,configurable:!0});import{homedir as g}from"node:os";import{croutonBannerLines as A}from"./banner.js";const T="\x1B[2m",x="\x1B[0m",D=100,G="\x1B7",E="\x1B8",S="\x1B[J",L="\x1B[2K";function v(s){const t=process.stdout,h=Date.now();let p=!1,r;const c=g(),u=s.cwd===void 0?void 0:s.cwd===c?"~":s.cwd.startsWith(`${c}/`)?`~${s.cwd.slice(c.length)}`:s.cwd,i=A({...s,...u===void 0?{}:{cwd:u}}).join(`\r
|
|
2
|
-
`),d=e(()=>`${T}starting ${((Date.now()-h)/1e3).toFixed(1)}s${x}`,"seconds"),b=e(()=>{t.write(`\r${L}${d()}`)},"tick"),l=e(()=>{t.write(`${E}${S}${i}\r
|
|
3
|
-
\r
|
|
4
|
-
${d()}`)},"drawAll"),w=e(()=>r===void 0?"":`crtr: the agent ${r} is still running; reopen it with crtr -r ${r}
|
|
5
|
-
`,"reopenNote"),$=process.stdin.isTTY===!0,f=e(n=>{n.includes(3)&&(a(),process.stderr.write(w()),process.exit(130))},"onData"),o=e(n=>{a(),process.stderr.write(w()),process.kill(process.pid,n)},"onSignal");$&&(process.stdin.setRawMode(!0),process.stdin.on("data",f),process.stdin.resume()),process.once("SIGTERM",o),process.once("SIGHUP",o),t.on("resize",l);const m=i.split(`\r
|
|
6
|
-
`).reduce((n,M)=>n+Math.max(1,Math.ceil(M.replaceAll(/\u001b\[[0-9;]*m/g,"").length/Math.max(1,t.columns??80))),0)+2;t.write(`\x1B[?25l${`
|
|
7
|
-
`.repeat(m)}\x1B[${m}A${G}${i}\r
|
|
8
|
-
\r
|
|
9
|
-
${d()}`);const I=setInterval(b,D);function a(){p||(p=!0,clearInterval(I),t.off("resize",l),process.off("SIGTERM",o),process.off("SIGHUP",o),t.write(`${E}${S}\x1B[?25h`),$&&(process.stdin.off("data",f),process.stdin.pause(),process.stdin.setRawMode(!1)))}return e(a,"stop"),{stop:a,setNode:e(n=>{r=n},"setNode")}}e(v,"showStartingScreen");export{v as showStartingScreen};
|