@usepowerplant/cli 0.4.40 → 0.4.41

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/main.js CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="68f444bc-b4e3-5f4d-9d93-c8697eb31ccc")}catch(e){}}();
2
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="cd09de5d-96df-55f4-8e5c-09d4bc0d1006")}catch(e){}}();
3
3
  import { createRequire as __cliCreateRequire } from 'node:module';
4
4
  const require = __cliCreateRequire(import.meta.url);
5
5
  var __create = Object.create;
@@ -59676,6 +59676,26 @@ function parseTool(builder, native) {
59676
59676
  builder.events.push({ ...builder.base, source: resultSource, kind: "tool_result", callId, isError: isError2, output: bounded, launchedSubagentId: null });
59677
59677
  }
59678
59678
 
59679
+ // ../core/src/folderMapBackfill.ts
59680
+ var FOLDER_MAP_BACKFILL_PAGE_SIZE = 50;
59681
+ var identity = { harness: external_exports.enum(COLLECTOR_SESSION_HARNESSES), harnessSessionId: external_exports.string().min(1).max(500) };
59682
+ var folderMapGapsPageSchema = external_exports.object({
59683
+ sessions: external_exports.array(external_exports.object({ ...identity, orgId: external_exports.uuid(), startedAt: external_exports.iso.datetime({ offset: true }).nullable() })).max(FOLDER_MAP_BACKFILL_PAGE_SIZE),
59684
+ next: external_exports.string().min(1).max(200).nullable()
59685
+ });
59686
+ var folderMapUploadSchema = external_exports.object({
59687
+ destinationOrgId: external_exports.uuid(),
59688
+ sessions: external_exports.array(external_exports.object({ ...identity, folderMap: external_exports.unknown() })).min(1).max(FOLDER_MAP_BACKFILL_PAGE_SIZE)
59689
+ });
59690
+ var folderMapUploadResultSchema = external_exports.object({
59691
+ /** Maps given to the folder map writer: sessions this machine uploaded to the destination workspace. */
59692
+ recorded: external_exports.number().int().min(0),
59693
+ /** Maps parseFolderMap refused. */
59694
+ invalid: external_exports.number().int().min(0),
59695
+ /** The destination workspace is locked for billing, so nothing was recorded. */
59696
+ paused: external_exports.boolean()
59697
+ });
59698
+
59679
59699
  // ../core/src/cursorRunRedaction.ts
59680
59700
  var REDACTED2 = "[REDACTED]";
59681
59701
  var SECRET_REST = /^[^\s\\"',;]+/;
@@ -87673,7 +87693,7 @@ function _init2(options = {}, getDefaultIntegrationsImpl) {
87673
87693
  import tls2 from "node:tls";
87674
87694
  var import_undici = __toESM(require_undici(), 1);
87675
87695
  var CLI_VERSION_HEADER = "x-powerplant-cli-version";
87676
- var cliVersion = true ? "0.4.40" : "0.0.0-checkout";
87696
+ var cliVersion = true ? "0.4.41" : "0.0.0-checkout";
87677
87697
  function cliVersionHeaders() {
87678
87698
  return { [CLI_VERSION_HEADER]: cliVersion, "user-agent": `powerplant-cli/${cliVersion}` };
87679
87699
  }
@@ -87864,11 +87884,11 @@ var fetchTransport = (options) => createTransport(
87864
87884
  })
87865
87885
  );
87866
87886
  var reportingOrgId;
