@parcha/agentrun-serve 0.1.0-beta.49 → 0.1.0-beta.51

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.
Files changed (216) hide show
  1. package/CHANGELOG.md +173 -9
  2. package/README.md +246 -39
  3. package/dist/agent-delete.d.ts +3 -2
  4. package/dist/agent-delete.js +29 -4
  5. package/dist/agents-store.js +7 -3
  6. package/dist/api-only.d.ts +8 -10
  7. package/dist/api-only.js +11 -12
  8. package/dist/capacity.d.ts +50 -0
  9. package/dist/capacity.js +49 -0
  10. package/dist/cli-learning/claude-wire.d.ts +41 -0
  11. package/dist/cli-learning/claude-wire.js +258 -0
  12. package/dist/cli-learning/cli.d.ts +11 -0
  13. package/dist/cli-learning/cli.js +241 -0
  14. package/dist/cli-learning/codex-worktree.d.ts +10 -0
  15. package/dist/cli-learning/codex-worktree.js +119 -0
  16. package/dist/cli-learning/connections.d.ts +62 -0
  17. package/dist/cli-learning/connections.js +87 -0
  18. package/dist/cli-learning/entry.d.ts +1 -0
  19. package/dist/cli-learning/entry.js +4 -0
  20. package/dist/cli-learning/evidence.d.ts +78 -0
  21. package/dist/cli-learning/evidence.js +492 -0
  22. package/dist/cli-learning/hook.d.ts +33 -0
  23. package/dist/cli-learning/hook.js +544 -0
  24. package/dist/cli-learning/install.d.ts +33 -0
  25. package/dist/cli-learning/install.js +335 -0
  26. package/dist/cli-learning/observation-proof.d.ts +14 -0
  27. package/dist/cli-learning/observation-proof.js +10 -0
  28. package/dist/cli-learning/policy.d.ts +48 -0
  29. package/dist/cli-learning/policy.js +363 -0
  30. package/dist/cli-learning/schema.d.ts +16 -0
  31. package/dist/cli-learning/schema.js +27 -0
  32. package/dist/cli-learning/state.d.ts +23 -0
  33. package/dist/cli-learning/state.js +61 -0
  34. package/dist/cli.js +24 -2
  35. package/dist/compute-cost.d.ts +101 -0
  36. package/dist/compute-cost.js +250 -0
  37. package/dist/console/assets/index-Bt1B51b7.js +733 -0
  38. package/dist/console/assets/index-sVftE9Ht.css +1 -0
  39. package/dist/console/index.html +2 -2
  40. package/dist/email/email-faux.d.ts +3 -1
  41. package/dist/email/email-faux.js +3 -2
  42. package/dist/email/routes.js +22 -12
  43. package/dist/eval-previous.d.ts +52 -0
  44. package/dist/eval-previous.js +164 -0
  45. package/dist/file-types.d.ts +2 -0
  46. package/dist/file-types.js +3 -1
  47. package/dist/harness-install.d.ts +6 -2
  48. package/dist/harness-install.js +40 -8
  49. package/dist/harness.d.ts +1 -1
  50. package/dist/harness.js +3 -2
  51. package/dist/learn/check.d.ts +8 -5
  52. package/dist/learn/check.js +25 -24
  53. package/dist/learn/repick.d.ts +22 -13
  54. package/dist/learn/repick.js +57 -56
  55. package/dist/learn/secrets.js +14 -3
  56. package/dist/learn/workflow-draft.d.ts +4 -0
  57. package/dist/learn/workflow-draft.js +10 -7
  58. package/dist/learned-workflow.js +8 -8
  59. package/dist/learning-setting.js +2 -2
  60. package/dist/learning-words.d.ts +1 -1
  61. package/dist/learning-words.js +1 -1
  62. package/dist/mcp-pin-first.js +2 -1
  63. package/dist/mcp-private-hosts.d.ts +24 -3
  64. package/dist/mcp-private-hosts.js +53 -3
  65. package/dist/model-gateway.d.ts +2 -0
  66. package/dist/model-gateway.js +3 -1
  67. package/dist/native/runtimes.d.ts +2 -0
  68. package/dist/native/runtimes.js +2 -0
  69. package/dist/observation/learning.d.ts +32 -0
  70. package/dist/observation/learning.js +66 -0
  71. package/dist/observation/observer.d.ts +8 -1
  72. package/dist/observation/observer.js +89 -9
  73. package/dist/observation/schema.js +12 -4
  74. package/dist/observation/usage-identity.d.ts +9 -0
  75. package/dist/observation/usage-identity.js +11 -0
  76. package/dist/openapi.js +113 -29
  77. package/dist/paid-calls.d.ts +13 -6
  78. package/dist/paid-calls.js +14 -8
  79. package/dist/run-launch.d.ts +16 -2
  80. package/dist/run-launch.js +6 -1
  81. package/dist/run-timeline-served.js +5 -3
  82. package/dist/run-usage.d.ts +23 -8
  83. package/dist/run-usage.js +100 -18
  84. package/dist/run-view.d.ts +2 -0
  85. package/dist/run-view.js +12 -7
  86. package/dist/runner/adapter-loop.d.ts +4 -0
  87. package/dist/runner/adapter-loop.js +44 -27
  88. package/dist/runner/adapter-run-spec.d.ts +8 -3
  89. package/dist/runner/adapter-run-spec.js +15 -8
  90. package/dist/runner/beside.d.ts +13 -0
  91. package/dist/runner/beside.js +27 -8
  92. package/dist/runner/big-writes.d.ts +33 -0
  93. package/dist/runner/big-writes.js +105 -0
  94. package/dist/runner/cli-run-spec.js +16 -8
  95. package/dist/runner/disk-free.d.ts +44 -0
  96. package/dist/runner/disk-free.js +96 -0
  97. package/dist/runner/feedback-round.d.ts +12 -8
  98. package/dist/runner/feedback-round.js +16 -30
  99. package/dist/runner/harness-loops.js +3 -1
  100. package/dist/runner/held.d.ts +4 -1
  101. package/dist/runner/journal-kinds.d.ts +1 -1
  102. package/dist/runner/learning-end.js +13 -4
  103. package/dist/runner/main.d.ts +17 -6
  104. package/dist/runner/main.js +187 -45
  105. package/dist/runner/metrics.d.ts +4 -0
  106. package/dist/runner/metrics.js +9 -0
  107. package/dist/runner/presence.d.ts +11 -2
  108. package/dist/runner/presence.js +31 -3
  109. package/dist/runner/run-child-host.d.ts +27 -17
  110. package/dist/runner/run-child-host.js +70 -116
  111. package/dist/runner/run-child.js +3 -0
  112. package/dist/runner/run-errors.js +2 -0
  113. package/dist/runner/runner-check.d.ts +51 -0
  114. package/dist/runner/runner-check.js +206 -0
  115. package/dist/runner/runner-metrics.d.ts +19 -0
  116. package/dist/runner/runner-metrics.js +49 -0
  117. package/dist/runner/runner.d.ts +37 -0
  118. package/dist/runner/runner.js +43 -3
  119. package/dist/runner/save-slots.d.ts +9 -0
  120. package/dist/runner/save-slots.js +91 -0
  121. package/dist/runner/sdk-loop.js +34 -22
  122. package/dist/runs-over-store.d.ts +8 -1
  123. package/dist/runs-over-store.js +57 -9
  124. package/dist/sdk/runs.d.ts +25 -6
  125. package/dist/sdk/runs.js +107 -35
  126. package/dist/sdk/runtimes.d.ts +19 -0
  127. package/dist/sdk/runtimes.js +23 -0
  128. package/dist/sdk/schema.d.ts +14 -8
  129. package/dist/sdk/schema.js +18 -6
  130. package/dist/server.d.ts +7 -0
  131. package/dist/server.js +151 -28
  132. package/dist/skills/agentrun-serve/SKILL.md +52 -7
  133. package/dist/start-switches.js +2 -0
  134. package/dist/stats.d.ts +4 -0
  135. package/dist/stats.js +1 -1
  136. package/dist/store/agent-body.d.ts +13 -2
  137. package/dist/store/agent-body.js +19 -4
  138. package/dist/store/dialect.d.ts +2 -0
  139. package/dist/store/dialect.js +1 -0
  140. package/dist/store/index.d.ts +3 -3
  141. package/dist/store/index.js +2 -2
  142. package/dist/store/postgres/connection.d.ts +5 -2
  143. package/dist/store/postgres/connection.js +19 -7
  144. package/dist/store/postgres/dialect.js +1 -0
  145. package/dist/store/postgres/migrate.d.ts +30 -0
  146. package/dist/store/postgres/migrate.js +72 -5
  147. package/dist/store/postgres/migration-lint.d.ts +8 -0
  148. package/dist/store/postgres/migration-lint.js +119 -0
  149. package/dist/store/postgres/migrations/0023_computer_interval_resources.sql +14 -0
  150. package/dist/store/postgres/migrations/0024_runner_capacity.sql +28 -0
  151. package/dist/store/postgres/store.d.ts +8 -3
  152. package/dist/store/postgres/store.js +31 -11
  153. package/dist/store/schema.d.ts +26 -4
  154. package/dist/store/schema.js +45 -4
  155. package/dist/store/sqlite/connection.d.ts +3 -3
  156. package/dist/store/sqlite/connection.js +3 -3
  157. package/dist/store/sqlite/run-launch.d.ts +9 -1
  158. package/dist/store/sqlite/run-launch.js +44 -0
  159. package/dist/store/sqlite/store.d.ts +19 -4
  160. package/dist/store/sqlite/store.js +180 -93
  161. package/dist/store/store-schema.d.ts +34 -0
  162. package/dist/store/store-schema.js +125 -0
  163. package/dist/store/store.d.ts +61 -2
  164. package/dist/store/store.js +13 -0
  165. package/dist/store-reads/analytics.d.ts +3 -2
  166. package/dist/store-reads/analytics.js +20 -8
  167. package/dist/store-reads/cap.d.ts +9 -5
  168. package/dist/store-reads/cap.js +28 -2
  169. package/dist/store-reads/decisions.d.ts +21 -0
  170. package/dist/store-reads/decisions.js +22 -0
  171. package/dist/store-reads/journal.d.ts +8 -2
  172. package/dist/store-reads/journal.js +27 -8
  173. package/dist/store-view.d.ts +9 -4
  174. package/dist/store-view.js +48 -25
  175. package/dist/template-eval.d.ts +15 -1
  176. package/dist/template-eval.js +92 -13
  177. package/dist/templates.d.ts +4 -3
  178. package/dist/templates.js +4 -3
  179. package/dist/timeline/labels.js +17 -0
  180. package/dist/tool-gate.d.ts +4 -2
  181. package/dist/tool-list.js +1 -0
  182. package/dist/tools.d.ts +6 -2
  183. package/dist/tools.js +13 -1
  184. package/dist/trigger-targets.d.ts +21 -5
  185. package/dist/trigger-targets.js +13 -10
  186. package/dist/unified-usage.d.ts +24 -0
  187. package/dist/unified-usage.js +400 -0
  188. package/dist/uploads-archil.d.ts +100 -0
  189. package/dist/uploads-archil.js +430 -0
  190. package/dist/uploads.d.ts +55 -1
  191. package/dist/uploads.js +185 -98
  192. package/dist/validate.js +1 -1
  193. package/dist/web-fake.d.ts +25 -0
  194. package/dist/web-fake.js +38 -1
  195. package/dist/web-save.d.ts +75 -0
  196. package/dist/web-save.js +235 -0
  197. package/dist/workspace/archil-claim.d.ts +5 -2
  198. package/dist/workspace/archil-claim.js +5 -2
  199. package/dist/workspace/archil-disk.d.ts +11 -1
  200. package/dist/workspace/archil-disk.js +43 -10
  201. package/dist/workspace/archil.d.ts +3 -0
  202. package/dist/workspace/archil.js +102 -16
  203. package/dist/workspace/computer-for-claim.d.ts +14 -0
  204. package/dist/workspace/computer-for-claim.js +46 -7
  205. package/dist/workspace/computer-intervals.d.ts +9 -3
  206. package/dist/workspace/computer-intervals.js +17 -8
  207. package/dist/workspace/pieced.d.ts +14 -0
  208. package/dist/workspace/pieced.js +23 -0
  209. package/dist/workspace/run-disk.js +32 -12
  210. package/dist/workspace/run-workspace.d.ts +1 -1
  211. package/dist/workspace/run-workspace.js +11 -6
  212. package/package.json +10 -10
  213. package/skills/agentrun-serve/SKILL.md +52 -7
  214. package/templates/README.md +36 -7
  215. package/dist/console/assets/index-Bzn4eUYF.js +0 -715
  216. package/dist/console/assets/index-CR2ZGei1.css +0 -1
