@h1r-ai/croche-cli 0.6.1 → 0.7.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.
@@ -3,5 +3,7 @@ type Context = {
3
3
  readFile: (path: string, what: string) => Promise<string>;
4
4
  request: (path: string, method?: string, body?: unknown) => Promise<any>;
5
5
  };
6
+ /** One Core validator, including raw JSON grammar, canonical identity and byte bounds. */
7
+ export declare function validateBundleIdentity(raw: string): string;
6
8
  export declare function pushBase(args: Record<string, string>, context: Context): Promise<unknown>;
7
9
  export {};
@@ -16,3 +16,10 @@ export function selectedAgent(attachments,attachmentId,key){
16
16
  if(!row?.open)return null;
17
17
  return {attachmentId,target:{agentId:row.agentId,instance:row.instance,openSequence:row.openSequence},runtimeInstanceId:row.runtimeInstanceId,capabilities:attachment.capabilities};
18
18
  }
19
+ // A null identity in an initial roster can become known without reconnecting.
20
+ // The label is observational only: it never grants command/selection authority.
21
+ export function projectLabel(attachment,events){
22
+ if(attachment.runtime?.project)return attachment.runtime.project;
23
+ const identified=events.findLast(e=>id(e.projectId)&&attachment.agents.some(row=>row.open&&row.agentId===e.agentId&&row.runtimeInstanceId===e.runtimeInstanceId&&row.openSequence===e.openSequence));
24
+ return identified?.projectId??'Awaiting project identification';
25
+ }
@@ -1,7 +1,7 @@
1
1
  import {flowRows,flowCost,inspectable,inputBubbles} from './stage-model.js';
2
2
  import {readStageManifestFile,manifestLabels} from './stage-manifest.js';
3
3
  import {mountControl} from './stage-control.js';
4
- import {liveAttachments,selectedAgent,agentKey} from './stage-targets.js';
4
+ import {liveAttachments,selectedAgent,agentKey,projectLabel} from './stage-targets.js';
5
5
  const $=id=>document.getElementById(id);
6
6
  let snapshot={events:[]},session='',selected='',stream,manifest=null,manifestGeneration=0,project='',refreshing=false,refreshAgain=false;
7
7
  let live=[],remoteActive=false,remoteEvents=[],remoteLost=false;