87867
- function tagReportingIdentity(identity2) {
87868
- if (identity2.machineId) setTag("machine_id", identity2.machineId);
87869
- if (identity2.orgId) {
87870
- reportingOrgId = identity2.orgId;
87871
- setTag("org_id", identity2.orgId);
87887
+ function tagReportingIdentity(identity3) {
87888
+ if (identity3.machineId) setTag("machine_id", identity3.machineId);
87889
+ if (identity3.orgId) {
87890
+ reportingOrgId = identity3.orgId;
87891
+ setTag("org_id", identity3.orgId);
87872
87892
  setTag("is_test_workspace", void 0);
87873
87893
  }
87874
87894
  }
@@ -89506,10 +89526,19 @@ function workspaceRepoTest(capture2, sessionRepo, captureRepoFullNames) {
89506
89526
  const own2 = sessionRepo === void 0 ? null : canonicalRepoFullName(sessionRepo);
89507
89527
  if (own2 === null) return () => false;
89508
89528
  if (capture2.mode !== "org-repos") return (repoFullName) => ownerOf(repoFullName) === ownerOf(own2);
89509
- const claims = capture2.workspaceClaims ?? [{ owners: capture2.allowedOwners, repos: capture2.allowedRepos }];
89510
- const routed = claims.filter((claim2) => (captureRepoFullNames ?? [own2]).every((repo) => workspaceClaimsRepo(repo, claim2)));
89529
+ const routed = routedClaims(capture2, captureRepoFullNames ?? [own2]);
89511
89530
  return (repoFullName) => repoFullName === own2 || routed.length > 0 && routed.every((claim2) => workspaceClaimsRepo(repoFullName, claim2));
89512
89531
  }
89532
+ function routedClaims(capture2, repos) {
89533
+ const claims = capture2.workspaceClaims ?? [{ owners: capture2.allowedOwners, repos: capture2.allowedRepos }];
89534
+ return claims.filter((claim2) => repos.every((repo) => workspaceClaimsRepo(repo, claim2)));
89535
+ }
89536
+ function mapMayGoTo(capture2, session, orgId) {
89537
+ const own2 = session.repoFullName === void 0 ? null : canonicalRepoFullName(session.repoFullName);
89538
+ if (capture2.mode !== "org-repos" || own2 === null) return true;
89539
+ const routed = routedClaims(capture2, session.captureRepoFullNames ?? [own2]);
89540
+ return routed.length === 0 || routed.some((claim2) => claim2.orgId === orgId);
89541
+ }
89513
89542
  var ownerOf = (repoFullName) => repoFullName.split("/", 1)[0];
89514
89543
  function folderMapper(capture2, skips) {
89515
89544
  const prober = checkoutProber(capture2.environment);
@@ -89555,7 +89584,9 @@ function sessionFoldersOf(folders, prober, isWorkspaceRepo, homeDir = os5.homedi
89555
89584
  }
89556
89585
  const unnamedAdditional = !working && (probe.kind === "github" && !isWorkspaceRepo(probe.repoFullName) || probe.kind === "unreadable");
89557
89586
  if (!unnamedAdditional && probe.kind !== "no-checkout" && (probe.kind !== "github" || !isWorkspaceRepo(probe.repoFullName))) continue;
89558
- const rootFolder = rootFolderOf(folder, homeDir, platform2);
89587
+ const mapRoot = probe.kind === "no-checkout" || unnamedAdditional ? folder : mapRootOf(folder, prober, homeDir, platform2);
89588
+ const base = mapRoot ?? folder;
89589
+ const rootFolder = rootFolderOf(base, homeDir, platform2);
89559
89590
  const unmapped = redactText(rootFolder) !== rootFolder || rootFolder.length > MAX_FOLDER_MAP_PATH_LENGTH || platform2 !== "win32" && rootFolder.includes("\\");
89560
89591
  const duplicate = roots.some((root) => platform2 === "win32" ? root.folder.toLowerCase() === rootFolder.toLowerCase() : root.folder === rootFolder);
89561
89592
  if (roots.length >= MAX_FOLDER_MAP_ROOTS || unmapped || duplicate) continue;
@@ -89573,7 +89604,7 @@ function sessionFoldersOf(folders, prober, isWorkspaceRepo, homeDir = os5.homedi
89573
89604
  };
89574
89605
  const relativeTo = (from, to) => paths.relative(from, to).split(paths.sep).join("/") || ".";
89575
89606
  const addCheckout = (checkout, probe2) => {
89576
- add(relativeTo(paths.resolve(folder), paths.resolve(checkout)), probe2);
89607
+ add(relativeTo(paths.resolve(base), paths.resolve(checkout)), probe2);
89577
89608
  const root = prober.checkoutRoot(checkout);
89578
89609
  const realCheckout = prober.realFolder(checkout);
89579
89610
  if (root === null || realCheckout === null) return;
@@ -89581,7 +89612,7 @@ function sessionFoldersOf(folders, prober, isWorkspaceRepo, homeDir = os5.homedi
89581
89612
  if (submodules === null) truncated = true;
89582
89613
  else for (const submodule of submodules) {
89583
89614
  const withinCheckout = paths.relative(realCheckout, paths.join(root, submodule.path));
89584
- add(relativeTo(paths.resolve(folder), paths.resolve(checkout, withinCheckout)), submodule.probe);
89615
+ add(relativeTo(paths.resolve(base), paths.resolve(checkout, withinCheckout)), submodule.probe);
89585
89616
  }
89586
89617
  };
89587
89618
  if (unnamedAdditional) add(".", probe);
@@ -89593,7 +89624,9 @@ function sessionFoldersOf(folders, prober, isWorkspaceRepo, homeDir = os5.homedi
89593
89624
  if (found.kind === "github" && isWorkspaceRepo(found.repoFullName)) addCheckout(checkout, found);
89594
89625
  else truncated = true;
89595
89626
  }
89596
- } else addCheckout(folder, probe);
89627
+ } else if (mapRoot === null) {
89628
+ truncated = true;
89629
+ } else addCheckout(mapRoot, probe);
89597
89630
  roots.push({ folder: rootFolder, checkouts: [...checkouts.values()].sort((a, b2) => a.path < b2.path ? -1 : 1), truncated });
89598
89631
  }
89599
89632
  const homeDirectory = platform2 === "win32" ? homeDir.replaceAll("\\", "/") : homeDir;
@@ -89603,6 +89636,20 @@ function sessionFoldersOf(folders, prober, isWorkspaceRepo, homeDir = os5.homedi
89603
89636
  ...roots.length > 0 && { folderMap: { roots, ...usesHome && redactText(homeDirectory) === homeDirectory && { homeDirectory } } }
89604
89637
  };
89605
89638
  }