@@ -2,6 +2,8 @@
2
2
  * Observation never launches a run, imports credentials, creates a runnable definition or enables learning. */
3
3
  import { createHash, randomBytes, timingSafeEqual } from "node:crypto";
4
4
  import { NATIVE_OBSERVATION_HARNESSES, nativeObservationProtocol } from "../native/runtimes.js";
5
+ import { unboundLearning } from "./learning.js";
6
+ import { usageIdentityOf } from "./usage-identity.js";
5
7
  const PREFIX = "observation.connector.";
6
8
  const DAY = 86_400_000;
7
9
  const OFFLINE = 120_000;
@@ -55,6 +57,13 @@ const uuid = (v) => typeof v === "string" &&
55
57
  /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(v);
56
58
  const harness = (v) => nativeObservationProtocol(v) !== undefined;
57
59
  const safeInt = (v, min = 0) => typeof v === "number" && Number.isSafeInteger(v) && v >= min;
60
+ /** Explicit native titles only: no conversation previews, paths, controls or obvious credentials. */
61
+ const sessionLabel = (v, max, project = false) => typeof v === "string" && v.length > 0 && v.length <= max && v.trim() === v &&
62
+ !/[\u0000-\u001f\u007f-\u009f\u2028\u2029\p{Cf}\p{Cs}]/u.test(v) &&
63
+ !/\\/.test(v) && !(project && v.includes("/")) &&
64
+ !/(?:^|[\s"'=(])(?:\/\S|~[/\\]|[A-Za-z]:[/\\]|\\\\)/.test(v) &&
65
+ !/\b[a-z][a-z0-9+.-]*:\/\//i.test(v) &&
66
+ !/\bsk[-_]|ghp_|github_pat_|xox[baprs]-|\bBearer\s|AKIA[A-Z0-9]{12,}/i.test(v);
58
67
  const activities = new Set([
59
68
  "unknown",
60
69
  "working",
@@ -145,6 +154,8 @@ function checkMode(row, sources) {
145
154
  }
146
155
  export const observationCapabilities = () => ({
147
156
  version: 1,
157
+ session_labels: true,
158
+ cli_learning: { session_association: true },
148
159
  ingestion_modes: ["polling", "otlp"],
149
160
  supported_harnesses: [...NATIVE_OBSERVATION_HARNESSES],
150
161
  logs_formats: ["json"],
@@ -153,6 +164,7 @@ export const observationCapabilities = () => ({
153
164
  max_log_records: 100,
154
165
  max_payload_bytes: MAX_OTLP_PAYLOAD_BYTES,
155
166
  token_usage: {
167
+ polling: true,
156
168
  supported_harnesses: [...NATIVE_OBSERVATION_HARNESSES],
157
169
  model_attribute: "agentrun.model",
158
170
  count_attributes: COUNTS.map((k) => "agentrun." + k),
@@ -168,9 +180,11 @@ export const observationCapabilities = () => ({
168
180
  export class Observations {
169
181
  store;
170
182
  now;
171
- constructor(store, now = Date.now) {
183
+ learning;
184
+ constructor(store, now = Date.now, learning) {
172
185
  this.store = store;
173
186
  this.now = now;
187
+ this.learning = learning;
174
188
  }
175
189
  stamp() {
176
190
  return new Date(this.now()).toISOString();
@@ -445,9 +459,10 @@ export class Observations {
445
459
  "type",
446
460
  "occurred_at",
447
461
  "metadata",
462
+ "usage",
448
463
  ]);
449
464
  const m = obj(e.metadata);
450
- exact(m, ["harness", "activity"]);
465
+ exact(m, ["harness", "activity", "display_name", "project_name", "cli_learning"]);
451
466
  if (!uuid(e.event_id) ||
452
467
  !id(e.source_id) ||
453
468
  !id(e.external_session_id) ||
@@ -456,10 +471,47 @@ export class Observations {
456
471
  !timestamp(e.occurred_at) ||
457
472
  Date.parse(e.occurred_at) > this.now() + 300_000 ||
458
473
  !harness(m.harness) ||
459
- !activities.has(m.activity))
474
+ !activities.has(m.activity) ||
475
+ (Object.hasOwn(m, "display_name") && !sessionLabel(m.display_name, 120)) ||
476
+ (Object.hasOwn(m, "project_name") && !sessionLabel(m.project_name, 80, true)))
460
477
  refuse(422, "connector_invalid");
478
+ if (Object.hasOwn(m, "cli_learning")) {
479
+ const learning = obj(m.cli_learning);
480
+ exact(learning, ["readiness", "connection_id", "native_session_hash", "proof"]);
481
+ if (!["ready", "setup_required", "unknown", "unsupported"].includes(learning.readiness)
482
+ || (Object.hasOwn(learning, "connection_id") && !id(learning.connection_id))
483
+ || (Object.hasOwn(learning, "proof") && (typeof learning.proof !== "string" || !/^[0-9a-f]{64}$/.test(learning.proof)))
484
+ || (Object.hasOwn(learning, "native_session_hash") && (typeof learning.native_session_hash !== "string" || !/^[0-9a-f]{64}$/.test(learning.native_session_hash)))
485
+ || Object.hasOwn(learning, "connection_id") !== Object.hasOwn(learning, "proof")
486
+ || Object.hasOwn(learning, "connection_id") !== Object.hasOwn(learning, "native_session_hash")
487
+ || (learning.readiness === "ready" && !learning.connection_id))
488
+ refuse(422, "connector_invalid");
489
+ }
490
+ if (Object.hasOwn(e, "usage")) {
491
+ const usage = obj(e.usage);
492
+ exact(usage, ["model", ...COUNTS]);
493
+ if (typeof usage.model !== "string" ||
494
+ !/^[A-Za-z0-9][A-Za-z0-9._:/+\-]{0,127}$/.test(usage.model) ||
495
+ !safeInt(usage.input_tokens) ||
496
+ !safeInt(usage.output_tokens) ||
497
+ COUNTS.some((k) => Object.hasOwn(usage, k) && !safeInt(usage[k])) ||
498
+ (usage.cache_read_tokens ?? 0) + (usage.cache_write_tokens ?? 0) > usage.input_tokens ||
499
+ !Number.isSafeInteger(usage.input_tokens + usage.output_tokens))
500
+ refuse(422, "connector_invalid");
501
+ }
461
502
  return e;
462
503
  });
504
+ // Authenticate the observation scope before looking up any private CLI connection. A stale or forged
505
+ // association cannot attach a profile, but it must not stop otherwise valid activity and usage ingestion.
506
+ await this.authenticate(connectorId, credential);
507
+ for (const event of events) {
508
+ const report = event.metadata.cli_learning;
509
+ if (report)
510
+ event.learning_association = this.learning
511
+ ? await this.learning.verify(report, { connector_id: connectorId, source_id: event.source_id,
512
+ external_session_id: event.external_session_id, runtime: event.metadata.harness === "claude" ? "claude-code" : "codex", sequence: event.sequence })
513
+ : { readiness: report.connection_id ? "unknown" : report.readiness };
514
+ }
463
515
  return this.ingest(connectorId, credential, b.selections_revision, events, "polling");
464
516
  }
465
517
  async ingest(connectorId, credential, revision, events, mode) {
@@ -485,7 +537,8 @@ export class Observations {
485
537
  refuse(403, "connector_source_denied");
486
538
  if (Date.parse(e.occurred_at) < row.receipt_floor)
487
539
  continue;
488
- const request = fingerprint(e), prior = row.receipts[e.event_id];
540
+ const { learning_association, ...reported } = e;
541
+ const request = fingerprint(reported), prior = row.receipts[e.event_id];
489
542
  if (prior) {
490
543
  if (prior.hash !== request)
491
544
  refuse(409, "idempotency_conflict");
@@ -504,6 +557,13 @@ export class Observations {
504
557
  hash([connectorId, e.metadata.harness, e.external_session_id].join(":")).slice(0, 40), old = row.sessions[sessionId];
505
558
  if (!old && Object.keys(row.sessions).length >= MAX_SESSIONS)
506
559
  refuse(429, "connector_session_capacity_exceeded");
560
+ // Historical accounting survives readiness changes and credential revocation. Migrate
561
+ // old verified associations before replacing them, never trust the raw source report.
562
+ const previousIdentity = usageIdentityOf(old?.usage_identity) ?? usageIdentityOf(old?.learning_association);
563
+ const assertedIdentity = usageIdentityOf(learning_association);
564
+ if (previousIdentity && assertedIdentity && previousIdentity.native_session_hash !== assertedIdentity.native_session_hash)
565
+ refuse(409, "connector_session_identity_conflict");
566
+ const usage_identity = previousIdentity ?? assertedIdentity;
507
567
  const at = this.stamp();
508
568
  row.receipts[e.event_id] = {
509
569
  hash: request,
@@ -515,13 +575,21 @@ export class Observations {
515
575
  ? BigInt(e.source_time) >
516
576
  BigInt(old?.source_time ?? String((old?.sequence ?? 0) * 1000))
517
577
  : e.sequence > (old?.sequence ?? 0));
518
- if (!old || (!e.initial_only && newer))
578
+ if (!old || (!e.initial_only && newer)) {
579
+ // Older clients and OTLP activity may omit names. Keep the last accepted
580
+ // labels until a genuinely newer observation explicitly replaces them.
581
+ const display_name = e.metadata.display_name ?? old?.display_name;
582
+ const project_name = e.metadata.project_name ?? old?.project_name;
519
583
  row.sessions[sessionId] = {
520
584
  id: sessionId,
521
585
  source_id: e.source_id,
522
586
  external_session_id: e.external_session_id,
523
587
  harness: e.metadata.harness,
524
588
  activity: e.metadata.activity,
589
+ ...(display_name ? { display_name } : {}),
590
+ ...(project_name ? { project_name } : {}),
591
+ ...(learning_association ? { learning_association } : {}),
592
+ ...(usage_identity ? { usage_identity } : {}),
525
593
  sequence: e.sequence,
526
594
  ingestion_epoch: row.ingestion_epoch ?? 0,
527
595
  ...(e.source_time ? { source_time: e.source_time } : {}),
@@ -531,9 +599,18 @@ export class Observations {
531
599
  updated_at: at,
532
600
  usage_by_day: old?.usage_by_day ?? {},
533
601
  };
534
- if (e.usage) {
602
+ }
603
+ // An older, independently verified receipt can still establish historical identity
604
+ // without changing current activity/readiness or admitting its stale usage again.
605
+ if (usage_identity)
606
+ row.sessions[sessionId].usage_identity = usage_identity;
607
+ // Polling reports durable counter deltas in sequence order. A new UUID must not
608
+ // make a stale sequence count twice; native OTLP requests can legitimately arrive late.
609
+ if (e.usage && (mode === "otlp" || newer)) {
535
610
  const session = row.sessions[sessionId];
536
- const date = at.slice(0, 10);
611
+ const date = mode === "polling"
612
+ ? new Date(e.occurred_at).toISOString().slice(0, 10)
613
+ : at.slice(0, 10);
537
614
  const day = (session.usage_by_day[date] ??= {});
538
615
  const previous = Object.hasOwn(day, e.usage.model)
539
616
  ? day[e.usage.model]
@@ -737,14 +814,14 @@ export class Observations {
737
814
  this.now();
738
815
  const terminal = ["finished", "failed", "stopped"].includes(s.activity);
739
816
  const summary = summaries.get(s.id);
740
- const { usage_by_day, ingestion_epoch, ...shown } = s;
817
+ const { usage_by_day, ingestion_epoch, learning_association, usage_identity, ...shown } = s;
741
818
  sessions.push({
742
819
  ...shown,
743
820
  connector_id: row.id,
744
821
  workspace_id: "local",
745
822
  kind: "connected_session",
746
823
  state: "active",
747
- display_name: `${row.display_name} · ${s.harness === "claude" ? "Claude Code" : "Codex"}`,
824
+ display_name: s.display_name ?? `${s.harness === "claude" ? "Claude Code" : "Codex"} · ${s.external_session_id.slice(-8)}`,
748
825
  reported_activity: s.activity,
749
826
  activity: terminal
750
827
  ? s.activity
@@ -754,6 +831,9 @@ export class Observations {
754
831
  connection_state: connector.connection_state,
755
832
  selection_active: active,
756
833
  observation_only: true,
834
+ learning: this.learning
835
+ ? await this.learning.view(learning_association, s.harness === "claude" ? "claude-code" : "codex")
836
+ : unboundLearning(learning_association?.readiness),
757
837
  models: [...(summary?.models ?? [])],
758
838
  usage: {
759
839
  ...(summary?.usage ?? unavailable()),
@@ -2,7 +2,7 @@
2
2
  import { NATIVE_OBSERVATION_HARNESSES } from "../native/runtimes.js";
3
3
  const text = { type: "string" };
4
4
  const count = { type: "integer", minimum: 0 };
5
- const object = (properties, required = Object.keys(properties)) => ({ type: "object", properties, required });
5
+ const object = (properties, required = Object.keys(properties), optional = []) => ({ type: "object", properties, required: required.filter((key) => !optional.includes(key)) });
6
6
  const usage = object({
7
7
  input_tokens: count,
8
8
  output_tokens: count,
@@ -29,7 +29,7 @@ export const OBSERVATION_PATHS = {
29
29
  get: {
30
30
  operationId: "getObservations",
31
31
  summary: "Read activity and token usage reported by externally running agents",
32
- description: "Observation-only sessions retain the original harness. They are not executable agent definitions and do not enable learning. Tokens include cache in input; absent cache counters are null. Receipts have a seven-day replay window; older source timestamps cannot create activity or usage. Sessions and received-day usage are retained for 90 days. Capacity overflow is explicitly refused. Cross-connector totals outside exact integer range are null with overflow true. CLI ingestion is at /api/v2/control; /api/v2/control/connectors/capabilities advertises the supported wire formats.",
32
+ description: "Observation-only sessions retain the original harness. They are not executable agent definitions and do not enable learning. Learning status may refer to an existing CLI learning profile after a source proves its project/runtime-scoped credential; On also requires an accepted hook window for the exact native session. Profile settings are read live. No credential, proof or source path appears in observations. Tokens include cache in input; absent cache counters are null. Receipts have a seven-day replay window; older source timestamps cannot create activity or usage. Sessions and daily usage are retained for 90 days. Polling token deltas use the source UTC day and strictly increasing session sequences; OTLP usage uses the received UTC day. Capacity overflow is explicitly refused. Cross-connector totals outside exact integer range are null with overflow true. CLI ingestion is at /api/v2/control; /api/v2/control/connectors/capabilities advertises the supported wire formats and token_usage.polling support.",
33
33
  tags: ["Observations"],
34
34
  security: [{ bearer: [] }],
35
35
  "x-agentrun-serve": "observations/1",
@@ -78,7 +78,8 @@ export const OBSERVATION_PATHS = {
78
78
  created_at: text,
79
79
  updated_at: text,
80
80
  sequence: count,
81
- display_name: text,
81
+ display_name: { ...text, description: "Explicit native session title when reported; otherwise the harness and an opaque ID suffix." },
82
+ project_name: { ...text, description: "Optional project basename; never an absolute source path." },
82
83
  models: { type: "array", items: text },
83
84
  usage: {
84
85
  ...usage,
@@ -89,7 +90,14 @@ export const OBSERVATION_PATHS = {
89
90
  required: [...usage.required, "status"],
90
91
  },
91
92
  observation_only: { const: true },
92
- }),
93
+ learning: object({
94
+ state: { enum: ["on", "off", "setup_required", "unknown", "unsupported"] },
95
+ reason: { enum: ["ready", "source_setup_required", "source_unknown", "delegated_session", "connection_unavailable", "server_disabled", "agent_disabled", "awaiting_activation"] },
96
+ agent_id: text,
97
+ connection_id: text,
98
+ mode: { enum: ["off", "notes", "corrections", "workflows"] },
99
+ }, undefined, ["agent_id", "connection_id", "mode"]),
100
+ }, undefined, ["project_name"]),
93
101
  },
94
102
  usage: {
95
103
  ...usage,
@@ -0,0 +1,9 @@
1
+ /** Private historical provenance for one observed session's retained usage. It grants no learning authority. */
2
+ export type UsageIdentity = {
3
+ native_session_hash: string;
4
+ connection_id: string;
5
+ generation: string;
6
+ };
7
+ /** Read a server-verified association or its persisted accounting identity, never a wire report.
8
+ * Only verification adds generation; structural validation here does not authenticate a source. */
9
+ export declare function usageIdentityOf(value: unknown): UsageIdentity | undefined;
@@ -0,0 +1,11 @@
1
+ /** Read a server-verified association or its persisted accounting identity, never a wire report.
2
+ * Only verification adds generation; structural validation here does not authenticate a source. */
3
+ export function usageIdentityOf(value) {
4
+ if (!value || typeof value !== "object" || Array.isArray(value))
5
+ return undefined;
6
+ const { native_session_hash, connection_id, generation } = value;
7
+ return typeof native_session_hash === "string" && /^[a-f0-9]{64}$/.test(native_session_hash)
8
+ && typeof connection_id === "string" && connection_id.length > 0
9
+ && typeof generation === "string" && generation.length > 0
10
+ ? { native_session_hash, connection_id, generation } : undefined;
11
+ }