@north-light/crouter-api 0.3.263 → 0.3.270

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.
@@ -19,7 +19,7 @@ import type { CancelReviewRequest, CreateReviewRequest, ListReviewsQuery, Review
19
19
  import type { CreateReviewCommentRequest, EditReviewCommentRequest, ListReviewCommentsQuery, ReadReviewCommentEventsQuery, ReviewCommentActionRequest, ReviewCommentDetailDTO, ReviewCommentEventsDTO, ReviewCommentListDTO, ReviewCommentMutationDTO, ReviewCommentRangeBatchRequest, ReviewCommentRangeBatchResultDTO } from './dto/review-comments.js';
20
20
  import type { CancelInboxTicketRequest, CanceledTicketResultDTO, InboxListDTO, InboxPageDTO, InboxPageHistoryDTO, InboxPageResponseDTO, InboxTicketIdDTO, PageFeedbackResolutionDTO, PageResponsesDTO, PageTicketResultDTO, RespondInboxPageRequest } from './dto/inbox.js';
21
21
  import type { CreateHumanRequestDTO, CreateHumanRequestRequest, HumanRequestDTO, HumanRequestIdDTO, ReplaceHumanRequestRequest, RespondHumanRequestRequest, SettleHumanRequestRequest } from './dto/human-requests.js';
22
- import type { AttentionCountsDTO, AttentionDTO, DashboardDTO, DashboardQuery, HistoryGrepQuery, HistoryGrepResultDTO, HistoryReadQuery, HistoryReadResultDTO, HistorySearchQuery, HistorySearchResultDTO, PruneRequest, PruneResultDTO, RebuildIndexResultDTO, RosterDTO, SnapshotDTO } from './dto/canvas.js';
22
+ import type { AttentionCountsDTO, AttentionDTO, DashboardDTO, DashboardQuery, HistoryGrepQuery, HistoryGrepResultDTO, HistoryReadQuery, HistoryStatsQuery, HistoryStatsResultDTO, HistoryReadResultDTO, HistorySearchQuery, HistorySearchResultDTO, PruneRequest, PruneResultDTO, RebuildIndexResultDTO, RosterDTO, SnapshotDTO } from './dto/canvas.js';
23
23
  import type { AbandonWorktreeRequest, AbandonWorktreeResultDTO, CloseWorktreeResultDTO, QuarantinedWorktreeDTO } from './dto/worktree.js';
24
24
  import type { BrokerExtensionStateDTO, BrokerGeneratedNameRequest, BrokerGeneratedNameResultDTO, BrokerInboxCursorDirective, BrokerInboxCursorRequest, BrokerModelCommitRequest, BrokerModelCommitResultDTO, BrokerPersonaAckRequest, BrokerPersonaAckResultDTO, BrokerSessionBoundRequest, BrokerSessionBoundResultDTO, BrokerSettleDirective, BrokerSettleRequest } from './dto/broker-ops.js';
25
25
  export interface CrtrClientOptions {
@@ -279,6 +279,10 @@ export declare class CrtrClient {
279
279
  /** Resolve one `<node-id>:<relpath>` history ref to its full body
280
280
  * (`crtr canvas history read`). */
281
281
  historyRead(q: HistoryReadQuery): Promise<HistoryReadResultDTO>;
282
+ /** Grouped-count projection over the per-cwd episodic corpus
283
+ * (`crtr canvas history stats`). Same filters as search/grep, aggregate
284
+ * result instead of a hit page — POST-bodied for the same reasons. */
285
+ historyStats(q: HistoryStatsQuery): Promise<HistoryStatsResultDTO>;
282
286
  /** The machine-readable browser canvas roster (`crtr canvas snapshot`) —
283
287
  * distinct from the per-node `getSnapshot`. */
284
288
  canvasSnapshot(): Promise<SnapshotDTO>;
@@ -519,6 +519,12 @@ export class CrtrClient {
519
519
  historyRead(q) {
520
520
  return this.request('GET', withQuery(routes.canvasHistoryRead(), q));
521
521
  }
522
+ /** Grouped-count projection over the per-cwd episodic corpus
523
+ * (`crtr canvas history stats`). Same filters as search/grep, aggregate
524
+ * result instead of a hit page — POST-bodied for the same reasons. */
525
+ historyStats(q) {
526
+ return this.request('POST', routes.canvasHistoryStats(), q);
527
+ }
522
528
  /** The machine-readable browser canvas roster (`crtr canvas snapshot`) —
523
529
  * distinct from the per-node `getSnapshot`. */
524
530
  canvasSnapshot() {
@@ -26,6 +26,10 @@ export interface BrokerWelcomeSnapshot<M = unknown> {
26
26
  messages: M[];
27
27
  /** Stable session-entry ids aligned 1:1 with `messages`. */
28
28
  messageIds?: string[];
29
+ /** Presentation visibility aligned 1:1 with `messages`. */
30
+ messageVisibility: Array<'visible' | 'internal'>;
31
+ /** Presentation visibility of the run currently owned by the engine. */
32
+ turnVisibility: 'visible' | 'internal';
29
33
  state?: {
30
34
  isStreaming?: boolean;
31
35
  };
@@ -42,6 +46,11 @@ export interface BrokerWelcomeFrame<M = unknown> {
42
46
  type: 'welcome';
43
47
  snapshot?: BrokerWelcomeSnapshot<M>;
44
48
  }
49
+ /** The presentation classification of the run whose native events follow. */
50
+ export interface BrokerTurnVisibilityFrame {
51
+ type: 'turn_visibility';
52
+ visibility: 'visible' | 'internal';
53
+ }
45
54
  /**
46
55
  * The crtrd broker `node_named` control frame — the node's generated name at the
47
56
  * instant crtrd committed it.
@@ -68,11 +77,11 @@ export interface BrokerNodeNamedFrame {
68
77
  }
69
78
  /**
70
79
  * The broker-control frames a relay consumer reads: `welcome` (catch-up snapshot),
71
- * `error`, and `node_named`. The broker interleaves others (display_*, ack, …)
80
+ * `turn_visibility`, `error`, and `node_named`. The broker interleaves others (display_*, ack, …)
72
81
  * under non-colliding `type` discriminants; a relay mapper drops those through its
73
82
  * `default` arm untyped, so they are not enumerated here.
74
83
  */
75
- export type BrokerControlFrame<M = unknown> = BrokerWelcomeFrame<M> | BrokerErrorFrame | BrokerNodeNamedFrame;
84
+ export type BrokerControlFrame<M = unknown> = BrokerWelcomeFrame<M> | BrokerTurnVisibilityFrame | BrokerErrorFrame | BrokerNodeNamedFrame;
76
85
  /**
77
86
  * What the crtrd broker attach delivers to a relay consumer: the live engine
78
87
  * event stream (`E` — pi's `AgentSessionEvent`, relayed verbatim) unioned with the
@@ -1,8 +1,8 @@
1
1
  // Broker attach-protocol envelope DTOs — the crtrd-specific control frames the
2
2
  // broker interleaves around pi's native agent-session event stream over a node's
3
3
  // `view.sock` (and its WS bridge, spec §5). This module owns ONLY that envelope
4
- // vocabulary: the two broker-control frames a relay consumer reads (`welcome` +
5
- // `error`), the welcome snapshot they carry, and the relay union that folds them
4
+ // vocabulary: the broker-control frames a relay consumer reads, the welcome
5
+ // snapshot they carry, and the relay union that folds them
6
6
  // together with the live engine event stream.
7
7
  //
8
8
  // PURITY (spec §3.1): like every file under `src/api/`, this imports NOTHING —
@@ -52,7 +52,7 @@ export interface HistorySearchQuery {
52
52
  under?: string;
53
53
  /** Restrict to specific node ids. */
54
54
  nodes?: string[];
55
- /** Corpus types: report | doc | roadmap | meta | inbox. */
55
+ /** Corpus types: report | doc | roadmap | meta | inbox | transcript. */
56
56
  types?: string[];
57
57
  report_kind?: string;
58
58
  kinds?: string[];
@@ -61,6 +61,12 @@ export interface HistorySearchQuery {
61
61
  since_ms?: number;
62
62
  /** Upper bound on artifact timestamp (epoch ms), parsed CLI-side. */
63
63
  until_ms?: number;
64
+ /** Inbound-message narrowing (transcript + inbox): what drove arrival. */
65
+ origins?: string[];
66
+ /** Transcript-message roles: user | assistant | toolResult. */
67
+ roles?: string[];
68
+ /** Case-insensitive substring against sender attribution. */
69
+ from?: string;
64
70
  /** Weigh full body text in ranking (`--body`). */
65
71
  weigh_body?: boolean;
66
72
  /** relevance | recency | oldest — already resolved to the effective sort. */
@@ -93,7 +99,7 @@ export interface HistoryGrepQuery {
93
99
  under?: string;
94
100
  /** Restrict to specific node ids. */
95
101
  nodes?: string[];
96
- /** Corpus types: report | doc | roadmap | meta | inbox. */
102
+ /** Corpus types: report | doc | roadmap | meta | inbox | transcript. */
97
103
  types?: string[];
98
104
  report_kind?: string;
99
105
  kinds?: string[];
@@ -102,9 +108,50 @@ export interface HistoryGrepQuery {
102
108
  since_ms?: number;
103
109
  /** Upper bound on artifact timestamp (epoch ms), parsed CLI-side. */
104
110
  until_ms?: number;
111
+ /** Inbound-message narrowing (transcript + inbox): what drove arrival. */
112
+ origins?: string[];
113
+ /** Transcript-message roles: user | assistant | toolResult. */
114
+ roles?: string[];
115
+ /** Case-insensitive substring against sender attribution. */
116
+ from?: string;
105
117
  limit?: number;
106
118
  cursor?: Cursor;
107
119
  }
120
+ /** `POST /v1/canvas/history/stats` body — the grouped-count projection over
121
+ * the same corpus search and grep scan, backing `crtr canvas history stats`.
122
+ * Shares every scope/corpus/message filter; carries no query, pattern, or
123
+ * pagination because the result is an aggregate, not a hit list. */
124
+ export interface HistoryStatsQuery {
125
+ /** origin | node | kind | day | type | role. Defaults to type. */
126
+ group_by?: string;
127
+ cwd?: string;
128
+ all_cwds?: boolean;
129
+ under?: string;
130
+ nodes?: string[];
131
+ types?: string[];
132
+ report_kind?: string;
133
+ kinds?: string[];
134
+ statuses?: string[];
135
+ since_ms?: number;
136
+ until_ms?: number;
137
+ origins?: string[];
138
+ roles?: string[];
139
+ from?: string;
140
+ }
141
+ /** `POST /v1/canvas/history/stats` result — counts by the grouped dimension,
142
+ * descending. `total` counts the artifacts that carried the dimension, so it
143
+ * can be lower than the corpus size when grouping by one not every artifact
144
+ * has (origin, role). */
145
+ export interface HistoryStatsResultDTO {
146
+ group_by: string;
147
+ groups: Array<{
148
+ key: string;
149
+ count: number;
150
+ }>;
151
+ total: number;
152
+ /** Artifacts scanned before the grouping dimension was applied. */
153
+ scanned: number;
154
+ }
108
155
  /** One matching body line from `crtr canvas history grep`. */
109
156
  export interface HistoryGrepHitDTO {
110
157
  ref: string;
@@ -126,6 +173,10 @@ export interface HistoryReadQuery {
126
173
  ref: string;
127
174
  /** Keep the artifact's YAML frontmatter (stripped by default). */
128
175
  frontmatter?: boolean;
176
+ /** `rendered` (default) or `raw` — the verbatim bytes behind the ref: the
177
+ * session file for a bare `session` ref, the one jsonl line for a message,
178
+ * the unparsed file for a report or doc. */
179
+ format?: string;
129
180
  }
130
181
  /** `GET /v1/canvas/history/read` result — one hit's full body. */
131
182
  export interface HistoryReadResultDTO {
@@ -67,6 +67,12 @@ export interface CreateNodeRequest {
67
67
  export interface NodeSummaryDTO {
68
68
  node_id: NodeIdDTO;
69
69
  name: string;
70
+ /** Generated first-task description, absent when the node is not yet named.
71
+ * Paired with `name` it forms the full display label, so a roster consumer
72
+ * builds it without a per-node metadata fetch. */
73
+ description?: string;
74
+ /** How many times the node has been (re)launched; absent on a pre-v38 row. */
75
+ cycles?: number;
70
76
  kind: string;
71
77
  mode: ModeDTO;
72
78
  lifecycle: LifecycleDTO;
@@ -169,7 +175,6 @@ export interface NodeFaultDTO {
169
175
  export interface NodeDetailDTO extends NodeSummaryDTO {
170
176
  /** Node that created this node, or null when an external process did. */
171
177
  creator: NodeIdDTO | null;
172
- description?: string;
173
178
  /** The namer's prose form of `description` — sentence case, punctuation intact
174
179
  * (`NodeMeta.title`). What a surface showing this node to a person reads;
175
180
  * absent on a node named before titles existed. */
@@ -177,7 +182,6 @@ export interface NodeDetailDTO extends NodeSummaryDTO {
177
182
  /** The Nerd Font glyph the namer chose for this node's work, when it has one
178
183
  * (`NodeMeta.icon`). Rendered ahead of the label by surfaces that want it. */
179
184
  icon?: string;
180
- cycles?: number;
181
185
  /** Approximate context-window token load of the node's live/last session,
182
186
  * used by the orchestrator yield-nudge (`childFollowUp`). Null when unknown
183
187
  * (never launched, or no token accounting yet). */
@@ -240,6 +244,8 @@ export interface NodeSnapshotDTO {
240
244
  snapshot: {
241
245
  messages: unknown[];
242
246
  messageIds?: string[];
247
+ messageVisibility: Array<'visible' | 'internal'>;
248
+ turnVisibility: 'visible' | 'internal';
243
249
  stats: unknown;
244
250
  state: Record<string, unknown>;
245
251
  display: {
@@ -278,6 +284,8 @@ export interface NodeMessagesPageDTO {
278
284
  messages: unknown[];
279
285
  /** Stable session-entry ids aligned 1:1 with `messages`. */
280
286
  message_ids?: string[];
287
+ /** Presentation visibility aligned 1:1 with `messages`. */
288
+ message_visibility: Array<'visible' | 'internal'>;
281
289
  /** Opaque cursor toward older messages; null at the start of the session. */
282
290
  next_cursor: Cursor | null;
283
291
  captured_at: IsoTime;
@@ -59,6 +59,7 @@ export declare const routes: {
59
59
  readonly canvasHistorySearch: () => string;
60
60
  readonly canvasHistoryGrep: () => string;
61
61
  readonly canvasHistoryRead: () => string;
62
+ readonly canvasHistoryStats: () => string;
62
63
  readonly canvasSnapshot: () => string;
63
64
  readonly canvasRoster: () => string;
64
65
  readonly canvasPrune: () => string;
@@ -81,6 +81,7 @@ export const routes = {
81
81
  canvasHistorySearch: () => `${V}/canvas/history/search`,
82
82
  canvasHistoryGrep: () => `${V}/canvas/history/grep`,
83
83
  canvasHistoryRead: () => `${V}/canvas/history/read`,
84
+ canvasHistoryStats: () => `${V}/canvas/history/stats`,
84
85
  canvasSnapshot: () => `${V}/canvas/snapshot`,
85
86
  canvasRoster: () => `${V}/canvas/roster`,
86
87
  canvasPrune: () => `${V}/canvas/prune`,
@@ -8,6 +8,8 @@ export declare function envNodeCwd(): string | undefined;
8
8
  * undefined. Cleared (not read) via `delete process.env['CRTR_MODEL_INTENT']`
9
9
  * in `runtime/broker.ts` — a mutation, not a read, so it stays there. */
10
10
  export declare function envModelIntent(): string | undefined;
11
+ /** Whether the launch recipe requires this broker to keep its exact provider/model. */
12
+ export declare function envModelExact(): boolean;
11
13
  /** The raw `CRTR_HOME` override, unresolved. Use `crtrHome()`
12
14
  * (`core/canvas/paths.ts`) to get the resolved canvas-home path; use this
13
15
  * only when a caller needs the override itself — to check whether one is
@@ -67,6 +69,14 @@ export declare function envWarnLiveBrokers(): number | undefined;
67
69
  /** Test-only unattended-park interval override (`CRTR_TEST_UNATTENDED_PARK_MS`),
68
70
  * gated by `envNoDaemonAutostart()` at the call site; no production default. */
69
71
  export declare function envTestUnattendedParkMs(): number | undefined;
72
+ /** Production unattended-park interval override (`CRTR_UNATTENDED_PARK_MS`), in
73
+ * milliseconds; wins over the user-scope config value
74
+ * (`readConfig('user').lifecycle.unattendedParkMs`, itself defaulting to 15
75
+ * min) whenever set, autostart or not. Unlike `CRTR_TEST_UNATTENDED_PARK_MS`
76
+ * this is not gated on `envNoDaemonAutostart()`: it is the env escape hatch
77
+ * above the configured knob a deployment sets to tune how long an eligible
78
+ * resident idles before its parking turn. */
79
+ export declare function envUnattendedParkMs(): number | undefined;
70
80
  /** Test-only park-summary grace-period override
71
81
  * (`CRTR_TEST_PARK_SUMMARY_GRACE_MS`); no production default. */
72
82
  export declare function envTestParkSummaryGraceMs(): number | undefined;
@@ -40,6 +40,10 @@ export function envNodeCwd() {
40
40
  export function envModelIntent() {
41
41
  return process.env['CRTR_MODEL_INTENT'];
42
42
  }
43
+ /** Whether the launch recipe requires this broker to keep its exact provider/model. */
44
+ export function envModelExact() {
45
+ return process.env['CRTR_MODEL_EXACT'] === '1';
46
+ }
43
47
  /** The raw `CRTR_HOME` override, unresolved. Use `crtrHome()`
44
48
  * (`core/canvas/paths.ts`) to get the resolved canvas-home path; use this
45
49
  * only when a caller needs the override itself — to check whether one is
@@ -140,10 +144,11 @@ export function envDebug() {
140
144
  return process.env['CRTR_DEBUG'] === '1';
141
145
  }
142
146
  // Precedence — broker-supervision.ts's threshold/interval overrides. Each
143
- // returns the raw parsed value with NO default: the caller (config for the
144
- // thresholds, a hardcoded production constant for the intervals) supplies
145
- // the default, and env wins over it when set. Undefined, unparseable, or
146
- // non-positive all mean "no override" the caller's own default applies.
147
+ // returns the raw parsed value with NO default: the caller supplies the
148
+ // default (user config for the broker thresholds and the unattended-park
149
+ // interval, a hardcoded constant for the test-only park-summary grace), and
150
+ // env wins over it when set. Undefined, unparseable, or non-positive all mean
151
+ // "no override" — the caller's own default applies.
147
152
  function parsePositiveInteger(raw) {
148
153
  if (raw === undefined || raw === '')
149
154
  return undefined;
@@ -171,6 +176,16 @@ function parsePositiveMsNoDefault(raw) {
171
176
  export function envTestUnattendedParkMs() {
172
177
  return parsePositiveMsNoDefault(process.env['CRTR_TEST_UNATTENDED_PARK_MS']);
173
178
  }
179
+ /** Production unattended-park interval override (`CRTR_UNATTENDED_PARK_MS`), in
180
+ * milliseconds; wins over the user-scope config value
181
+ * (`readConfig('user').lifecycle.unattendedParkMs`, itself defaulting to 15
182
+ * min) whenever set, autostart or not. Unlike `CRTR_TEST_UNATTENDED_PARK_MS`
183
+ * this is not gated on `envNoDaemonAutostart()`: it is the env escape hatch
184
+ * above the configured knob a deployment sets to tune how long an eligible
185
+ * resident idles before its parking turn. */
186
+ export function envUnattendedParkMs() {
187
+ return parsePositiveMsNoDefault(process.env['CRTR_UNATTENDED_PARK_MS']);
188
+ }
174
189
  /** Test-only park-summary grace-period override
175
190
  * (`CRTR_TEST_PARK_SUMMARY_GRACE_MS`); no production default. */
176
191
  export function envTestParkSummaryGraceMs() {
@@ -11,8 +11,7 @@ export declare const STALL_REPROMPT: string;
11
11
  /** The daemon's parking mandate: the last turn of a conversation the unattended
12
12
  * clock is concluding. Delivered live, wrapped in a `park` runtime card. It
13
13
  * governs both the node's durable inheritance and reader-facing output:
14
- * one update for subscribers and history, then a silent stop with no assistant
15
- * prose for an external channel to relay.
14
+ * one update for subscribers and history, then a brief completion reply.
16
15
  *
17
16
  * The durable inheritance shares a CONTRACT with `node yield`'s pre-invocation
18
17
  * guide (roadmap current, short and shrinking; context dir for in-progress
@@ -16,8 +16,7 @@ export const STALL_REPROMPT = "You've stopped but you're not waiting on anyone a
16
16
  /** The daemon's parking mandate: the last turn of a conversation the unattended
17
17
  * clock is concluding. Delivered live, wrapped in a `park` runtime card. It
18
18
  * governs both the node's durable inheritance and reader-facing output:
19
- * one update for subscribers and history, then a silent stop with no assistant
20
- * prose for an external channel to relay.
19
+ * one update for subscribers and history, then a brief completion reply.
21
20
  *
22
21
  * The durable inheritance shares a CONTRACT with `node yield`'s pre-invocation
23
22
  * guide (roadmap current, short and shrinking; context dir for in-progress
@@ -28,8 +27,8 @@ export const PARK_SUMMARY_PROMPT = 'This conversation has been idle with nothing
28
27
  + '2. Rewrite `$CRTR_CONTEXT_DIR/roadmap.md` for a fresh context window. This is the only handoff document a later fresh cycle receives in full. Preserve the current goal and exit criteria when they still apply, then state the present outcome; what remains or is blocked; decisions or questions still open; exact recovery handles for in-flight state; and the first safe move on return. Keep strategy and present state, not a transcript recap. Delete stale and completed steps instead of marking them done; the roadmap should stay short and shrink. Write a minimal one now if none exists.\n\n'
29
28
  + '3. Put supporting material in your context directory only when the roadmap would become bulky without it. Rewrite existing living documents rather than leave superseded versions. Name every supporting file the next cycle must read from the roadmap and say what it is for—the revive shows filenames but does not inject their contents. Task state, identifiers, and recovery detail belong here, not in memory.\n\n'
30
29
  + '4. Use memory only for a non-obvious, reusable lesson that should survive this task and is not already recorded. Read `crtr memory write -h`, find before writing, and choose the narrowest scope that will reach the next agent who needs it. Do not put a conversation recap, task status, recovery handles, or facts already captured in code or docs into memory.\n\n'
31
- + '5. Push exactly one regular update with `crtr push update --tier deferred`, never `crtr push final`. Write it for subscribers and history, not as a second roadmap. Its first line must stand alone as the current outcome, blocker, or decision that matters; then include only unfinished work, a needed decision, and concrete handles a subscriber may need. This concludes the conversation; it does not finish the mandate.\n\n'
32
- + '6. Keep this entire turn silent in the conversation: produce no assistant prose before, between, or after tool calls, and do not narrate the work. Once every required tool call has finished, end the response immediately without emitting any text, sign-off, summary, acknowledgement, or other visible content by emitting the `stop` token with no text. The deferred update from step 5 is the only reader-facing conclusion. A later message reopens you on a fresh context window grounded in your goal and roadmap, so the inheritance you leave now is what you get back.';
30
+ + '5. Push exactly one regular update with `crtr push update --tier deferred`, never `crtr push final`. Write for someone who has not seen this conversation: name the work in plain terms, say where it stands, and say what remains or is blocked. Put the current outcome in the first line; include only needed decisions and recovery handles. This concludes the conversation, not the mandate.\n\n'
31
+ + '6. When finished, reply with exactly `done`.';
33
32
  /** Static recovery prompts shared by the broker producer and display classifier. */
34
33
  export const AUTH_FAULT_RECOVERY_BODY = 'Provider credentials were just updated (a new login landed). Your previous turn stopped on a provider authentication failure. Continue from where you left off and retry the work that failed.';
35
34
  export const CONNECTION_FAULT_RECOVERY_BODY = 'The network connection is back online. Your previous turn stopped on a connection error (the network was down). Continue from where you left off and retry the work that failed.';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@north-light/crouter-api",
3
- "version": "0.3.263",
3
+ "version": "0.3.270",
4
4
  "description": "Typed crtrd /v1 API contract — DTOs, route builders, the error contract, and the CrtrClient. Zero runtime dependencies.",
5
5
  "type": "module",
6
6
  "main": "./dist/api/index.js",