89639
+ function mapRootOf(folder, prober, homeDir, platform2) {
89640
+ const root = prober.checkoutRoot(folder);
89641
+ if (root === null) return folder;
89642
+ const paths = pathRules(platform2);
89643
+ const key = (value) => platform2 === "win32" ? value.toLowerCase() : value;
89644
+ const isRoot = (candidate) => key(prober.realFolder(candidate) ?? "") === key(root);
89645
+ if (isRoot(folder)) return folder;
89646
+ const home = key(prober.realFolder(homeDir) ?? paths.resolve(homeDir));
89647
+ if (home === key(root) || home.startsWith(key(root.endsWith(paths.sep) ? root : root + paths.sep)) || paths.dirname(root) === root) return null;
89648
+ for (let candidate = paths.dirname(paths.resolve(folder)); ; candidate = paths.dirname(candidate)) {
89649
+ if (isRoot(candidate)) return candidate;
89650
+ if (paths.dirname(candidate) === candidate) return null;
89651
+ }
89652
+ }
89606
89653
  function rootFolderOf(folder, homeDir, platform2) {
89607
89654
  const sep2 = platform2 === "win32" ? path8.win32.sep : path8.posix.sep;
89608
89655
  const home = homeDir.endsWith(sep2) ? homeDir.slice(0, -1) : homeDir;
@@ -90907,6 +90954,7 @@ async function collectCodexSessions(options = {}) {
90907
90954
  const thread = threadOf(threadId2, stored);
90908
90955
  if (thread === null) return;
90909
90956
  harnessSessionId = thread.harnessSessionId;
90957
+ if (applyWindow && options.onlySessions?.({ harness: "codex-local", harnessSessionId }) === false) return;
90910
90958
  const base = thread.files[0];
90911
90959
  const first = readFirstSessionMeta(base.rolloutPath);
90912
90960
  const link = first.state === "session_meta" ? parseCodexChildThread(first.meta) : void 0;
@@ -91879,6 +91927,7 @@ function collectFromStore(db, userDir, options, result, knownIds, mapFolders) {
91879
91927
  try {
91880
91928
  if (!isRecord2(raw) || typeof raw.composerId !== "string" || raw.composerId === "") continue;
91881
91929
  knownIds.add(raw.composerId);
91930
+ if (options.onlySessions?.({ harness: "cursor-local", harnessSessionId: raw.composerId }) === false) continue;
91882
91931
  const lastUpdatedAt = typeof raw.lastUpdatedAt === "number" ? raw.lastUpdatedAt : typeof raw.createdAt === "number" ? raw.createdAt : null;
91883
91932
  if (lastUpdatedAt === null) continue;
91884
91933
  const value = typeof raw.value === "string" ? safeJsonRecord(raw.value) : null;
@@ -92217,6 +92266,7 @@ function collectCursorTranscriptFiles(options, isDatabaseSession, result, databa
92217
92266
  if (file2 !== `${createHash5("sha256").update(record2.sessionId).digest("hex")}.json`) continue;
92218
92267
  if (isDatabaseSession(record2.sessionId) || existsSync3(path12.join(databaseExtractedTranscriptsDir, extractedTranscriptFileName2(record2.sessionId))))
92219
92268
  continue;
92269
+ if (options.onlySessions?.({ harness: "cursor-local", harnessSessionId: record2.sessionId }) === false) continue;
92220
92270
  if (record2.transcriptPath === null || record2.workspaceRoots.length !== 1) continue;
92221
92271
  const cwd = record2.workspaceRoots[0];
92222
92272
  if (!path12.isAbsolute(cwd)) continue;
@@ -97246,7 +97296,10 @@ var storedCredentialsSchema = external_exports.object({
97246
97296
  claims: external_exports.array(external_exports.object({ owners: external_exports.array(external_exports.string()), repos: external_exports.array(external_exports.string()).nullable() })),
97247
97297
  folders: external_exports.array(external_exports.string()),
97248
97298
  routingPolicies: external_exports.array(external_exports.object({ orgId: external_exports.string(), owners: external_exports.array(external_exports.string()), repos: external_exports.array(external_exports.string()).nullable(), parentFolderSync: external_exports.boolean().optional() })).optional()
97249
- }).optional()
97299
+ }).optional(),
97300
+ /** The folder map backfill's place in the server's list (folderMapBackfill.ts): where it resumes and whether a page
97301
+ * left a session for a later round, or when the list ended. Absent = not started. */
97302
+ folderMapBackfill: external_exports.union([external_exports.object({ after: external_exports.string().nullable(), missed: external_exports.boolean() }), external_exports.object({ doneAt: external_exports.string() })]).optional()
97250
97303
  });
97251
97304
  var InvalidStoredCredentialsError = class extends ExpectedCliError {
97252
97305
  };
@@ -97429,14 +97482,14 @@ function openUrl(url2, onFailure, platform2 = process.platform) {
97429
97482
 
97430
97483
  // ../../apps/syncservice/src/sessionRefusals.ts
97431
97484
  var sessionIdentitySchema = external_exports.object({ source: external_exports.enum(LEGACY_COLLECTOR_SESSION_SOURCES), externalId: external_exports.string() });
97432
- function harnessIdentityOf(identity2) {
97433
- const harness = harnessFromLegacySessionSource(identity2.source);
97485
+ function harnessIdentityOf(identity3) {
97486
+ const harness = harnessFromLegacySessionSource(identity3.source);
97434
97487
  if (harness.kind !== "harness") {
97435
97488
  throw new Error("sessions ingest returned an unsupported session identity");
97436
97489
  }
97437
97490
  return {
97438
97491
  harness: external_exports.enum(COLLECTOR_SESSION_HARNESSES).parse(harness.harness),
97439
- harnessSessionId: identity2.externalId
97492
+ harnessSessionId: identity3.externalId
97440
97493
  };
97441
97494
  }
97442
97495
  var sessionRefusalSchema = external_exports.object({
@@ -97672,8 +97725,8 @@ function fallbackTitle(line) {
97672
97725
  function firstLine(text) {
97673
97726
  return text.split("\n", 1)[0].trim();
97674
97727
  }
97675
- function sessionKey(identity2) {
97676
- return JSON.stringify([identity2.harness, identity2.harnessSessionId]);
97728
+ function sessionKey(identity3) {
97729
+ return JSON.stringify([identity3.harness, identity3.harnessSessionId]);
97677
97730
  }
97678
97731
  async function collectClaudeCodeSessions(options = {}) {
97679
97732
  const claudeDir = options.claudeDir ?? path43.join(os19.homedir(), ".claude");
@@ -97701,6 +97754,7 @@ async function collectClaudeCodeSessions(options = {}) {
97701
97754
  const stat = statIfExists(transcriptPath);
97702
97755
  if (!stat) continue;
97703
97756
  const sessionId = path43.basename(entry, ".jsonl");
97757
+ if (options.onlySessions?.({ harness: "claude-local", harnessSessionId: sessionId }) === false) continue;
97704
97758
  const subagents = options.locationsOnly ? NO_SUBAGENTS : listSubagents(path43.join(projectDir, sessionId, "subagents"));
97705
97759
  const mtimeMs = Math.max(stat.mtimeMs, subagents.workflows.mtimeMs, ...subagents.files.map((file2) => file2.mtimeMs ?? 0));
97706
97760
  if (options.sinceMs !== void 0 && mtimeMs < options.sinceMs) continue;
@@ -99235,8 +99289,8 @@ var codexLocal = {
99235
99289
  hookSessionId: (externalId) => rolloutIdentity(`${externalId}.jsonl`).threadId,
99236
99290
  // A page file continues a thread whose base rollout names the session.
99237
99291
  transcriptSession(transcriptPath) {
99238
- const identity2 = rolloutIdentity(transcriptPath);
99239
- return identity2.page ? { hookId: identity2.threadId } : { externalId: path45.basename(transcriptPath, ".jsonl") };
99292
+ const identity3 = rolloutIdentity(transcriptPath);
99293
+ return identity3.page ? { hookId: identity3.threadId } : { externalId: path45.basename(transcriptPath, ".jsonl") };
99240
99294
  },
99241
99295
  // The hook records the rollout of each thread before it appends the
99242
99296
  // journal line (hookHandlers.ts).
@@ -100916,6 +100970,124 @@ function readIfExists2(p) {
100916
100970
  }
100917
100971
  }
100918
100972
 
100973
+ // ../../apps/syncservice/src/folderMapUploads.ts
100974
+ async function fetchFolderMapGaps(apiUrl, machineToken, after) {
100975
+ const url2 = new URL(`${apiUrl}/api/ingest/folder-maps/missing`);
100976
+ if (after !== null) url2.searchParams.set("after", after);
100977
+ const response = await fetchWithRetry("listing sessions without folder maps", url2.toString(), {
100978
+ headers: { authorization: `Bearer ${machineToken}` }
100979
+ });
100980
+ if (response.status === 401) throw tokenRejected("The ingest API", response);
100981
+ if (response.status === 404) {
100982
+ await response.body?.cancel();
100983
+ return "unsupported";
100984
+ }
100985
+ if (!response.ok) throw await failedResponse("folder map list failed", response);
100986
+ return parseApiResponse(external_exports.object({ data: folderMapGapsPageSchema }), await response.json().catch(() => null), "folder map list").data;
100987
+ }
100988
+ async function uploadFolderMaps(apiUrl, machineToken, upload) {
100989
+ const response = await fetchWithRetry("uploading folder maps", `${apiUrl}/api/ingest/folder-maps`, {
100990
+ method: "POST",
100991
+ headers: { authorization: `Bearer ${machineToken}`, "content-type": "application/json" },
100992
+ body: JSON.stringify(upload)
100993
+ });
100994
+ if (response.status === 401) throw tokenRejected("The ingest API", response);
100995
+ if (response.status === 404) {
100996
+ await response.body?.cancel();
100997
+ return "unsupported";
100998
+ }
100999
+ if (!response.ok) throw await failedResponse("folder map upload failed", response);
101000
+ return parseApiResponse(external_exports.object({ data: folderMapUploadResultSchema }), await response.json().catch(() => null), "folder map upload").data;
101001
+ }
101002
+
101003
+ // ../../apps/syncservice/src/folderMapBackfill.ts
101004
+ var MAX_UPLOAD_BYTES = 512 * 1024;
101005
+ var DAY_MS4 = 24 * 60 * 60 * 1e3;
101006
+ async function backfillFolderMaps(input2) {
101007
+ const { apiUrl, token, capture: capture2, progress } = input2;
101008
+ const state = progress.load();
101009
+ if ("doneAt" in state) return { kind: "done" };
101010
+ const page = await (input2.fetchGaps ?? fetchFolderMapGaps)(apiUrl, token, state.after);
101011
+ if (page === "unsupported") return { kind: "unsupported" };
101012
+ const wanted = new Set(page.sessions.map(sessionKey));
101013
+ const sinceMs = Math.min(...page.sessions.map((gap) => gap.startedAt === null ? 0 : Date.parse(gap.startedAt) - DAY_MS4));
101014
+ const collected = wanted.size === 0 ? { sessions: [], unread: false } : await (input2.collect ?? collectLocalSessions)({
101015
+ sinceMs,
101016
+ capture: capture2,
101017
+ onlySessions: (identity3) => wanted.has(sessionKey(identity3)),
101018
+ harnesses: new Set(page.sessions.map((gap) => gap.harness))
101019
+ });
101020
+ const items = new Map(collected.sessions.map((session) => [sessionKey(session.item), session.item]));
101021
+ const batches = /* @__PURE__ */ new Map();
101022
+ for (const gap of page.sessions) {
101023
+ const item = items.get(sessionKey(gap));
101024
+ if (item?.folderMap === void 0 || !mapMayGoTo(capture2, item, gap.orgId)) continue;
101025
+ batches.set(gap.orgId, [...batches.get(gap.orgId) ?? [], { harness: gap.harness, harnessSessionId: gap.harnessSessionId, folderMap: item.folderMap }]);
101026
+ }
101027
+ let mapped = 0;
101028
+ let paused = 0;
101029
+ for (const [destinationOrgId, maps] of batches) {
101030
+ for (const sessions of bySize(maps)) {
101031
+ const result = await (input2.uploadMaps ?? uploadFolderMaps)(apiUrl, token, { destinationOrgId, sessions });
101032
+ if (result === "unsupported") return { kind: "unsupported" };
101033
+ if (result.paused) paused += sessions.length;
101034
+ else mapped += result.recorded;
101035
+ }
101036
+ }
101037
+ const missed = state.missed || paused > 0 || collected.unread;
101038
+ const next = page.next !== null ? { after: page.next, missed } : missed ? { after: null, missed: false } : { doneAt: (input2.now?.() ?? /* @__PURE__ */ new Date()).toISOString() };
101039
+ progress.save(next);
101040
+ return { kind: "page", listed: page.sessions.length, mapped, paused, finished: "doneAt" in next };
101041
+ }
101042
+ async function runFolderMapBackfill(appEnv, credentials, capture2, log3, options) {
101043
+ if (!options.backfillFolderMaps || capture2.claimsUnresolved || capture2.mode === "org-repos" && capture2.workspaceClaims === void 0) return;
101044
+ try {
101045
+ const summary = await backfillFolderMaps({ apiUrl: credentials.apiUrl, token: credentials.token, capture: capture2, progress: folderMapBackfillProgress(appEnv, credentials), ...options.folderMapApi });
101046
+ const line = describeFolderMapBackfill(summary);
101047
+ if (line !== null) log3(line);
101048
+ } catch (cause) {
101049
+ log3(`\u26A0 Folder maps for older sessions skipped this pass, ${cause instanceof Error ? cause.message : String(cause)}`);
101050
+ }
101051
+ }
101052
+ function describeFolderMapBackfill(summary) {
101053
+ if (summary.kind !== "page" || summary.listed === 0) return null;
101054
+ const left = summary.listed - summary.mapped - summary.paused;
101055
+ return `Folder maps for older sessions: ${summary.mapped} sent` + (summary.paused > 0 ? `, ${summary.paused} paused for billing` : "") + (left > 0 ? `, ${left} with no map from this computer` : "") + (summary.finished ? ", done." : ".");
101056
+ }
101057
+ function folderMapBackfillProgress(appEnv, credentials) {
101058
+ return {
101059
+ load: () => credentials.folderMapBackfill ?? { after: null, missed: false },
101060
+ save: (state) => {
101061
+ const current = loadCredentials(appEnv);
101062
+ if (current === null || current.token !== credentials.token || current.enrolledAt !== credentials.enrolledAt) return;
101063
+ saveCredentials(appEnv, { ...current, folderMapBackfill: state });
101064
+ }
101065
+ };
101066
+ }
101067
+ var collectLocalSessions = async ({ harnesses, ...options }) => {
101068
+ const claude = harnesses.has("claude-local") ? await collectClaudeCodeSessions(options) : null;
101069
+ const codex = harnesses.has("codex-local") ? await collectCodexSessions(options) : null;
101070
+ const cursor = harnesses.has("cursor-local") ? await collectCursorSessions(options) : null;
101071
+ return {
101072
+ sessions: [...claude?.sessions ?? [], ...codex?.sessions ?? [], ...cursor?.sessions ?? []],
101073
+ unread: (claude?.unreadable.length ?? 0) > 0 || (codex?.unreadable.length ?? 0) > 0 || cursor !== null && cursor.unavailable !== null
101074
+ };
101075
+ };
101076
+ function bySize(maps) {
101077
+ const uploads = [];
101078
+ let bytes = 0;
101079
+ for (const map2 of maps) {
101080
+ const size = Buffer.byteLength(JSON.stringify(map2));
101081
+ if (uploads.length === 0 || bytes + size > MAX_UPLOAD_BYTES) {
101082
+ uploads.push([]);
101083
+ bytes = 0;
101084
+ }
101085
+ uploads.at(-1).push(map2);
101086
+ bytes += size;
101087
+ }
101088
+ return uploads;
101089
+ }
101090
+
100919
101091
  // ../../apps/syncservice/src/sync.ts
100920
101092
  var RecordTurns = class {
100921
101093
  last = Promise.resolve();
@@ -100963,6 +101135,10 @@ async function runSyncPassInternal(config2, options, diagnostic, turn) {
100963
101135
  diagnostic.stage = "policy";
100964
101136
  const capture2 = await resolveCapturePolicy(config2, credentials, log3, void 0, options);
100965
101137
  diagnostic.claimsUnresolved = capture2.claimsUnresolved === true;
101138
+ const backfill = async () => {
101139
+ turn.end();
101140
+ await runFolderMapBackfill(config2.appEnv, credentials, capture2, log3, options);
101141
+ };
100966
101142
  const coverage = createSyncCoverage(config2.appEnv, options, credentials, capture2);
100967
101143
  const { sinceMs, rawShipped, window: window2, alreadySynced, alreadySyncedRepo } = coverage;
100968
101144
  if (window2.deepSweep) {
@@ -101091,6 +101267,7 @@ async function runSyncPassInternal(config2, options, diagnostic, turn) {
101091
101267
  } else if (collectedCompletely) {
101092
101268
  recordSyncedHistory();
101093
101269
  }
101270
+ await backfill();
101094
101271
  return { sessions: collected, upserted: 0, coverage: coverage.summary(collectedCompletely) };
101095
101272
  }
101096
101273
  diagnostic.stage = "metadata";
@@ -101217,6 +101394,7 @@ async function runSyncPassInternal(config2, options, diagnostic, turn) {
101217
101394
  }
101218
101395
  const complete = coverage.complete(diagnostic, raw, rawEligible, retryPending);
101219
101396
  recordSyncedHistory(complete);
101397
+ await backfill();
101220
101398
  return { sessions: collected, upserted, retryPending: retryPending > 0, coverage: coverage.summary(complete) };
101221
101399
  }
101222
101400
  async function runSyncPass(config2, options = {}) {
@@ -101333,7 +101511,7 @@ function fileErrorCode(error63) {
101333
101511
  return "invalid-state";
101334
101512
  }
101335
101513
  var digest = (value) => createHash9("sha256").update(JSON.stringify(value)).digest("hex");
101336
- var identity = (appEnv, credentials) => digest([
101514
+ var identity2 = (appEnv, credentials) => digest([
101337
101515
  appEnv,
101338
101516
  credentials.apiUrl,
101339
101517
  credentials.machineId,
@@ -101408,10 +101586,10 @@ function openWatchRecovery(options) {
101408
101586
  }
101409
101587
  return {
101410
101588
  restartSinceMs(credentials) {
101411
- return credentials && saved?.identity === identity(options.appEnv, credentials) ? saved.restartSinceMs : void 0;
101589
+ return credentials && saved?.identity === identity2(options.appEnv, credentials) ? saved.restartSinceMs : void 0;
101412
101590
  },
101413
101591
  beginPass(input2) {
101414
- const enrollment = identity(options.appEnv, input2.credentials);
101592
+ const enrollment = identity2(options.appEnv, input2.credentials);
101415
101593
  const scope = authority(input2.capture);
101416
101594
  const local = localAuthority(input2.credentials);
101417
101595
  if (!state && saved?.identity === enrollment) {
@@ -101466,7 +101644,7 @@ function openWatchRecovery(options) {
101466
101644
  timer.unref();
101467
101645
  },
101468
101646
  commit(restartSinceMs2, credentials) {
101469
- if (!canCheckpoint() || credentials === null || identity(options.appEnv, credentials) !== enrollment || localAuthority(credentials) !== local) return;
101647
+ if (!canCheckpoint() || credentials === null || identity2(options.appEnv, credentials) !== enrollment || localAuthority(credentials) !== local) return;
101470
101648
  current.pendingSinceMs = void 0;
101471
101649
  dirty ||= restartSinceMs2 !== current.snapshot.restartSinceMs;
101472
101650
  current.snapshot.restartSinceMs = restartSinceMs2;
@@ -102109,9 +102287,9 @@ function createWatchLoop(deps) {
102109
102287
  ...due.map(([, entry]) => entry.mtimeMs - 1)
102110
102288
  );
102111
102289
  try {
102112
- const summary = await deps.runPass(narrowSinceMs === void 0 ? {} : {
102113
- narrowSinceMs,
102114
- ...!history && liveSinceMs !== void 0 && { live: true }
102290
+ const summary = await deps.runPass({
102291
+ ...narrowSinceMs !== void 0 && { narrowSinceMs, ...!history && liveSinceMs !== void 0 && { live: true } },
102292
+ ...history && { backfillFolderMaps: true }
102115
102293
  });
102116
102294
  const scannedFloorMs = summary.coverage?.sinceMs ?? narrowSinceMs ?? steadyFloor;
102117
102295
  const complete = summary.coverage?.complete === true;
@@ -106777,7 +106955,7 @@ function runResumeSession(source, sessionId, deps = {}) {
106777
106955
  }
106778
106956
 
106779
106957
  // src/version.ts
106780
- var CLI_VERSION = true ? "0.4.40" : "0.0.0-checkout";
106958
+ var CLI_VERSION = true ? "0.4.41" : "0.0.0-checkout";
106781
106959
  var CLI_RELEASE_BUILD = true ? true : false;
106782
106960
  var CLI_DEVELOPMENT_COPY = false;
106783
106961
  function updateRefusal(tarball, developmentCopy = CLI_DEVELOPMENT_COPY) {
@@ -108686,4 +108864,4 @@ undici/lib/web/websocket/frame.js:
108686
108864
  (*! ws. MIT License. Einar Otto Stangvik <einaros@gmail.com> *)
108687
108865
  */
108688
108866
 
108689
- //# debugId=68f444bc-b4e3-5f4d-9d93-c8697eb31ccc
108867
+ //# debugId=cd09de5d-96df-55f4-8e5c-09d4bc0d1006
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usepowerplant/cli",
3
- "version": "0.4.40",
3
+ "version": "0.4.41",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },