@archme/cli 0.15.1 → 0.16.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/dist/cli.js CHANGED
@@ -19607,6 +19607,45 @@ var init_claimStance = __esm({
19607
19607
  }
19608
19608
  });
19609
19609
 
19610
+ // src/daemon/platformDevices.ts
19611
+ async function readPlatformDevices(client, userId) {
19612
+ const { data, error } = await client.from("agent_devices").select("id, name").eq("user_id", userId).is("org_id", null).eq("is_platform", true).eq("status", "enabled");
19613
+ if (error) throw new Error(error.message);
19614
+ return data ?? [];
19615
+ }
19616
+ function withPlatformDevices(devices, platform3) {
19617
+ const out = [...devices];
19618
+ for (const p of platform3) {
19619
+ if (!out.some((d) => d.deviceId === p.id)) out.push({ orgId: null, deviceId: p.id });
19620
+ }
19621
+ return out;
19622
+ }
19623
+ function deviceForOrgLookup(devices) {
19624
+ const members = devices.filter((d) => d.orgId !== null);
19625
+ const byOrg = new Map(members.map((d) => [d.orgId, d.deviceId]));
19626
+ return (orgId) => byOrg.get(orgId) ?? members[0]?.deviceId ?? null;
19627
+ }
19628
+ function poolBootLine(platform3, mode) {
19629
+ if (platform3.length === 0) return "not in managed pool";
19630
+ const names = platform3.map((p) => `${p.name} (${p.id})`).join(", ");
19631
+ return `in managed pool: platform device ${names}, ${mode === "required" ? "active" : "inactive unless sandbox=required"}`;
19632
+ }
19633
+ async function discoverClaimDevices(client, userId, devices, mode, out = console) {
19634
+ let platform3 = [];
19635
+ try {
19636
+ platform3 = await readPlatformDevices(client, userId);
19637
+ } catch (e) {
19638
+ out.warn(`platform device read failed, starting member-only until restart: ${e.message}`);
19639
+ }
19640
+ out.log(` ${poolBootLine(platform3, mode)}`);
19641
+ return { devices: withPlatformDevices(devices, platform3), platform: platform3 };
19642
+ }
19643
+ var init_platformDevices = __esm({
19644
+ "src/daemon/platformDevices.ts"() {
19645
+ "use strict";
19646
+ }
19647
+ });
19648
+
19610
19649
  // src/daemon/sandboxJob/result.ts
19611
19650
  import { readFile as readFile13 } from "node:fs/promises";
19612
19651
  function isValidNonce(nonce) {
@@ -23236,14 +23275,16 @@ async function rpcSetDaemonPause(ctx, pauseUntil, reason, detail) {
23236
23275
  console.error(`set_daemon_pause failed: ${error.message}`);
23237
23276
  }
23238
23277
  }