@@ -33,7 +33,7 @@ function render(){
33
33
  const focused=document.activeElement?.closest('.flow-row')?.dataset.id;
34
34
  if(!project&&live.length)project=live[0].attachmentId;
35
35
  const attachment=live.find(a=>a.attachmentId===project);
36
- const runtimeOptions=live.map(a=>new Option(`${a.runtime?.project??'Runtime'} · ${a.runtime?.platform??'unknown platform'} · ${a.attachmentId.slice(-8)}`,a.attachmentId));
36
+ const runtimeOptions=live.map(a=>new Option(`${projectLabel(a,viewEvents)} · ${a.runtime?.platform??'unknown platform'} · ${a.attachmentId.slice(-8)}${a.captureReadStatus==='retrying'?' · capture read failed, retrying':''}`,a.attachmentId));
37
37
  if(!attachment){const missing=new Option(project?'Disconnected — choose a live Runtime':'No connected Runtime',project);missing.disabled=true;runtimeOptions.unshift(missing);}
38
38
  $('projects').replaceChildren(...runtimeOptions);$('projects').value=project;
39
39
  if(!session&&attachment?.agents.length)session=agentKey(attachment.agents.find(a=>a.open)??attachment.agents[0]);
@@ -213,8 +213,19 @@ export class DebugCollector {
213
213
  listener(); this.observe.wake(); }
214
214
  /** Ends every Studio observation stream with `collector_stopping`. */
215
215
  stop() { this.observe.end('collector_stopping'); }
216
- /** Server-owned v2 read adapter only; no new HTTP intake or credential authority. */
217
- acceptV2(value) { const event = this.validate(value); this.store(event); this.publish(); }
216
+ /** Server-owned v2 read adapter. False means this event failed collector validation. */
217
+ acceptV2(value) {
218
+ try {
219
+ this.store(this.validate(value));
220
+ }
221
+ catch (error) {
222
+ if (error instanceof HttpError && error.status >= 400 && error.status < 500)
223
+ return false;
224
+ throw error;
225
+ }
226
+ this.publish();
227
+ return true;
228
+ }
218
229
  controlRoster(attachments, connected) {
219
230
  const next = connected ? 'connected' : 'disconnected';
220
231
  if (JSON.stringify(this.liveAttachments) === JSON.stringify(attachments) && this.controlStatus === next)
@@ -61,44 +61,28 @@ export class ControlBridge {
61
61
  if (!Array.isArray(value.attachments) || value.attachments.length > 100)
62
62
  throw Error('Invalid live roster.');
63
63
  const attachments = value.attachments.filter(object).filter(a => a.state === 'connected');
64
- for (const a of attachments) {
64
+ const liveIds = attachments.map(a => {
65
65
  if (typeof a.attachmentId !== 'string' || !Array.isArray(a.agents) || !Array.isArray(a.capabilities))
66
66
  throw Error('Invalid live roster.');
67
- const id = a.attachmentId, after = this.cursors.get(id) ?? 0, result = await this.call('/read', { attachmentId: id, after });
68
- if (result.attachmentId !== id || !count(result.through) || result.through < after || !Array.isArray(result.entries) || !Array.isArray(result.gaps))
69
- throw Error('Uncorrelated control read.');
70
- const events = [];
71
- let last = after;
72
- for (const row of result.entries) {
73
- if (!object(row) || !count(row.cursor) || row.cursor <= last || row.cursor > result.through || !object(row.capture) || !count(row.capture.seq) || !object(row.capture.event))
74
- throw Error('Invalid control cursor.');
75
- last = row.cursor;
76
- if (row.capture.event.type !== 'roster')
77
- events.push(row.capture.event);
67
+ return a.attachmentId;
68
+ });
69
+ const roster = [];
70
+ for (const [index, id] of liveIds.entries()) {
71
+ let captureReadStatus = 'ok';
72
+ try {
73
+ await this.readAttachment(id);
78
74
  }
79
- for (const gap of result.gaps) {
80
- if (!object(gap) || !count(gap.from) || !count(gap.through) || gap.from > gap.through || gap.through > result.through)
81
- throw Error('Invalid control loss.');
75
+ catch {
76
+ captureReadStatus = 'retrying';
82
77
  }
83
- for (const event of events)
84
- this.collector.acceptV2(event);
85
- // Count each missing viewer cursor once, including private/withheld entries.
86
- const ranges = result.gaps.map(g => ({ from: Math.max(after + 1, g.from), through: g.through })).filter(g => g.from <= g.through).sort((a, b) => a.from - b.from);
87
- let end = after, lost = 0;
88
- for (const g of ranges) {
89
- lost += Math.max(0, g.through - Math.max(end, g.from - 1));
90
- end = Math.max(end, g.through);
91
- }
92
- if (lost)
93
- this.collector.controlLoss(lost);
94
- this.cursors.set(id, result.through);
78
+ if (this.abort.signal.aborted)
79
+ return;
80
+ roster.push({ ...attachments[index], captureReadStatus });
95
81
  }
96
- if (this.abort.signal.aborted)
97
- return;
98
82
  for (const id of this.cursors.keys())
99
- if (!attachments.some(a => a.attachmentId === id))
83
+ if (!liveIds.includes(id))
100
84
  this.cursors.delete(id);
101
- this.collector.controlRoster(attachments, true);
85
+ this.collector.controlRoster(roster, true);
102
86
  }
103
87
  catch {
104
88
  if (!this.abort.signal.aborted)
@@ -108,6 +92,40 @@ export class ControlBridge {
108
92
  this.busy = false;
109
93
  }
110
94
  }
95
+ async readAttachment(id) {
96
+ const after = this.cursors.get(id) ?? 0, result = await this.call('/read', { attachmentId: id, after });
97
+ if (this.abort.signal.aborted)
98
+ return;
99
+ if (result.attachmentId !== id || !count(result.through) || result.through < after || !Array.isArray(result.entries) || !Array.isArray(result.gaps))
100
+ throw Error('Uncorrelated control read.');
101
+ const events = [];
102
+ let last = after;
103
+ for (const row of result.entries) {
104
+ if (!object(row) || !count(row.cursor) || row.cursor <= last || row.cursor > result.through || !object(row.capture) || !count(row.capture.seq) || !object(row.capture.event))
105
+ throw Error('Invalid control cursor.');
106
+ last = row.cursor;
107
+ if (row.capture.event.type !== 'roster')
108
+ events.push(row.capture.event);
109
+ }
110
+ for (const gap of result.gaps) {
111
+ if (!object(gap) || !count(gap.from) || !count(gap.through) || gap.from > gap.through || gap.through > result.through)
112
+ throw Error('Invalid control loss.');
113
+ }
114
+ let lost = 0;
115
+ for (const event of events)
116
+ if (!this.collector.acceptV2(event))
117
+ lost++;
118
+ // Count each missing viewer cursor once, including private/withheld entries.
119
+ const ranges = result.gaps.map(g => ({ from: Math.max(after + 1, g.from), through: g.through })).filter(g => g.from <= g.through).sort((a, b) => a.from - b.from);
120
+ let end = after;
121
+ for (const g of ranges) {
122
+ lost += Math.max(0, g.through - Math.max(end, g.from - 1));
123
+ end = Math.max(end, g.through);
124
+ }
125
+ if (lost)
126
+ this.collector.controlLoss(lost);
127
+ this.cursors.set(id, result.through);
128
+ }
111
129
  start() { void this.poll(); this.timer = setInterval(() => void this.poll(), 1000); this.timer.unref?.(); }
112
130
  stop() { clearInterval(this.timer); this.abort.abort(); this.collector.controlRoster([], false); }
113
131
  }
@@ -1,6 +1,6 @@
1
1
  import { createHash, randomBytes } from 'node:crypto';
2
2
  /**
3
- * Studio observation of a local collector (docs/DEBUG-PAIRING.md, #253 §2a): one-time codes,
3
+ * Studio observation of a local collector (docs/hld/cloud/README.md#studio): one-time codes,
4
4
  * observe-only bearer tokens, and the cursor-ordered SSE stream of `runtime`-visibility events.
5
5
  * Observe credentials are memory-only and never accepted by ingest, pause or clear.
6
6
  */
@@ -14,6 +14,7 @@ type EnvTarget = {
14
14
  entry: string;
15
15
  };
16
16
  };
17
- export declare function writeDebugEnv(t: EnvTarget, secret: string): Promise<void>;
18
- export declare function debugKeys(action: string, args: Args, client: Client): Promise<unknown>;
17
+ export declare const developmentKeyEnvRename = "CROCHE_DEBUG_KEY was renamed to CROCHE_DEVELOPMENT_KEY";
18
+ export declare function writeDevelopmentEnv(t: EnvTarget, secret: string): Promise<void>;
19
+ export declare function developmentKeys(action: string, args: Args, client: Client): Promise<unknown>;
19
20
  export {};
package/dist/index.js CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  readResponse,
6
6
  runCli,
7
7
  studioUrl
8
- } from "./chunk-K3UDT4EM.js";
8
+ } from "./chunk-42AQKNDN.js";
9
9
  import "./chunk-66EUX7EL.js";
10
10
  export {
11
11
  CliError,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@h1r-ai/croche-cli",
3
- "version": "0.6.1",
3
+ "version": "0.7.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },