@astrosheep/square 0.3.78 → 0.3.80

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 (70) hide show
  1. package/dist/attention-presentation.d.ts +2 -0
  2. package/dist/attention-presentation.js +39 -4
  3. package/dist/automatic-session.js +1 -1
  4. package/dist/boundary-presentation.js +4 -7
  5. package/dist/claude-mod.js +1 -1
  6. package/dist/cli/catch-presentation.d.ts +2 -2
  7. package/dist/cli/catch-presentation.js +3 -3
  8. package/dist/cli/context.d.ts +11 -1
  9. package/dist/cli/context.js +14 -3
  10. package/dist/cli/express-presentation.d.ts +6 -5
  11. package/dist/cli/express-presentation.js +42 -43
  12. package/dist/cli/maintenance-commands.js +6 -6
  13. package/dist/cli/mcp-server-command.js +1 -1
  14. package/dist/cli/observation-commands.d.ts +4 -4
  15. package/dist/cli/observation-commands.js +20 -16
  16. package/dist/cli/program.d.ts +1 -1
  17. package/dist/cli/program.js +5 -5
  18. package/dist/cli/square-commands.js +35 -23
  19. package/dist/decisions.d.ts +3 -5
  20. package/dist/decisions.js +10 -9
  21. package/dist/delivery.d.ts +1 -1
  22. package/dist/help.js +15 -2
  23. package/dist/inbox.js +3 -3
  24. package/dist/index.d.ts +1 -2
  25. package/dist/index.js +1 -2
  26. package/dist/ledger-maintenance.d.ts +1 -1
  27. package/dist/ledger-maintenance.js +1 -1
  28. package/dist/list.d.ts +3 -3
  29. package/dist/list.js +1 -1
  30. package/dist/mcp.d.ts +2 -2
  31. package/dist/mcp.js +12 -7
  32. package/dist/mention-parse.d.ts +2 -8
  33. package/dist/mention-parse.js +6 -9
  34. package/dist/model.d.ts +2 -2
  35. package/dist/notifications.js +24 -8
  36. package/dist/participant-host.js +5 -0
  37. package/dist/plugins/opencode/index.js +1 -1
  38. package/dist/square-actions.d.ts +22 -9
  39. package/dist/square-actions.js +26 -19
  40. package/dist/square-api.d.ts +43 -0
  41. package/dist/square-api.js +471 -0
  42. package/dist/square-facade.d.ts +123 -203
  43. package/dist/square-tools.d.ts +4 -3
  44. package/dist/square-tools.js +21 -15
  45. package/dist/stream.d.ts +2 -2
  46. package/dist/views.d.ts +16 -12
  47. package/dist/views.js +13 -27
  48. package/guides/application-demand-optimization.md +5 -0
  49. package/guides/application-facade-delivery-evidence.md +7 -2
  50. package/guides/mcp-connection-lifetime.md +2 -2
  51. package/guides/mcp.md +1 -1
  52. package/guides/operation-cancellation.md +2 -0
  53. package/guides/primitive-catch-consolidation.md +5 -0
  54. package/guides/primitive-history-consolidation.md +5 -0
  55. package/guides/primitive-status-consolidation.md +5 -0
  56. package/guides/primitive-storage-consolidation.md +5 -0
  57. package/guides/row-storage-design.md +1 -1
  58. package/guides/square-api.md +107 -0
  59. package/package.json +1 -1
  60. package/plugins/claude/.claude-plugin/plugin.json +1 -1
  61. package/plugins/claude/skills/square/SKILL.md +4 -4
  62. package/plugins/codex/.codex-plugin/plugin.json +1 -1
  63. package/plugins/opencode/index.ts +1 -1
  64. package/plugins/paseo/client/markdown.tsx +16 -6
  65. package/plugins/pi/square-pi.js +7 -6
  66. package/skills/square/SKILL.md +4 -4
  67. package/dist/square-application.d.ts +0 -38
  68. package/dist/square-application.js +0 -683
  69. package/guides/application-boundary.md +0 -32
  70. package/guides/application-facade-design.md +0 -98
@@ -1,10 +1,8 @@
1
1
  import type { ActivityId, Perception, Reach } from './square-core.js';
2
2
  import type { StoredAct } from './model.js';
3
3
  import type { HostLedgerPort, WakeTransportPort, DeliveryResult, SquareResourceOwner } from './ports.js';
4
- import type { DiagnoseResult } from './artifact.js';
5
- import type { MigrationOutcome } from './square-migration.js';
6
4
  export type { ActivityId, Perception, Reach } from './square-core.js';
7
- /** The existing indexed domain event, including read and historical actorless lifecycle records. */
5
+ /** Indexed archive event, including read and historical actorless lifecycle records. */
8
6
  export type ArchiveRecord = Readonly<StoredAct>;
9
7
  export interface Activity {
10
8
  readonly id: ActivityId;
@@ -20,35 +18,56 @@ export interface Activity {
20
18
  export interface PerceivedActivity extends Activity {
21
19
  readonly perception: Perception;
22
20
  }
23
- export interface ExpressOptions {
21
+ /** Request extra facts for rendering, without changing operation semantics. */
22
+ export interface ObservationOptions {
23
+ readonly observe?: boolean;
24
+ }
25
+ export interface ExpressOptions extends ObservationOptions {
24
26
  readonly force?: boolean;
25
27
  readonly mentions?: readonly string[];
26
28
  readonly reach?: Reach;
27
29
  readonly reply?: ActivityId;
28
30
  readonly noMention?: boolean;
31
+ readonly noWait?: boolean;
29
32
  }
30
- export interface ExpressResult {
33
+ export interface ActivityResult {
31
34
  readonly activity: Activity;
32
35
  readonly delivery?: DeliveryResult;
36
+ }
37
+ export interface ExpressResult extends ActivityResult {
38
+ readonly waited: boolean;
33
39
  /** The replied-to author was not standing when the reply landed. */
34
40
  readonly replyAuthorNotHere?: string;
41
+ /** Body @name tokens with no standing match at landing; never stored on the activity. */
42
+ readonly unmatchedMentions?: readonly string[];
43
+ readonly observation?: ExpressObservation;
35
44
  }
36
- export interface ListenerChangeData {
45
+ export interface ListenerChangeResult {
37
46
  readonly activity: Activity | null;
47
+ readonly observation?: ListenerObservation;
38
48
  }
39
- export type ListenerChangeResult = ListenerChangeData;
40
- export interface CatchOptions {
49
+ export interface ListeningResult {
50
+ readonly listening: readonly string[];
51
+ readonly observation?: SquareObservation;
52
+ }
53
+ export interface LifecycleResult extends ActivityResult {
54
+ readonly observation?: LifecycleObservation;
55
+ }
56
+ export interface CatchOptions extends ObservationOptions {
41
57
  readonly id?: ActivityId;
42
58
  readonly idle?: number;
43
59
  readonly from?: readonly string[];
44
60
  readonly mention?: boolean;
45
61
  readonly limit?: number;
62
+ readonly replace?: boolean;
46
63
  }
47
64
  export interface CatchResult {
48
65
  readonly activities: readonly PerceivedActivity[];
49
66
  readonly consumedThrough: ActivityId | null;
50
67
  readonly idleExpired: boolean;
51
68
  readonly remaining: number;
69
+ readonly status?: CatchTerminalStatus;
70
+ readonly observation?: CatchObservation;
52
71
  }
53
72
  export interface CatchWaitStart {
54
73
  readonly idleMs: number;
@@ -69,8 +88,23 @@ export interface OperationControl {
69
88
  readonly signal?: AbortSignal;
70
89
  readonly onProgress?: (progress: OperationProgress) => void;
71
90
  }
72
- export interface HistoryQuery {
73
- readonly limit?: number;
91
+ export interface OperationFailureDetail {
92
+ readonly operation: 'express' | 'join' | 'catch' | 'history' | 'other';
93
+ readonly subject?: 'caller' | 'filter' | 'recipient';
94
+ readonly participant?: string;
95
+ readonly expressEffect?: 'unsent' | 'landed' | 'unknown';
96
+ readonly landedId?: ActivityId;
97
+ readonly historyBounds?: {
98
+ readonly maxLimit: number;
99
+ readonly totalMatches: number;
100
+ };
101
+ }
102
+ export interface OperationError extends Error {
103
+ readonly operation?: OperationFailureDetail;
104
+ }
105
+ export interface HistoryQuery extends ObservationOptions {
106
+ /** Ten by default; null explicitly reads the full archive. */
107
+ readonly limit?: number | null;
74
108
  readonly order?: 'asc' | 'desc';
75
109
  readonly before?: ActivityId;
76
110
  readonly after?: ActivityId;
@@ -78,6 +112,14 @@ export interface HistoryQuery {
78
112
  readonly fixed?: string;
79
113
  readonly from?: readonly string[];
80
114
  readonly mention?: string;
115
+ readonly since?: number;
116
+ readonly at?: readonly ActivityId[];
117
+ readonly contextBefore?: number;
118
+ readonly contextAfter?: number;
119
+ }
120
+ export interface HistoryResult {
121
+ readonly activities: readonly Activity[];
122
+ readonly observation?: HistoryObservation;
81
123
  }
82
124
  export interface ParticipantStatus {
83
125
  readonly name: string;
@@ -98,132 +140,61 @@ export interface SquareSnapshot {
98
140
  readonly participants: readonly ParticipantStatus[];
99
141
  delivered(name: string, id: ActivityId): boolean;
100
142
  }
101
- export type SquareSource = {
102
- path: string;
103
- };
104
143
  export interface OpenOptions {
105
- clock?: () => number;
106
- hostLedger?: HostLedgerPort;
107
- wakeTransport?: WakeTransportPort;
108
- env?: NodeJS.ProcessEnv;
109
- }
110
- export interface SquareAtInput extends SquareSource, OpenOptions {
111
- }
112
- export interface SquareBuildInput extends SquareSource, OpenOptions {
113
- markdown: string;
114
- hardCap?: number | null;
115
- throttlePerMinute?: number;
116
- }
117
- /** Optional fence for owner-scoped lifecycle actions. */
118
- export interface OwnershipFenceOptions {
119
- readonly expectedEpoch?: number;
144
+ readonly clock?: () => number;
145
+ readonly hostLedger?: HostLedgerPort;
146
+ readonly wakeTransport?: WakeTransportPort;
147
+ readonly env?: NodeJS.ProcessEnv;
120
148
  }
121
- export interface Participant {
122
- readonly name: string;
123
- express(body: string, options?: ExpressOptions, control?: OperationControl): Promise<ExpressResult>;
124
- listen(target: string, control?: OperationControl): Promise<ListenerChangeResult>;
125
- ignore(target: string, control?: OperationControl): Promise<ListenerChangeResult>;
126
- listening(control?: OperationControl): Promise<readonly string[]>;
127
- catch(options?: CatchOptions, control?: OperationControl): Promise<CatchResult>;
128
- history(query?: HistoryQuery, control?: OperationControl): Promise<Activity[]>;
129
- hold(reason?: string, control?: OperationControl): Promise<ExpressResult>;
130
- resume(control?: OperationControl): Promise<ExpressResult>;
131
- /** Leave without a message. Only an omitted or empty body is accepted. */
132
- done(body?: string, control?: OperationControl): Promise<ExpressResult>;
149
+ export interface SquareLocation {
150
+ readonly path?: string;
151
+ readonly cwd?: string;
152
+ readonly env?: NodeJS.ProcessEnv;
133
153
  }
134
- export interface SquareApplicationContext extends Readonly<OpenOptions> {
135
- readonly cwd: string;
136
- readonly env: NodeJS.ProcessEnv;
137
- readonly squarePath?: string;
154
+ export interface SquareAtInput extends SquareLocation, OpenOptions {
138
155
  readonly participant?: string;
139
- /** Borrow the owner's connection for the configured square. The caller owns its lifetime;
140
- * without an owner, each operation opens and closes its own connection. */
156
+ /** A caller-owned connection; closing this Square never closes its owner. */
141
157
  readonly resources?: SquareResourceOwner;
142
158
  }
143
- /** Data-only callers do not request or pay for presentation work. */
144
- export interface ApplicationOutcome<Data, Projection, Presentation extends boolean = true> {
145
- readonly data: Data;
146
- readonly projection: Presentation extends true ? Projection : undefined;
147
- }
148
- export interface ApplicationFailureDetail {
149
- readonly operation: 'express' | 'join' | 'catch' | 'history' | 'other';
150
- readonly subject?: 'caller' | 'filter' | 'recipient';
151
- readonly participant?: string;
152
- readonly expressEffect?: 'unsent' | 'landed' | 'unknown';
153
- readonly landedId?: ActivityId;
154
- readonly historyBounds?: {
155
- readonly maxLimit: number;
156
- readonly totalMatches: number;
157
- };
158
- }
159
- export interface ApplicationError extends Error {
160
- readonly operation?: ApplicationFailureDetail;
161
- }
162
- export interface SquareContextProjection {
163
- readonly location: string;
164
- readonly standingCount: number;
165
- readonly held: boolean;
166
- readonly now: number;
167
- readonly participant?: string;
168
- readonly automaticDeliveryAvailable: boolean;
169
- }
170
- export interface BuildApplicationInput {
159
+ export interface SquareBuildInput extends SquareAtInput {
171
160
  readonly markdown: string;
172
161
  readonly hardCap?: number | null;
173
162
  readonly throttlePerMinute?: number;
174
163
  readonly template?: string;
175
164
  readonly force?: boolean;
176
165
  }
177
- export interface BuildApplicationData {
178
- readonly location: string;
179
- readonly hardCap: number | null;
180
- readonly throttlePerMinute?: number;
181
- }
182
- export interface JoinApplicationOptions {
166
+ export interface JoinOptions extends ObservationOptions {
183
167
  readonly takeover?: boolean;
184
168
  readonly last?: number;
185
169
  }
186
- export interface JoinApplicationData {
187
- readonly participant: string;
170
+ export interface JoinResult {
171
+ readonly participant: Participant;
188
172
  readonly activity: Activity | null;
189
173
  readonly kind: 'joined' | 'reconnected' | 'taken-over';
190
- /** Known joined-or-done participants, NOT the current standing count. */
174
+ /** Known joined-or-done participants, not the current standing count. */
191
175
  readonly participantCount: number;
176
+ readonly observation?: JoinObservation;
192
177
  }
193
- export interface ExpressApplicationOptions extends ExpressOptions {
194
- readonly noWait?: boolean;
195
- readonly requireExplicitReach?: boolean;
196
- }
197
- export interface ExpressApplicationData {
198
- readonly activity: Activity;
199
- readonly waited: boolean;
200
- readonly replyAuthorNotHere?: string;
178
+ /** Optional fence for owner-scoped lifecycle actions. */
179
+ export interface OwnershipFenceOptions {
180
+ readonly expectedEpoch?: number;
201
181
  }
202
- export interface CatchApplicationOptions extends CatchOptions {
203
- readonly replace?: boolean;
182
+ export interface Participant {
183
+ readonly name: string;
184
+ express(body: string, options?: ExpressOptions, control?: OperationControl): Promise<ExpressResult>;
185
+ listen(target: string, options?: ObservationOptions, control?: OperationControl): Promise<ListenerChangeResult>;
186
+ ignore(target: string, options?: ObservationOptions, control?: OperationControl): Promise<ListenerChangeResult>;
187
+ listening(options?: ObservationOptions, control?: OperationControl): Promise<ListeningResult>;
188
+ catch(options?: CatchOptions, control?: OperationControl): Promise<CatchResult>;
189
+ history(query?: HistoryQuery, control?: OperationControl): Promise<HistoryResult>;
190
+ hold(reason?: string, options?: ObservationOptions, control?: OperationControl): Promise<LifecycleResult>;
191
+ resume(options?: ObservationOptions, control?: OperationControl): Promise<LifecycleResult>;
192
+ /** Leave without a message. Only an omitted or empty body is accepted. */
193
+ done(body?: string, options?: ObservationOptions, control?: OperationControl): Promise<LifecycleResult>;
204
194
  }
205
195
  export type CatchTerminalStatus = 'already-active' | 'replaced' | 'capped' | 'quorum';
206
196
  export type CatchStopStatus = CatchTerminalStatus | 'empty-now' | 'stale';
207
- export interface CatchApplicationData extends CatchResult {
208
- readonly status?: CatchTerminalStatus;
209
- }
210
- export interface HistoryApplicationQuery extends HistoryQuery {
211
- readonly since?: number;
212
- readonly at?: readonly ActivityId[];
213
- readonly contextBefore?: number;
214
- readonly contextAfter?: number;
215
- }
216
- export interface HistoryApplicationData {
217
- readonly activities: readonly Activity[];
218
- }
219
- export interface ListeningData {
220
- readonly listening: readonly string[];
221
- }
222
- export interface LifecycleData {
223
- readonly activity: Activity;
224
- }
225
197
  export type ParticipantPresence = 'never-joined' | 'active' | 'watching' | 'done';
226
- /** Canonical public participant fields; status excludes never-joined roster entries. */
227
198
  export interface ParticipantSummary {
228
199
  readonly name: string;
229
200
  readonly state: 'active' | 'done' | 'not joined';
@@ -234,7 +205,10 @@ export interface ParticipantSummary {
234
205
  readonly unreadActivityCount: number;
235
206
  readonly pendingMentionCount: number;
236
207
  }
237
- export interface StatusApplicationData {
208
+ export interface StatusOptions extends ObservationOptions {
209
+ readonly viewer?: string;
210
+ }
211
+ export interface StatusResult {
238
212
  readonly hardCap: number | null;
239
213
  readonly activeCount: number;
240
214
  readonly doneCount: number;
@@ -247,13 +221,13 @@ export interface StatusApplicationData {
247
221
  readonly at?: number;
248
222
  } | null;
249
223
  readonly latestActivity?: Activity;
224
+ readonly observation?: StatusObservation;
250
225
  }
251
- export interface ParticipantsApplicationData {
226
+ export interface ParticipantsResult {
252
227
  readonly participants: readonly ParticipantSummary[];
228
+ readonly observation?: ParticipantsObservation;
253
229
  }
254
- export type DiagnosisApplicationData = DiagnoseResult;
255
- export type MigrationApplicationData = MigrationOutcome;
256
- export interface DiscoveryApplicationOptions {
230
+ export interface DiscoveryOptions {
257
231
  readonly depth?: number;
258
232
  readonly limit?: number;
259
233
  readonly after?: string;
@@ -265,21 +239,14 @@ export interface SquareListItem {
265
239
  readonly participants: readonly string[];
266
240
  readonly activities: number;
267
241
  }
268
- export interface DiscoveryApplicationData {
242
+ export interface DiscoveryResult {
269
243
  readonly items: readonly SquareListItem[];
270
244
  readonly stopped: boolean;
271
- /** All discovered squares before applying the cursor or page limit. */
272
245
  readonly total: number;
273
246
  readonly remaining: number;
274
247
  readonly next?: string;
275
248
  }
276
- export interface DiscoveryProjection {
277
- readonly cwd: string;
278
- readonly now: number;
279
- readonly depth: number;
280
- readonly limit: number;
281
- }
282
- export interface InboxApplicationOptions {
249
+ export interface InboxOptions {
283
250
  readonly limit?: number;
284
251
  }
285
252
  export interface InboxMembershipSummary {
@@ -287,16 +254,11 @@ export interface InboxMembershipSummary {
287
254
  readonly squarePath: string;
288
255
  readonly pending: number;
289
256
  }
290
- export interface InboxApplicationData {
257
+ export interface InboxResult {
291
258
  readonly rows: readonly InboxMembershipSummary[];
292
259
  readonly total: number;
293
260
  }
294
- export interface InboxProjection {
295
- readonly sessionId: string;
296
- readonly now: number;
297
- readonly limit: number;
298
- }
299
- export interface RecoveryApplicationData {
261
+ export interface RecoveryResult {
300
262
  readonly participant?: string;
301
263
  readonly standingCount?: number;
302
264
  readonly held?: boolean;
@@ -306,7 +268,6 @@ export interface RecoveryApplicationData {
306
268
  readonly roster?: readonly string[];
307
269
  readonly activitySummaries?: readonly UnreadActivitySummary[];
308
270
  }
309
- export type RecoveryProjection = RecoveryApplicationData & Partial<SquareContextProjection>;
310
271
  export type StreamStart = {
311
272
  readonly kind: 'tail';
312
273
  readonly last: number;
@@ -314,11 +275,11 @@ export type StreamStart = {
314
275
  readonly kind: 'after';
315
276
  readonly after: number;
316
277
  };
317
- export interface StreamApplicationOptions {
278
+ export interface StreamOptions {
318
279
  readonly recipient?: string;
319
280
  readonly start?: StreamStart;
320
281
  }
321
- export type StreamApplicationRecord = ArchiveRecord & {
282
+ export type StreamRecord = ArchiveRecord & {
322
283
  readonly seq: number;
323
284
  readonly square: string;
324
285
  readonly route?: string;
@@ -336,33 +297,13 @@ export interface UnreadActivitySummary {
336
297
  readonly latestActivityAgeMs: number;
337
298
  readonly previews: readonly UnreadActivityPreview[];
338
299
  }
339
- /** Selected-row observations. participantCount in these existing concern DTOs is a standing count. */
340
- export interface RecoveryObservation {
341
- readonly name: string;
342
- readonly roster: readonly string[];
343
- readonly activitySummaries: readonly UnreadActivitySummary[];
344
- readonly participantCount: number;
345
- readonly held: boolean;
346
- readonly holdReason?: string;
347
- readonly ownActivityCount: number;
348
- readonly hardCap: number | null;
349
- }
350
300
  export interface EntryPresentation {
351
- readonly joined: boolean;
352
301
  readonly joinedBefore: boolean;
353
302
  readonly scene: string;
354
- readonly context: string;
355
303
  readonly joinContext: string;
356
304
  readonly recentActivities: readonly ArchiveRecord[];
357
305
  readonly perceptions: Readonly<Record<number, Perception>>;
358
306
  readonly sayNumbers: Readonly<Record<number, number>>;
359
- readonly participantCount: number;
360
- readonly held: boolean;
361
- }
362
- export interface HistoryContinuation {
363
- readonly direction: 'before' | 'after';
364
- readonly cursor: ActivityId;
365
- readonly limit: number;
366
307
  }
367
308
  export interface ListPresentation {
368
309
  readonly context: readonly string[];
@@ -370,7 +311,6 @@ export interface ListPresentation {
370
311
  readonly activities: number;
371
312
  }
372
313
  export interface PresenceClassification {
373
- /** Names in canonical data, watching first, then recent signs of life; no presentation clipping. */
374
314
  readonly orderedHereNames: readonly string[];
375
315
  readonly lingeringCount: number;
376
316
  readonly classificationByName: Readonly<Record<string, 'here' | 'lingering' | 'done' | 'not-joined'>>;
@@ -387,54 +327,61 @@ export interface StreamProjection {
387
327
  readonly cursor: number;
388
328
  readonly hasMore: boolean;
389
329
  }
390
- export interface EntryProjection extends SquareContextProjection, EntryPresentation {
330
+ export interface SquareObservation {
331
+ readonly location: string;
332
+ readonly standingCount: number;
333
+ readonly held: boolean;
334
+ readonly now: number;
335
+ readonly participant?: string;
336
+ readonly automaticDeliveryAvailable: boolean;
337
+ }
338
+ export interface JoinObservation extends SquareObservation {
339
+ readonly entry?: EntryPresentation;
340
+ /** The receipt succeeded, but optional recent-history/context enrichment was unavailable. */
341
+ readonly enrichmentUnavailable?: true;
391
342
  }
392
- export interface ExpressionObservation extends Pick<SquareContextProjection, 'standingCount' | 'held' | 'now'> {
343
+ export interface ExpressionObservation extends Pick<SquareObservation, 'standingCount' | 'held' | 'now'> {
393
344
  readonly ownActivityCount: number;
394
345
  readonly hardCap: number | null;
395
346
  }
396
- export interface ExpressProjection extends SquareContextProjection, ExpressionObservation {
347
+ export interface ExpressObservation extends SquareObservation, ExpressionObservation {
397
348
  readonly participant: string;
398
349
  readonly pendingPublic: readonly ArchiveRecord[];
399
350
  readonly sayNumbers: Readonly<Record<number, number>>;
400
351
  readonly perceptions: Readonly<Record<number, Perception>>;
401
352
  readonly reentry?: Activity;
402
- readonly delivery?: DeliveryResult;
403
353
  }
404
- export interface CatchProjection extends SquareContextProjection, ExpressionObservation {
354
+ export interface CatchObservation extends SquareObservation, ExpressionObservation {
405
355
  readonly participant: string;
406
356
  readonly sayNumbers: Readonly<Record<number, number>>;
407
- /** Optional nearby presence is not a commit-time selection fact. */
408
357
  readonly presence?: CatchPresence;
409
358
  readonly stop?: CatchStopStatus;
410
359
  readonly waitStarted?: boolean;
411
360
  readonly replaced?: boolean;
412
361
  readonly enrichmentUnavailable?: true;
413
362
  }
414
- export interface HistoryProjection extends SquareContextProjection {
363
+ export interface HistoryContinuation {
364
+ readonly direction: 'before' | 'after';
365
+ readonly cursor: ActivityId;
366
+ readonly limit: number;
367
+ }
368
+ export interface HistoryObservation extends SquareObservation {
415
369
  readonly activities: readonly ArchiveRecord[];
416
370
  readonly sayNumbers: Readonly<Record<number, number>>;
417
371
  readonly presenceAnchors: Readonly<Record<number, readonly string[]>>;
418
372
  readonly totalMatches: number;
419
- /** Ordinary terminal history visibility and stable continuation are owner policy. */
420
373
  readonly visibleActivities: readonly ArchiveRecord[];
421
374
  readonly continuation?: HistoryContinuation;
422
375
  }
423
- export interface ListenerProjection extends SquareContextProjection {
376
+ export interface ListenerObservation extends SquareObservation {
424
377
  readonly participant: string;
425
378
  readonly target: string;
426
379
  readonly requestedTarget: string;
427
380
  }
428
- export interface EventPresentation {
381
+ export interface LifecycleObservation extends SquareObservation {
429
382
  readonly activity: ArchiveRecord;
430
- readonly participantCount: number;
431
- readonly held: boolean;
432
- }
433
- export interface LifecycleProjection extends SquareContextProjection, EventPresentation {
434
- readonly delivery?: DeliveryResult;
435
383
  }
436
- export interface StatusProjection extends SquareContextProjection, PresenceClassification {
437
- /** Full roster size, including never-joined names omitted from status data. */
384
+ export interface StatusObservation extends SquareObservation, PresenceClassification {
438
385
  readonly knownParticipantCount: number;
439
386
  readonly latestActNumber?: number;
440
387
  readonly latestPerception?: Perception;
@@ -446,32 +393,5 @@ export interface StatusProjection extends SquareContextProjection, PresenceClass
446
393
  readonly attentionNames: readonly string[];
447
394
  readonly viewer: string;
448
395
  }
449
- export interface ParticipantsProjection extends SquareContextProjection, PresenceClassification {
450
- }
451
- export interface SquareApplication<Presentation extends boolean = true> {
452
- now(): number;
453
- build(input: BuildApplicationInput, control?: OperationControl): Promise<ApplicationOutcome<BuildApplicationData, SquareContextProjection, Presentation>>;
454
- join(options?: JoinApplicationOptions, control?: OperationControl): Promise<ApplicationOutcome<JoinApplicationData, EntryProjection, Presentation>>;
455
- express(body: string, options?: ExpressApplicationOptions, control?: OperationControl): Promise<ApplicationOutcome<ExpressApplicationData, ExpressProjection, Presentation>>;
456
- catch(options?: CatchApplicationOptions, control?: OperationControl): Promise<ApplicationOutcome<CatchApplicationData, CatchProjection, Presentation>>;
457
- history(query?: HistoryApplicationQuery, control?: OperationControl): Promise<ApplicationOutcome<HistoryApplicationData, HistoryProjection, Presentation>>;
458
- listen(target: string, control?: OperationControl): Promise<ApplicationOutcome<ListenerChangeData, ListenerProjection, Presentation>>;
459
- ignore(target: string, control?: OperationControl): Promise<ApplicationOutcome<ListenerChangeData, ListenerProjection, Presentation>>;
460
- listening(control?: OperationControl): Promise<ApplicationOutcome<ListeningData, SquareContextProjection, Presentation>>;
461
- hold(reason?: string, control?: OperationControl): Promise<ApplicationOutcome<LifecycleData, LifecycleProjection, Presentation>>;
462
- resume(control?: OperationControl): Promise<ApplicationOutcome<LifecycleData, LifecycleProjection, Presentation>>;
463
- done(body?: string, control?: OperationControl): Promise<ApplicationOutcome<LifecycleData, LifecycleProjection, Presentation>>;
464
- status(viewer?: string, control?: OperationControl): Promise<ApplicationOutcome<StatusApplicationData, StatusProjection, Presentation>>;
465
- participants(control?: OperationControl): Promise<ApplicationOutcome<ParticipantsApplicationData, ParticipantsProjection, Presentation>>;
466
- diagnose(control?: OperationControl): Promise<ApplicationOutcome<DiagnosisApplicationData, Partial<SquareContextProjection>, Presentation>>;
467
- migrate(control?: OperationControl): Promise<ApplicationOutcome<MigrationApplicationData, Partial<SquareContextProjection>, Presentation>>;
468
- discover(options: DiscoveryApplicationOptions, control?: OperationControl): Promise<ApplicationOutcome<DiscoveryApplicationData, DiscoveryProjection, Presentation>>;
469
- inbox(sessionId: string, options?: InboxApplicationOptions, control?: OperationControl): Promise<ApplicationOutcome<InboxApplicationData, InboxProjection, Presentation>>;
470
- recovery(control?: OperationControl): Promise<ApplicationOutcome<RecoveryApplicationData, RecoveryProjection, Presentation>>;
471
- stream(options: StreamApplicationOptions, control?: OperationControl): AsyncIterable<StreamApplicationRecord>;
472
- }
473
- export type JoinApplicationResult = JoinApplicationData;
474
- export type ExpressApplicationResult = ExpressApplicationData;
475
- export type ApplicationStatus = StatusApplicationData;
476
- export type ApplicationStatusProjection = StatusProjection;
477
- export type ApplicationParticipants = ParticipantsApplicationData;
396
+ export interface ParticipantsObservation extends SquareObservation, PresenceClassification {
397
+ }
@@ -1,12 +1,13 @@
1
1
  import { z } from 'zod/v4';
2
- import type { ApplicationOutcome, OperationControl, SquareApplication } from './square-facade.js';
2
+ import type { Square } from './square-api.js';
3
+ import type { OperationControl } from './square-facade.js';
3
4
  type JsonObject = Record<string, unknown>;
4
- type Outcome = Promise<ApplicationOutcome<object, unknown, false>>;
5
+ type Outcome = Promise<object>;
5
6
  interface ToolDefinition {
6
7
  name: string;
7
8
  description: string;
8
9
  inputSchema: z.ZodObject<z.ZodRawShape>;
9
- run(app: SquareApplication<false>, args: JsonObject, control: OperationControl): Outcome;
10
+ run(square: Square, args: JsonObject, control: OperationControl): Outcome;
10
11
  }
11
12
  export declare const SQUARE_TOOL_INSTRUCTIONS = "The catch tool consumes activities. Use history with act/<index> cursors for read-only archive access.";
12
13
  export declare const SQUARE_TOOLS: readonly ToolDefinition[];
@@ -6,36 +6,42 @@ const activityId = z.string().regex(/^act\/(0|[1-9][0-9]*)$/);
6
6
  const stringArray = z.array(z.string());
7
7
  function tool(name, description, shape, run) {
8
8
  const inputSchema = z.object({ ...shape, location }).strict();
9
- return { name, description, inputSchema, run: (app, args, control) => {
9
+ return { name, description, inputSchema, run: (square, args, control) => {
10
10
  const { location: _location, ...operationArgs } = inputSchema.parse(args);
11
- return run(app, operationArgs, control);
11
+ return run(square, operationArgs, control);
12
12
  } };
13
13
  }
14
14
  export const SQUARE_TOOL_INSTRUCTIONS = 'The catch tool consumes activities. Use history with act/<index> cursors for read-only archive access.';
15
15
  export const SQUARE_TOOLS = [
16
- tool('join', 'Join the square as a participant.', { as: participant, takeover: z.boolean().optional().describe('Take the name from its current session owner.') }, (app, { takeover }, control) => app.join({ takeover }, control)),
17
- tool('express', 'Express a message or embodied action in the square. Mentions and replies direct attention; bell reaches everyone. Bare activity is valid even with no listeners.', {
16
+ tool('join', 'Join the square as a participant.', { as: participant, takeover: z.boolean().optional().describe('Take the name from its current session owner.') }, async (square, { as, takeover }, control) => {
17
+ const { participant, ...receipt } = await square.join(as, { takeover }, control);
18
+ return { ...receipt, participant: participant.name };
19
+ }),
20
+ tool('express', 'Express a message or embodied action in the square. Mentions and replies direct attention; bell reaches everyone and keeps body @names literal. Bell cannot combine with explicit mentions. Bare activity is valid even with no listeners.', {
18
21
  as: participant, body: z.string(), mentions: stringArray.optional(), reach: z.enum(['bell']).optional(),
19
22
  reply: activityId.optional(), noMention: z.boolean().optional().describe('Disable body @name scanning; explicit mentions and reply still apply.'),
20
23
  force: z.boolean().optional().describe('Speak without first catching unread activity or satisfying attention etiquette.'),
21
24
  noWait: z.boolean().optional().describe('Return an error rather than waiting when held or throttled.'),
22
- }, (app, { body, as: _participant, ...options }, control) => app.express(body, options, control)),
25
+ }, async (square, { body, as, ...options }, control) => {
26
+ const { delivery: _delivery, ...result } = await (await square.participant(as)).express(body, options, control);
27
+ return result;
28
+ }),
23
29
  tool('catch', 'Catch and consume activities perceptible to the participant. idle waits for relevant activity or this many milliseconds of quiet; omitted means immediate. id catches one activity and cannot be combined with filters, idle or limit.', {
24
30
  as: participant, id: activityId.optional(), idle: z.number().finite().min(0).optional(), from: stringArray.optional(),
25
31
  mention: z.boolean().optional(), limit: z.number().int().min(1).optional(),
26
- }, (app, { as: _participant, ...options }, control) => app.catch(options, control)),
32
+ }, async (square, { as, ...options }, control) => (await square.participant(as)).catch(options, control)),
27
33
  tool('history', 'Read the activity stream without consuming it, using stable activity-id cursors. Default page size is 10, maximum 100. grep is a regex; fixed is literal text; use only one.', {
28
34
  limit: z.number().int().min(1).optional(), order: z.enum(['asc', 'desc']).optional(), before: activityId.optional(), after: activityId.optional(),
29
35
  grep: z.string().optional(), fixed: z.string().optional(), from: stringArray.optional(), mention: z.string().optional(),
30
- }, (app, args, control) => app.history(args, control)),
31
- tool('listen', 'Listen for future bare activity from a participant, clearing any ignore of them.', { as: participant, target: z.string() }, (app, { target }, control) => app.listen(target, control)),
32
- tool('ignore', 'Block a participant’s future mentions and bare activity. Listening again clears the ignore; already landed activity is unchanged.', { as: participant, target: z.string() }, (app, { target }, control) => app.ignore(target, control)),
33
- tool('listening', 'List participants this participant is listening to.', { as: participant }, (app, _args, control) => app.listening(control)),
34
- tool('hold', 'Raise a hand to hold the square.', { as: participant, reason: z.string().optional() }, (app, { reason }, control) => app.hold(reason, control)),
35
- tool('resume', 'Release the current hold.', { as: participant }, (app, _args, control) => app.resume(control)),
36
- tool('done', 'Leave the square without adding a message.', { as: participant }, (app, _args, control) => app.done(undefined, control)),
37
- tool('status', 'Read the public status of the square.', {}, (app, _args, control) => app.status(undefined, control)),
38
- tool('participants', 'List participants standing in or done with the square.', {}, (app, _args, control) => app.participants(control)),
36
+ }, (square, args, control) => square.history(args, control)),
37
+ tool('listen', 'Listen for future bare activity from a participant, clearing any ignore of them.', { as: participant, target: z.string() }, async (square, { as, target }, control) => (await square.participant(as)).listen(target, {}, control)),
38
+ tool('ignore', 'Block a participant’s future mentions and bare activity. Listening again clears the ignore; already landed activity is unchanged.', { as: participant, target: z.string() }, async (square, { as, target }, control) => (await square.participant(as)).ignore(target, {}, control)),
39
+ tool('listening', 'List participants this participant is listening to.', { as: participant }, async (square, { as }, control) => (await square.participant(as)).listening({}, control)),
40
+ tool('hold', 'Raise a hand to hold the square.', { as: participant, reason: z.string().optional() }, async (square, { as, reason }, control) => (await square.participant(as)).hold(reason, {}, control)),
41
+ tool('resume', 'Release the current hold.', { as: participant }, async (square, { as }, control) => (await square.participant(as)).resume({}, control)),
42
+ tool('done', 'Leave the square without adding a message.', { as: participant }, async (square, { as }, control) => (await square.participant(as)).done(undefined, {}, control)),
43
+ tool('status', 'Read the public status of the square.', {}, (square, _args, control) => square.status({}, control)),
44
+ tool('participants', 'List participants standing in or done with the square.', {}, (square, _args, control) => square.participants({}, control)),
39
45
  ];
40
46
  export function squareToolFailure(error, signal) {
41
47
  const normalized = signal?.aborted
package/dist/stream.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import type { OpenOptions, OperationControl, StreamApplicationOptions, StreamApplicationRecord } from './square-facade.js';
1
+ import type { OpenOptions, OperationControl, StreamOptions, StreamRecord } from './square-facade.js';
2
2
  /** Pull-based observation; return interrupts an outstanding pull before awaiting its cleanup. */
3
- export declare function streamSquare(squarePath: string, options?: StreamApplicationOptions, control?: OperationControl, openOptions?: OpenOptions): AsyncIterable<StreamApplicationRecord>;
3
+ export declare function streamSquare(squarePath: string, options?: StreamOptions, control?: OperationControl, openOptions?: OpenOptions): AsyncIterable<StreamRecord>;