larness 0.5.0 → 0.6.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/apps/server/dist/{managed-Cw3MVilO.js → address-DpgJ0siq.js} +317 -183
- package/apps/server/dist/{args-CrKTPT06.js → args-BdJc1CBU.js} +29 -22
- package/apps/server/dist/cli.js +28 -7
- package/apps/server/dist/client-CBpatu1B.js +28 -0
- package/apps/server/dist/{client-D_Ni3Zpx.js → client-CoxHAiNW.js} +1 -1
- package/apps/server/dist/doctor-CGNZt_v3.js +1 -0
- package/apps/server/dist/{doctor-CE6cONuz.js → doctor-rpwPrkoS.js} +4 -3
- package/apps/server/dist/doctor.js +1 -1
- package/apps/server/dist/index.js +1424 -507
- package/apps/server/dist/{inspect-XgAc84F9.js → inspect-DUe_-Yma.js} +89 -1
- package/apps/server/dist/{lifecycle-C3KV3-Ax.js → lifecycle-Ck4LRKft.js} +7 -4
- package/apps/server/dist/managed-CpNf_iJZ.js +191 -0
- package/apps/server/dist/status-B6kiOT0f.js +94 -0
- package/apps/server/dist/status-C0hriYPD.js +681 -0
- package/apps/server/dist/status.js +1 -58
- package/apps/server/dist/{supervisor-IYDKL4iU.js → supervisor-BvHyiN7Z.js} +3 -2
- package/apps/server/dist/tui.js +5 -5
- package/apps/server/dist/unlock-hrRXYx4L.js +87 -0
- package/apps/server/drizzle/0001_auth.sql +109 -109
- package/apps/server/drizzle/0002_projects.sql +12 -12
- package/apps/server/drizzle/0003_workspace.sql +80 -80
- package/apps/server/drizzle/0004_models.sql +30 -30
- package/apps/server/drizzle/0005_resources.sql +54 -54
- package/apps/server/drizzle/0006_commands.sql +23 -23
- package/apps/server/drizzle/0007_terminals.sql +41 -41
- package/apps/server/drizzle/0008_resource_actions.sql +23 -23
- package/apps/server/drizzle/0010_services.sql +31 -31
- package/apps/server/drizzle/0039_user_input_requests.sql +20 -0
- package/apps/server/drizzle/meta/0039_snapshot.json +5907 -0
- package/apps/server/drizzle/meta/_journal.json +7 -0
- package/apps/web/dist/assets/{FileEditor-DnQa6Owc.js → FileEditor-Cm9Wkyig.js} +1 -1
- package/apps/web/dist/assets/{FileViewer-DKlF-CWF.js → FileViewer-CZH6oX37.js} +1 -1
- package/apps/web/dist/assets/{cssMode-C9KmpsHc.js → cssMode-CAew8VW7.js} +1 -1
- package/apps/web/dist/assets/{editor.api-BwfHyHQ6.js → editor.api-CzAuy9rK.js} +1 -1
- package/apps/web/dist/assets/{freemarker2-D41RlIQ5.js → freemarker2-BucrIW4m.js} +1 -1
- package/apps/web/dist/assets/{handlebars-D-7R6ic0.js → handlebars-PSDIVzvE.js} +1 -1
- package/apps/web/dist/assets/{html-CUME4rt-.js → html-BAsmazci.js} +1 -1
- package/apps/web/dist/assets/{htmlMode-8w7WLhnL.js → htmlMode-Dc7T3d51.js} +1 -1
- package/apps/web/dist/assets/{index-BOS3UrP1.js → index-BzvuZhoD.js} +2 -2
- package/apps/web/dist/assets/{javascript-_3pdDG34.js → javascript-BOV99GQZ.js} +1 -1
- package/apps/web/dist/assets/{jsonMode-DiqocFCf.js → jsonMode-NusHHC7o.js} +1 -1
- package/apps/web/dist/assets/{liquid-j0FoiTXN.js → liquid-CNm5kTmC.js} +1 -1
- package/apps/web/dist/assets/{lspLanguageFeatures-Zj7K2sG4.js → lspLanguageFeatures-Cqpje4pY.js} +1 -1
- package/apps/web/dist/assets/main-ACTS2h7h.js +157 -0
- package/apps/web/dist/assets/main-DLLJi8c-.css +1 -0
- package/apps/web/dist/assets/{mdx-CGQ8Cw6J.js → mdx-CiTFZ2Bw.js} +1 -1
- package/apps/web/dist/assets/{monaco-CyMA3azg.js → monaco-A0m6b37p.js} +3 -3
- package/apps/web/dist/assets/{python-BtY34Z9A.js → python-CB1KNVKd.js} +1 -1
- package/apps/web/dist/assets/{razor-CzYHpLv5.js → razor-CWXh8JSQ.js} +1 -1
- package/apps/web/dist/assets/{tsMode-GZx3VEv9.js → tsMode-DML0dqzP.js} +1 -1
- package/apps/web/dist/assets/{typescript-CAfvuTDQ.js → typescript-BVEQXq27.js} +1 -1
- package/apps/web/dist/assets/{workers-C5BOxOmH.js → workers-DOOC_w8B.js} +1 -1
- package/apps/web/dist/assets/{xml-BGX4mtH7.js → xml-kLrSHWW0.js} +1 -1
- package/apps/web/dist/assets/{yaml-B2AgBtJB.js → yaml-CclA2znJ.js} +1 -1
- package/apps/web/dist/favicon.svg +4 -4
- package/apps/web/dist/index.html +1 -1
- package/docs/guides/install.md +3 -0
- package/package.json +1 -1
- package/apps/server/dist/address-D0ZG5qR4.js +0 -97
- package/apps/server/dist/doctor-sPRlI92N.js +0 -1
- package/apps/server/dist/status-CV_zWfs6.js +0 -62
- package/apps/web/dist/assets/main-DZIruO5x.js +0 -157
- package/apps/web/dist/assets/main-gq3n_vn8.css +0 -1
|
@@ -287,6 +287,38 @@ const FilePathSchema = z.string().min(1).max(4096).refine((value) => {
|
|
|
287
287
|
return !normalized.startsWith("/") && !normalized.includes("\0") && normalized.split("/").every((part) => part !== ".." && !part.includes(":"));
|
|
288
288
|
}, "Expected a relative path inside the authorized root").transform((value) => value.replaceAll("\\", "/"));
|
|
289
289
|
const FileVersionSchema = z.string().regex(/^[a-f0-9]{64}$/);
|
|
290
|
+
/** Binary transfer limits. Editing keeps its own 512 KiB UTF-8 ceiling. */
|
|
291
|
+
const MAX_UPLOAD_FILE_BYTES = 26214400;
|
|
292
|
+
const MAX_DOWNLOAD_FILE_BYTES = 67108864;
|
|
293
|
+
/** Text bodies at or below this size are scanned for saved credentials. */
|
|
294
|
+
const MAX_CREDENTIAL_SCAN_BYTES = 1048576;
|
|
295
|
+
/**
|
|
296
|
+
* Raw byte transfers take the same scope + relative path shape as reads, but
|
|
297
|
+
* never negotiate an editor version in the query: overwrites carry it in
|
|
298
|
+
* `If-Match` so a plain download URL stays idempotent.
|
|
299
|
+
*/
|
|
300
|
+
const FileRawQuerySchema = z.union([
|
|
301
|
+
z.object({
|
|
302
|
+
workspace: z.literal("default"),
|
|
303
|
+
path: FilePathSchema
|
|
304
|
+
}).strict(),
|
|
305
|
+
z.object({
|
|
306
|
+
projectId: resourceId,
|
|
307
|
+
path: FilePathSchema
|
|
308
|
+
}).strict(),
|
|
309
|
+
z.object({
|
|
310
|
+
sessionId: resourceId,
|
|
311
|
+
path: FilePathSchema
|
|
312
|
+
}).strict()
|
|
313
|
+
]);
|
|
314
|
+
const FileUploadResultSchema = z.object({
|
|
315
|
+
path: FilePathSchema,
|
|
316
|
+
realPath: z.string(),
|
|
317
|
+
version: FileVersionSchema,
|
|
318
|
+
size: z.number().int().nonnegative(),
|
|
319
|
+
created: z.boolean(),
|
|
320
|
+
previousVersion: FileVersionSchema.optional()
|
|
321
|
+
});
|
|
290
322
|
const FileSaveSchema = z.object({
|
|
291
323
|
scope: FileScopeSchema,
|
|
292
324
|
path: FilePathSchema,
|
|
@@ -1198,6 +1230,15 @@ const GitDiffQuerySchema = z.object({
|
|
|
1198
1230
|
path: z.string().min(1).max(4096),
|
|
1199
1231
|
staged: z.enum(["true", "false"]).default("false")
|
|
1200
1232
|
}).strict();
|
|
1233
|
+
const GitCommitHashSchema = z.string().regex(/^(?:[a-f0-9]{40}|[a-f0-9]{64})$/, "Invalid Git commit hash");
|
|
1234
|
+
const GitCommitParamsSchema = z.object({
|
|
1235
|
+
id: z.string().min(1).max(128),
|
|
1236
|
+
hash: GitCommitHashSchema
|
|
1237
|
+
}).strict();
|
|
1238
|
+
const GitCommitDiffQuerySchema = z.object({
|
|
1239
|
+
path: z.string().min(1).max(4096),
|
|
1240
|
+
origPath: z.string().min(1).max(4096).optional()
|
|
1241
|
+
}).strict();
|
|
1201
1242
|
const GitLogQuerySchema = z.object({
|
|
1202
1243
|
limit: z.coerce.number().int().min(1).max(100).default(50),
|
|
1203
1244
|
cursor: z.coerce.number().int().nonnegative().default(0)
|
|
@@ -1206,6 +1247,34 @@ const GitBranchesQuerySchema = z.object({
|
|
|
1206
1247
|
limit: z.coerce.number().int().min(1).max(200).default(100),
|
|
1207
1248
|
cursor: z.coerce.number().int().nonnegative().default(0)
|
|
1208
1249
|
}).strict();
|
|
1250
|
+
// ../../packages/shared/src/input.ts
|
|
1251
|
+
/**
|
|
1252
|
+
* Model-facing input for `ask_user`. The model never supplies an index or an
|
|
1253
|
+
* "Other" option: the server assigns indices in order and every client adds the
|
|
1254
|
+
* free-text row itself.
|
|
1255
|
+
*/
|
|
1256
|
+
const AskUserOptionSchema = z.object({
|
|
1257
|
+
label: z.string().trim().min(1).max(60),
|
|
1258
|
+
description: z.string().trim().max(200).optional()
|
|
1259
|
+
}).strict();
|
|
1260
|
+
const AskUserQuestionSchema = z.object({
|
|
1261
|
+
header: z.string().trim().min(1).max(30),
|
|
1262
|
+
question: z.string().trim().min(1).max(500),
|
|
1263
|
+
options: z.array(AskUserOptionSchema).min(2).max(5).optional(),
|
|
1264
|
+
multiple: z.boolean().optional()
|
|
1265
|
+
}).strict();
|
|
1266
|
+
const AskUserParamsSchema = z.object({ questions: z.array(AskUserQuestionSchema).min(1).max(4) }).strict();
|
|
1267
|
+
AskUserQuestionSchema.extend({ index: z.number().int().min(0).max(3) }).strict();
|
|
1268
|
+
const InputAnswerSchema = z.object({
|
|
1269
|
+
questionIndex: z.number().int().min(0).max(3),
|
|
1270
|
+
selected: z.array(z.string().max(60)).max(5),
|
|
1271
|
+
other: z.string().trim().max(2e3).optional()
|
|
1272
|
+
}).strict();
|
|
1273
|
+
const InputAnswersSchema = z.array(InputAnswerSchema).max(4);
|
|
1274
|
+
const INPUT_MAX_ANSWERS_BYTES = 32768;
|
|
1275
|
+
const INPUT_MAX_QUESTIONS_BYTES = 32768;
|
|
1276
|
+
const DEFAULT_INPUT_TTL_MS = 3e5;
|
|
1277
|
+
const MAX_INPUT_TTL_MS = 9e5;
|
|
1209
1278
|
z.enum(["script", "agent"]);
|
|
1210
1279
|
const ScheduledJobMissedPolicySchema = z.enum(["skip", "run_once"]);
|
|
1211
1280
|
const ScheduledJobApprovalPolicySchema = z.enum(["readonly", "autonomous"]);
|
|
@@ -1896,6 +1965,7 @@ var schema_exports = /* @__PURE__ */ __exportAll({
|
|
|
1896
1965
|
deploymentTargets: () => deploymentTargets,
|
|
1897
1966
|
deviceRequests: () => deviceRequests,
|
|
1898
1967
|
fileVersions: () => fileVersions,
|
|
1968
|
+
inputRequests: () => inputRequests,
|
|
1899
1969
|
memories: () => memories,
|
|
1900
1970
|
memoryRevisions: () => memoryRevisions,
|
|
1901
1971
|
memorySuppressions: () => memorySuppressions,
|
|
@@ -2061,6 +2131,24 @@ const approvals = sqliteTable("approvals", {
|
|
|
2061
2131
|
decidedBy: text("decided_by"),
|
|
2062
2132
|
createdAt: integer("created_at").notNull()
|
|
2063
2133
|
}, (table) => [index("idx_approvals_turn_status").on(table.turnId, table.status), index("idx_approvals_expiry").on(table.expiresAt)]);
|
|
2134
|
+
const inputRequests = sqliteTable("input_requests", {
|
|
2135
|
+
id: text("id").primaryKey(),
|
|
2136
|
+
turnId: text("turn_id").notNull().references(() => turns.id, { onDelete: "cascade" }),
|
|
2137
|
+
sessionId: text("session_id").notNull().references(() => sessions.id, { onDelete: "cascade" }),
|
|
2138
|
+
toolCallId: text("tool_call_id").notNull(),
|
|
2139
|
+
kind: text("kind").$type().notNull().default("question"),
|
|
2140
|
+
status: text("status").$type().notNull().default("pending"),
|
|
2141
|
+
questionsJson: text("questions_json").notNull(),
|
|
2142
|
+
answersJson: text("answers_json"),
|
|
2143
|
+
expiresAt: integer("expires_at").notNull(),
|
|
2144
|
+
resolvedAt: integer("resolved_at"),
|
|
2145
|
+
resolvedBy: text("resolved_by"),
|
|
2146
|
+
createdAt: integer("created_at").notNull()
|
|
2147
|
+
}, (table) => [
|
|
2148
|
+
index("idx_input_requests_turn_status").on(table.turnId, table.status),
|
|
2149
|
+
index("idx_input_requests_session_status").on(table.sessionId, table.status),
|
|
2150
|
+
index("idx_input_requests_expiry").on(table.expiresAt)
|
|
2151
|
+
]);
|
|
2064
2152
|
const resourceLocks = sqliteTable("resource_locks", {
|
|
2065
2153
|
id: text("id").primaryKey(),
|
|
2066
2154
|
resourceType: text("resource_type").$type().notNull(),
|
|
@@ -3062,4 +3150,4 @@ function inspectPendingInitialization(file) {
|
|
|
3062
3150
|
sqlite.close();
|
|
3063
3151
|
}
|
|
3064
3152
|
}
|
|
3065
|
-
export {
|
|
3153
|
+
export { secrets as $, normalizeCommandRequest as $n, DEFAULT_INPUT_TTL_MS as $t, deploymentAuthorizations as A, DeploymentTargetRefSchema as An, TerminalInputSchema as At, modelCatalogCache as B, deriveWebAuthn as Bn, ProcessIdSchema as Bt, auditLogs as C, DeploymentAuthorizationContextSchema as Cn, ServiceRegisterInputSchema as Ct, credentialProfiles as D, DeploymentSpecSchema as Dn, TerminalCreateSchema as Dt, commandExecutions as E, DeploymentSourceSchema as En, TERMINAL_LEASE_TTL_MS as Et, fileVersions as F, ServiceOpsSubscriptionSchema as Fn, TerminalResizeSchema as Ft, resourceActions as G, CommandOutputChunkSchema as Gn, MemoryKeySchema as Gt, modelProfiles as H, COMMAND_RETENTION_MS as Hn, ProcessStatusSchema as Ht, inputRequests as I, hasControlCharacters as In, TerminalSubscriptionSchema as It, resourceOperations as J, CommandRequestSchema as Jn, ReadMemoryInputSchema as Jt, resourceEvents as K, CommandOutputQuerySchema as Kn, MemoryKindSchema as Kt, memories as L, AppConfigSchema as Ln, TerminalTakeoverSchema as Lt, deploymentPlans as M, ServiceActionScopeSchema as Mn, TerminalOutputChunkSchema as Mt, deploymentTargets as N, ServiceControlInputSchema as Nn, TerminalPayloadSchema as Nt, deploymentApprovals as O, DeploymentTargetIdSchema as On, TerminalDevSchema as Ot, deviceRequests as P, ServiceOpsEventPayloadSchema as Pn, TerminalRenameSchema as Pt, schema_exports as Q, ShellCommandParamsSchema as Qn, AskUserParamsSchema as Qt, memoryRevisions as R, DEFAULT_APP_CONFIG as Rn, PROCESS_OUTPUT_MAX_BYTES as Rt, approvals as S, DeploymentArtifactManifestSchema as Sn, ServiceIdSchema as St, browserSessions as T, DeploymentPlanDocumentSchema as Tn, ServiceSubscriptionSchema as Tt, modelVisibility as U, CommandCancelSchema as Un, StartProcessParamsSchema as Ut, modelDefaults as V, COMMAND_OUTPUT_RETENTION_MS as Vn, ProcessOutputQuerySchema as Vt, projects as W, CommandIdSchema as Wn, PlanParamsSchema as Wt, scheduledJobRuns as X, CommandSubscriptionSchema as Xn, ScheduledJobInputSchema as Xt, resourceStreams as Y, CommandStatusPayloadSchema as Yn, RememberToolInputSchema as Yt, scheduledJobs as Z, MAX_COMMAND_TIMEOUT_MS as Zn, ScheduledJobPatchSchema as Zt, setMeta as _, DEPLOYMENT_ARTIFACT_MAX_BYTES as _n, isAcceptedAttachmentName as _r, FileStreamIdSchema as _t, isProcessAlive as a, GitActionSchema as an, FileReadQuerySchema as ar, sessionContextSummaries as at, WEB_SEARCH_REGIONS as b, DEPLOYMENT_BUILD_LOG_MAX_BYTES as bn, isSourceViewMime as br, ResourceEventsQuerySchema as bt, configFilePath as c, GitCommitParamsSchema as cn, FileSaveSchema as cr, terminals as ct, appliedMigrationCount as d, GitRemoteActionRequestSchema as dn, FileUploadResultSchema as dr, webSearchConnections as dt, INPUT_MAX_ANSWERS_BYTES as en, FileActionResultSchema as er, serviceActionAuthorizations as et, expectedMigrationCount as f, WORKSPACE_JOBS_CHANGED as fn, FileVersionSchema as fr, webauthnChallenges as ft, getMeta as g, DEPLOYMENT_APPROVAL_TTL_MS as gn, MAX_UPLOAD_FILE_BYTES as gr, FileResyncPayloadSchema as gt, ensureInstanceId as h, DEFAULT_PROJECT_ID as hn, MAX_EDITABLE_FILE_BYTES as hr, FileChangedPayloadSchema as ht, inspectInstanceLock as i, GitActionDecisionSchema as in, FileRawQuerySchema as ir, sessionAttachments as it, deploymentBuilds as j, ServiceActionAuthorizationDtoSchema as jn, TerminalLeaseSchema as jt, deploymentArtifacts as k, DeploymentTargetNameSchema as kn, TerminalIdSchema as kt, loadConfig as l, GitDiffQuerySchema as ln, FileScopeSchema as lr, trustedDevices as lt, runMigrations as m, WORKSPACE_SESSIONS_CHANGED as mn, MAX_DOWNLOAD_FILE_BYTES as mr, newId as mt, inspectPendingInitialization as n, InputAnswersSchema as nn, FileListQuerySchema as nr, serviceOpsServices as nt, releaseInstanceLock as o, GitBranchesQuerySchema as on, FileResultTargetSchema as or, sessions as ot, findServerRoot as p, WORKSPACE_MEMORY_CHANGED as pn, MAX_CREDENTIAL_SCAN_BYTES as pr, webauthnCredentials as pt, resourceLocks as q, CommandParamsSchema as qn, MemoryStatusSchema as qt, acquireInstanceLock as r, MAX_INPUT_TTL_MS as rn, FilePathSchema as rr, services as rt, recoverInitialization as s, GitCommitDiffQuerySchema as sn, FileSaveResultSchema as sr, terminalLeases as st, inspectDatabase as t, INPUT_MAX_QUESTIONS_BYTES as tn, FileActionSchema as tr, serviceOpsDeployments as tt, resolveConfig as u, GitLogQuerySchema as un, FileSearchQuerySchema as ur, turns as ut, MODEL_PROVIDER_IDS as v, DEPLOYMENT_ARTIFACT_MAX_FILES as vn, isBlockedAttachmentName as vr, FileSubscriptionSchema as vt, authSettings as w, DeploymentAuthorizationScopeSchema as wn, ServiceStatusSchema as wt, agentEvents as x, DEPLOYMENT_PLAN_TTL_MS as xn, ServiceEventPayloadSchema as xt, WEB_SEARCH_PROVIDER_IDS as y, DEPLOYMENT_ARTIFACT_MAX_PATH as yn, isSecretAttachmentName as yr, RESOURCE_EVENT_RETENTION_MS as yt, memorySuppressions as z, OriginUrlSchema as zn, PROCESS_OUTPUT_MAX_CHUNKS as zt };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { a as isProcessAlive, i as inspectInstanceLock, p as findServerRoot } from "./inspect-
|
|
2
|
-
import { t as ipcTokenPath } from "./address-
|
|
3
|
-
import { n as connectIpc } from "./client-
|
|
1
|
+
import { a as isProcessAlive, i as inspectInstanceLock, p as findServerRoot } from "./inspect-DUe_-Yma.js";
|
|
2
|
+
import { t as ipcTokenPath } from "./address-DpgJ0siq.js";
|
|
3
|
+
import { n as connectIpc } from "./client-CoxHAiNW.js";
|
|
4
4
|
import { r as resolveDataDir } from "./paths-BhVn34MT.js";
|
|
5
|
-
import { t as loadManagedConfig } from "./supervisor-
|
|
5
|
+
import { t as loadManagedConfig } from "./supervisor-BvHyiN7Z.js";
|
|
6
6
|
import { createRequire } from "node:module";
|
|
7
7
|
import { existsSync } from "node:fs";
|
|
8
8
|
import path from "node:path";
|
|
@@ -174,6 +174,9 @@ async function startCommand(io, options = {}) {
|
|
|
174
174
|
io.stdout(`[larness] server started, pid ${pid}\n`);
|
|
175
175
|
io.stdout(`[larness] web ${webUrl}\n`);
|
|
176
176
|
io.stdout(`[larness] logs ${daemonLogPath(dataDir)}\n`);
|
|
177
|
+
const { readBarrierSummary } = await import("./status.js");
|
|
178
|
+
const barriers = await readBarrierSummary(dataDir).catch(() => null);
|
|
179
|
+
if (barriers !== null && barriers.retained > 0) io.stdout(`[larness] ${barriers.retained} write barrier(s) cannot be proven orphaned; run \`larness unlock\`\n`);
|
|
177
180
|
return 0;
|
|
178
181
|
}
|
|
179
182
|
async function stopCommand(io) {
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { zn as OriginUrlSchema } from "./inspect-DUe_-Yma.js";
|
|
2
|
+
import { existsSync, readFileSync, realpathSync } from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
import { tmpdir } from "node:os";
|
|
6
|
+
// src/dev-web/paths.ts
|
|
7
|
+
const Manifest = z.object({
|
|
8
|
+
dependencies: z.record(z.string(), z.string()).optional(),
|
|
9
|
+
optionalDependencies: z.record(z.string(), z.string()).optional(),
|
|
10
|
+
peerDependencies: z.record(z.string(), z.string()).optional()
|
|
11
|
+
});
|
|
12
|
+
const contains = (root, file) => file === root || file.startsWith(root + path.sep);
|
|
13
|
+
function webRoots(webRoot) {
|
|
14
|
+
const roots = /* @__PURE__ */ new Set();
|
|
15
|
+
const visit = (directory) => {
|
|
16
|
+
if (!existsSync(directory)) return;
|
|
17
|
+
const root = realpathSync(directory);
|
|
18
|
+
if (roots.has(root)) return;
|
|
19
|
+
roots.add(root);
|
|
20
|
+
const manifestPath = path.join(root, "package.json");
|
|
21
|
+
if (!existsSync(manifestPath)) return;
|
|
22
|
+
const pkg = Manifest.parse(JSON.parse(readFileSync(manifestPath, "utf8")));
|
|
23
|
+
for (const name of Object.keys({
|
|
24
|
+
...pkg.dependencies,
|
|
25
|
+
...pkg.optionalDependencies,
|
|
26
|
+
...pkg.peerDependencies
|
|
27
|
+
})) {
|
|
28
|
+
let base = root;
|
|
29
|
+
for (;;) {
|
|
30
|
+
const candidate = path.join(base, "node_modules", name);
|
|
31
|
+
if (existsSync(candidate)) {
|
|
32
|
+
visit(candidate);
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
const parent = path.dirname(base);
|
|
36
|
+
if (parent === base) break;
|
|
37
|
+
base = parent;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
visit(webRoot);
|
|
42
|
+
visit(path.resolve(webRoot, "../../packages/ui"));
|
|
43
|
+
visit(path.resolve(webRoot, "../../packages/shared"));
|
|
44
|
+
visit(path.join(webRoot, "node_modules/vite"));
|
|
45
|
+
return [...roots];
|
|
46
|
+
}
|
|
47
|
+
function isDevPath(pathname) {
|
|
48
|
+
return /^\/(?:@vite(?:\/|$)|@react-refresh(?:\/|$)|@fs(?:\/|$)|@id(?:\/|$)|src(?:\/|$)|node_modules(?:\/|$)|__vite|__open-in-editor|_larness(?:\/|$))/.test(pathname);
|
|
49
|
+
}
|
|
50
|
+
function permittedPath(rawUrl, webRoot, roots) {
|
|
51
|
+
try {
|
|
52
|
+
const rawPath = rawUrl.split("?")[0] ?? "";
|
|
53
|
+
const decoded = decodeURIComponent(rawPath);
|
|
54
|
+
if (!decoded.startsWith("/") || decoded.startsWith("//") || decoded.includes("%") || decoded.includes("\\") || decoded.includes("\0")) return false;
|
|
55
|
+
if (decoded.split("/").some((s) => s === ".." || s === "." || s.startsWith(".env") || s === ".git" || /^(?:config\.json|master\.key|larness\.(?:db|lock)|vite\.config\..*|.*\.log)$/.test(s))) return false;
|
|
56
|
+
if (/^\/(?:api|ws|_larness)(?:\/|$)/.test(decoded) || decoded.startsWith("/__open-in-editor") || decoded.startsWith("/__vite")) return false;
|
|
57
|
+
const file = decoded.startsWith("/@fs/") ? path.normalize(decoded.slice(process.platform === "win32" ? 5 : 4)) : path.join(webRoot, decoded);
|
|
58
|
+
if (existsSync(file)) return roots.some((root) => contains(realpathSync(root), realpathSync(file)));
|
|
59
|
+
let ancestor = file;
|
|
60
|
+
while (!existsSync(ancestor)) {
|
|
61
|
+
const parent = path.dirname(ancestor);
|
|
62
|
+
if (parent === ancestor) return false;
|
|
63
|
+
ancestor = parent;
|
|
64
|
+
}
|
|
65
|
+
return roots.some((root) => contains(realpathSync(root), realpathSync(ancestor)));
|
|
66
|
+
} catch {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
// src/dev-web/control.ts
|
|
71
|
+
const HMR_PATH = "/_larness/dev/hmr";
|
|
72
|
+
const NONCE_MARKER = "LARNESS_DEV_RESPONSE_NONCE";
|
|
73
|
+
var DevWebUnavailable = class extends Error {
|
|
74
|
+
code = "DEV_WEB_UNAVAILABLE";
|
|
75
|
+
constructor() {
|
|
76
|
+
super("开发运行环境已停止,请重新启动 TUI");
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
var EntryConfigError = class extends Error {
|
|
80
|
+
constructor(origin, port) {
|
|
81
|
+
const canonical = new URL(OriginUrlSchema.parse(origin));
|
|
82
|
+
const targetPort = Number(canonical.port || (canonical.protocol === "https:" ? 443 : 80));
|
|
83
|
+
super(`浏览器地址是 ${canonical.origin},Server 监听端口是 ${port}。请关闭实例,一次性将 config.json 的 server.port 对齐为 ${targetPort},保留 publicUrl 和其他配置;若端口来自环境变量,请调整对应环境变量。`);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
const devWebCache = (generation) => path.join(tmpdir(), `larness-vite-cache-${z.uuid().parse(generation)}`);
|
|
87
|
+
const DevWebTargetSchema = z.strictObject({
|
|
88
|
+
generation: z.uuid(),
|
|
89
|
+
host: z.literal("127.0.0.1"),
|
|
90
|
+
port: z.int().min(1).max(65535)
|
|
91
|
+
});
|
|
92
|
+
const DevWebReadySchema = DevWebTargetSchema.extend({ type: z.literal("dev-web.ready") });
|
|
93
|
+
const DevWebAttachSchema = DevWebTargetSchema.extend({ type: z.literal("dev-web.attach") });
|
|
94
|
+
const DevWebAttachedSchema = z.strictObject({
|
|
95
|
+
type: z.literal("dev-web.attached"),
|
|
96
|
+
generation: z.uuid()
|
|
97
|
+
});
|
|
98
|
+
z.strictObject({
|
|
99
|
+
type: z.literal("dev-web.start"),
|
|
100
|
+
generation: z.uuid(),
|
|
101
|
+
origin: OriginUrlSchema
|
|
102
|
+
});
|
|
103
|
+
var DevWebControl = class {
|
|
104
|
+
child;
|
|
105
|
+
generation;
|
|
106
|
+
current = null;
|
|
107
|
+
closed = false;
|
|
108
|
+
constructor(child, generation) {
|
|
109
|
+
this.child = child;
|
|
110
|
+
this.generation = generation;
|
|
111
|
+
}
|
|
112
|
+
get target() {
|
|
113
|
+
return this.current;
|
|
114
|
+
}
|
|
115
|
+
accept(child, message) {
|
|
116
|
+
const parsed = DevWebReadySchema.safeParse(message);
|
|
117
|
+
if (this.closed || child !== this.child || !parsed.success || parsed.data.generation !== this.generation) return false;
|
|
118
|
+
const { type: _type, ...target } = parsed.data;
|
|
119
|
+
if (this.current && this.current.port !== target.port) return false;
|
|
120
|
+
this.current = target;
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
close() {
|
|
124
|
+
this.closed = true;
|
|
125
|
+
this.current = null;
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
// src/dev-web/managed.ts
|
|
129
|
+
function managedWebFiles(serverRoot, target) {
|
|
130
|
+
const webRoot = realpathSync(path.resolve(serverRoot, "../../apps/web"));
|
|
131
|
+
return {
|
|
132
|
+
webRoot,
|
|
133
|
+
roots: [...webRoots(webRoot), realpathSync(devWebCache(target.generation))]
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
function receiveDevWebTarget(timeoutMs = 25e3, signal) {
|
|
137
|
+
if (!process.send) return Promise.reject(/* @__PURE__ */ new Error("开发转发需要受管控制通道"));
|
|
138
|
+
return new Promise((resolve, reject) => {
|
|
139
|
+
const timer = setTimeout(() => finish(/* @__PURE__ */ new Error("开发控制通道超时")), timeoutMs);
|
|
140
|
+
const disconnect = () => finish(/* @__PURE__ */ new Error("开发控制通道已关闭"));
|
|
141
|
+
const abort = () => finish(/* @__PURE__ */ new Error("启动已取消"));
|
|
142
|
+
const message = (value) => {
|
|
143
|
+
const parsed = DevWebAttachSchema.safeParse(value);
|
|
144
|
+
if (!parsed.success) {
|
|
145
|
+
finish(/* @__PURE__ */ new Error("开发控制消息无效"));
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
const { type: _type, ...target } = parsed.data;
|
|
149
|
+
finish(null, target);
|
|
150
|
+
};
|
|
151
|
+
const finish = (error, target) => {
|
|
152
|
+
clearTimeout(timer);
|
|
153
|
+
process.off("message", message);
|
|
154
|
+
process.off("disconnect", disconnect);
|
|
155
|
+
signal?.removeEventListener("abort", abort);
|
|
156
|
+
if (error) reject(error);
|
|
157
|
+
else if (target) resolve(target);
|
|
158
|
+
};
|
|
159
|
+
process.once("message", message);
|
|
160
|
+
process.once("disconnect", disconnect);
|
|
161
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
162
|
+
if (signal?.aborted) abort();
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
function waitChildMessage(child, parse, signal, phase = "Server") {
|
|
166
|
+
return new Promise((resolve, reject) => {
|
|
167
|
+
const timer = setTimeout(() => finish(/* @__PURE__ */ new Error("开发子进程就绪超时")), 25e3);
|
|
168
|
+
const fail = () => finish(/* @__PURE__ */ new Error(`${phase} 未就绪即退出 (code=${child.exitCode ?? "none"}, signal=${child.signalCode ?? "none"})`));
|
|
169
|
+
const abort = () => finish(/* @__PURE__ */ new Error("启动已取消"));
|
|
170
|
+
const message = (value) => {
|
|
171
|
+
const parsed = parse(value);
|
|
172
|
+
if (parsed === null) finish(/* @__PURE__ */ new Error("开发子进程控制消息无效"));
|
|
173
|
+
else finish(null, parsed);
|
|
174
|
+
};
|
|
175
|
+
const finish = (error, value) => {
|
|
176
|
+
clearTimeout(timer);
|
|
177
|
+
child.off("message", message);
|
|
178
|
+
child.off("exit", fail);
|
|
179
|
+
child.off("error", fail);
|
|
180
|
+
signal?.removeEventListener("abort", abort);
|
|
181
|
+
if (error) reject(error);
|
|
182
|
+
else if (value !== void 0) resolve(value);
|
|
183
|
+
};
|
|
184
|
+
child.on("message", message);
|
|
185
|
+
child.once("exit", fail);
|
|
186
|
+
child.once("error", fail);
|
|
187
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
188
|
+
if (signal?.aborted) abort();
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
export { DevWebControl as a, EntryConfigError as c, devWebCache as d, isDevPath as f, DevWebAttachedSchema as i, HMR_PATH as l, receiveDevWebTarget as n, DevWebTargetSchema as o, permittedPath as p, waitChildMessage as r, DevWebUnavailable as s, managedWebFiles as t, NONCE_MARKER as u };
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { n as connectIpc } from "./client-CoxHAiNW.js";
|
|
2
|
+
import { r as inspectBarriersFile, t as collectStatus } from "./status-C0hriYPD.js";
|
|
3
|
+
import { r as resolveDataDir } from "./paths-BhVn34MT.js";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
// src/cli/status.ts
|
|
7
|
+
/**
|
|
8
|
+
* Merges the live IPC snapshot over the local report. A server started before
|
|
9
|
+
* this CLI version does not send the newer fields, so fall back per field
|
|
10
|
+
* instead of formatting an incomplete object.
|
|
11
|
+
*/
|
|
12
|
+
function completeStatus(remote, fallback) {
|
|
13
|
+
const defined = Object.fromEntries(Object.entries(remote).filter(([, value]) => value !== void 0));
|
|
14
|
+
const merged = {
|
|
15
|
+
...fallback,
|
|
16
|
+
...defined
|
|
17
|
+
};
|
|
18
|
+
return {
|
|
19
|
+
...merged,
|
|
20
|
+
warnings: merged.warnings.filter((warning) => !(merged.running && warning === "server is not running"))
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Barrier classification stays in the CLI: `system.status` must not spawn `ps`
|
|
25
|
+
* on every poll, and the read-only inspector works whether or not the server is
|
|
26
|
+
* running.
|
|
27
|
+
*/
|
|
28
|
+
async function readBarrierSummary(dataDir) {
|
|
29
|
+
const audit = await inspectBarriersFile(path.join(dataDir, "larness.db"));
|
|
30
|
+
if (audit === null) return null;
|
|
31
|
+
const items = [...audit.operations.map((operation) => ({
|
|
32
|
+
id: operation.id,
|
|
33
|
+
type: "operation",
|
|
34
|
+
kind: operation.kind,
|
|
35
|
+
status: operation.status,
|
|
36
|
+
reason: operation.reason,
|
|
37
|
+
pid: operation.pid,
|
|
38
|
+
rootRealPath: operation.rootRealPath
|
|
39
|
+
})), ...audit.locks.map((lock) => ({
|
|
40
|
+
id: lock.id,
|
|
41
|
+
type: "lock",
|
|
42
|
+
kind: `${lock.resourceType}:${lock.resourceId}`,
|
|
43
|
+
status: "LOCKED",
|
|
44
|
+
reason: lock.reason,
|
|
45
|
+
pid: null,
|
|
46
|
+
rootRealPath: lock.rootRealPath
|
|
47
|
+
}))];
|
|
48
|
+
return {
|
|
49
|
+
items,
|
|
50
|
+
retained: items.filter((item) => item.reason !== "settleable").length,
|
|
51
|
+
settleable: items.filter((item) => item.reason === "settleable").length
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
async function readStatus(options = {}) {
|
|
55
|
+
const dataDir = options.dataDir ?? resolveDataDir(options.env ?? process.env);
|
|
56
|
+
const barriers = await readBarrierSummary(dataDir).catch(() => null);
|
|
57
|
+
const withBarriers = (report) => barriers === null ? report : {
|
|
58
|
+
...report,
|
|
59
|
+
resourceBarriers: barriers
|
|
60
|
+
};
|
|
61
|
+
try {
|
|
62
|
+
const client = await connectIpc({
|
|
63
|
+
dataDir,
|
|
64
|
+
client: "status",
|
|
65
|
+
timeoutMs: 1500
|
|
66
|
+
});
|
|
67
|
+
try {
|
|
68
|
+
return withBarriers(completeStatus(await client.request("system.status", {}, 1500), await collectStatus({
|
|
69
|
+
dataDir,
|
|
70
|
+
...options.env === void 0 ? {} : { env: options.env }
|
|
71
|
+
})));
|
|
72
|
+
} finally {
|
|
73
|
+
client.close();
|
|
74
|
+
}
|
|
75
|
+
} catch {
|
|
76
|
+
return withBarriers(await collectStatus({
|
|
77
|
+
dataDir,
|
|
78
|
+
...options.env === void 0 ? {} : { env: options.env }
|
|
79
|
+
}));
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
function isEntryPoint() {
|
|
83
|
+
const entry = process.argv[1];
|
|
84
|
+
return entry !== void 0 && path.resolve(entry) === fileURLToPath(import.meta.url);
|
|
85
|
+
}
|
|
86
|
+
if (isEntryPoint()) try {
|
|
87
|
+
const status = await readStatus();
|
|
88
|
+
process.stdout.write(`${JSON.stringify(status, null, 2)}\n`);
|
|
89
|
+
} catch (error) {
|
|
90
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
91
|
+
process.stderr.write(`[larness] status failed: ${message}\n`);
|
|
92
|
+
process.exitCode = 1;
|
|
93
|
+
}
|
|
94
|
+
export { readBarrierSummary as n, readStatus as r, completeStatus as t };
|