23239
- async function rpcReportEvent(ctx, orgId, eventType, payload) {
23278
+ async function rpcReportEvent(ctx, job, deviceId, eventType, payload) {
23240
23279
  try {
23241
23280
  const { error } = await withAuthRetry(
23242
23281
  "report_daemon_event",
23243
23282
  () => ctx.supabase.rpc("report_daemon_event", {
23244
- p_org_id: orgId,
23283
+ p_org_id: job.org_id,
23245
23284
  p_event_type: eventType,
23246
- p_payload: payload
23285
+ p_payload: payload,
23286
+ p_job_id: job.id,
23287
+ p_device_id: deviceId
23247
23288
  }),
23248
23289
  ctx.reLogin
23249
23290
  );
@@ -23752,7 +23793,7 @@ async function runJob(ctx, job, claimDeviceId) {
23752
23793
  Object.assign(timings, outcome.metrics.durations_ms);
23753
23794
  Object.assign(metrics, outcome.metrics, { durations_ms: timings });
23754
23795
  const sandboxMetrics = outcome.metrics.sandbox;
23755
- void rpcReportEvent(ctx, job.org_id, "sandbox_job_metrics", {
23796
+ await rpcReportEvent(ctx, job, deviceId, "sandbox_job_metrics", {
23756
23797
  job_id: job.id,
23757
23798
  project_id: job.project_id,
23758
23799
  outcome: outcome.kind,
@@ -24133,7 +24174,7 @@ ${logs.stderr}`, sentPrompt);
24133
24174
  if (plan) {
24134
24175
  const { parsed, pauseUntil, info } = plan;
24135
24176
  if (!parsed) {
24136
- void rpcReportEvent(ctx, job.org_id, "rate_limit_unmatched_exit", {
24177
+ await rpcReportEvent(ctx, job, deviceId, "rate_limit_unmatched_exit", {
24137
24178
  job_id: job.id,
24138
24179
  excerpt: [runErr?.claudeError?.text, haystack].filter(Boolean).join("\n").slice(0, 500)
24139
24180
  });
@@ -24476,7 +24517,9 @@ async function runDaemon() {
24476
24517
  const via = usedFallback ? ` (via device ${active.cred.device_id})` : "";
24477
24518
  const accountUserId = auth.getUserId() ?? "OAuth account";
24478
24519
  console.log(` account ${accountUserId}: ${active.result.user.email ?? "OAuth user"} (${devices.length} org(s))${via}`);
24479
- const byOrg = new Map(devices.map((d) => [d.orgId, d.deviceId]));
24520
+ const discovered = await discoverClaimDevices(client, auth.getUserId() ?? "", devices, sandboxSettings.mode);
24521
+ platformDevices = new Set(discovered.platform.map((p) => p.id));
24522
+ const claimDevices = discovered.devices;
24480
24523
  const sessions = [{
24481
24524
  supabase: client,
24482
24525
  auth,
@@ -24486,16 +24529,9 @@ async function runDaemon() {
24486
24529
  supabaseUrl: SUPABASE_URL,
24487
24530
  cloneBaseDir: CLONE_BASE_DIR,
24488
24531
  reLogin: () => auth.reauthenticate(),
24489
- devices,
24490
- deviceForOrg: (orgId) => byOrg.get(orgId) ?? devices[0]?.deviceId ?? null
24532
+ devices: claimDevices,
24533
+ deviceForOrg: deviceForOrgLookup(claimDevices)
24491
24534
  }];
24492
- try {
24493
- const { data, error } = await client.from("agent_devices").select("id, is_platform").in("id", devices.map((d) => d.deviceId));
24494
- if (error) throw new Error(error.message);
24495
- platformDevices = new Set((data ?? []).filter((d) => d.is_platform).map((d) => d.id));
24496
- } catch (e) {
24497
- console.warn(`agent_devices.is_platform read failed (treating devices as not platform): ${e.message}`);
24498
- }
24499
24535
  if (sandboxSettings.mode !== "off") {
24500
24536
  try {
24501
24537
  const { createSandboxParts: createSandboxParts2 } = await Promise.resolve().then(() => (init_parts(), parts_exports));
@@ -24733,6 +24769,7 @@ var init_run = __esm({
24733
24769
  init_architectureCounts();
24734
24770
  init_imageManifest();
24735
24771
  init_claimStance();
24772
+ init_platformDevices();
24736
24773
  init_claudeVersion();
24737
24774
  init_host();
24738
24775
  init_runSandboxedJob();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@archme/cli",
3
- "version": "0.15.1",
3
+ "version": "0.16.0",
4
4
  "description": "Map your codebase into a living architecture diagram: run `archme init` in a repo to scan it, `archme daemon start` to keep it current on every commit.",
5
5
  "type": "module",
6
6
  "license": "SEE LICENSE IN LICENSE",
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "image": "ghcr.io/architectme/archme-job",
3
- "digest": "sha256:a3c757d0dc7608b3c4e45b24e1ba4459c8f7ece2d0551a4633d2f3833a6fdc3e"
3
+ "digest": "sha256:3f8b289540503cc18a2794fa9de858e75a4ceb2d3cf709d814cf816569c36a96"
4
4
  }