@astrosheep/square 0.3.70 → 0.3.72

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 (126) hide show
  1. package/dist/activity-feed.d.ts +4 -5
  2. package/dist/activity-feed.js +14 -10
  3. package/dist/artifact.d.ts +26 -33
  4. package/dist/artifact.js +346 -317
  5. package/dist/attention-presentation.js +2 -9
  6. package/dist/automatic-session.js +6 -6
  7. package/dist/boundary-presentation.js +3 -3
  8. package/dist/catch-decisions.d.ts +19 -12
  9. package/dist/catch-decisions.js +32 -68
  10. package/dist/claude-delivery.js +7 -7
  11. package/dist/claude-mod.js +18 -7
  12. package/dist/cli/catch-presentation.d.ts +7 -0
  13. package/dist/cli/catch-presentation.js +55 -0
  14. package/dist/cli/context.d.ts +1 -1
  15. package/dist/cli/context.js +5 -23
  16. package/dist/cli/express-presentation.d.ts +10 -0
  17. package/dist/cli/express-presentation.js +196 -0
  18. package/dist/cli/maintenance-commands.d.ts +4 -0
  19. package/dist/cli/maintenance-commands.js +29 -6
  20. package/dist/cli/observation-commands.d.ts +7 -5
  21. package/dist/cli/observation-commands.js +275 -262
  22. package/dist/cli/program.d.ts +1 -1
  23. package/dist/cli/program.js +43 -56
  24. package/dist/cli/registry.js +2 -1
  25. package/dist/cli/square-commands.d.ts +3 -9
  26. package/dist/cli/square-commands.js +134 -255
  27. package/dist/codex-queue.js +4 -1
  28. package/dist/decisions.d.ts +26 -74
  29. package/dist/decisions.js +190 -335
  30. package/dist/delivery-health.js +13 -22
  31. package/dist/delivery-operations.d.ts +0 -11
  32. package/dist/delivery-operations.js +44 -33
  33. package/dist/delivery.d.ts +33 -32
  34. package/dist/delivery.js +70 -81
  35. package/dist/help.js +6 -1
  36. package/dist/inbox.d.ts +27 -0
  37. package/dist/inbox.js +55 -18
  38. package/dist/index.d.ts +2 -4
  39. package/dist/index.js +1 -1
  40. package/dist/list.d.ts +7 -1
  41. package/dist/list.js +49 -122
  42. package/dist/mcp.d.ts +1 -1
  43. package/dist/mcp.js +7 -37
  44. package/dist/model.d.ts +4 -44
  45. package/dist/model.js +1 -3
  46. package/dist/notifications.d.ts +1 -1
  47. package/dist/notifications.js +13 -7
  48. package/dist/open-square.d.ts +16 -2
  49. package/dist/open-square.js +40 -1
  50. package/dist/packages/agent-delivery/src/claude.d.ts +2 -11
  51. package/dist/packages/agent-delivery/src/index.d.ts +2 -42
  52. package/dist/packages/agent-delivery/src/opencode.d.ts +2 -11
  53. package/dist/packages/agent-delivery/src/paseo.d.ts +2 -13
  54. package/dist/packages/agent-delivery/src/pi-client.d.ts +2 -9
  55. package/dist/packages/agent-delivery/src/types.d.ts +42 -0
  56. package/dist/participant-host.d.ts +6 -3
  57. package/dist/participant-host.js +44 -38
  58. package/dist/perception-projection.d.ts +6 -15
  59. package/dist/perception-projection.js +6 -26
  60. package/dist/plugins/opencode/delivery.js +9 -9
  61. package/dist/plugins/opencode/index.js +3 -3
  62. package/dist/ports.d.ts +156 -11
  63. package/dist/presentation-operations.d.ts +1 -1
  64. package/dist/presentation-operations.js +35 -44
  65. package/dist/presentation.d.ts +12 -19
  66. package/dist/presentation.js +33 -54
  67. package/dist/registry.d.ts +2 -0
  68. package/dist/registry.js +1 -1
  69. package/dist/routes.d.ts +7 -14
  70. package/dist/routes.js +34 -72
  71. package/dist/runtime.d.ts +12 -39
  72. package/dist/runtime.js +33 -164
  73. package/dist/square-actions.d.ts +11 -21
  74. package/dist/square-actions.js +171 -275
  75. package/dist/square-application.d.ts +31 -55
  76. package/dist/square-application.js +625 -141
  77. package/dist/square-core.d.ts +3 -94
  78. package/dist/square-core.js +8 -353
  79. package/dist/square-domain.d.ts +24 -0
  80. package/dist/square-domain.js +77 -0
  81. package/dist/square-facade.d.ts +360 -9
  82. package/dist/square-migration.d.ts +24 -0
  83. package/dist/square-migration.js +211 -0
  84. package/dist/square-projections.d.ts +2 -42
  85. package/dist/square-projections.js +1 -37
  86. package/dist/square-sqlite.d.ts +59 -0
  87. package/dist/square-sqlite.js +702 -0
  88. package/dist/stream.d.ts +3 -10
  89. package/dist/stream.js +81 -52
  90. package/dist/views.d.ts +27 -95
  91. package/dist/views.js +217 -87
  92. package/dist/wake-eligibility.d.ts +15 -5
  93. package/dist/wake-eligibility.js +32 -16
  94. package/dist/wakes.d.ts +3 -3
  95. package/dist/wakes.js +31 -27
  96. package/guides/application-facade-delivery-evidence.md +200 -0
  97. package/guides/application-facade-design.md +95 -0
  98. package/guides/change-waits.md +4 -4
  99. package/guides/migration.md +77 -0
  100. package/guides/postcommit-simplification-performance.md +36 -0
  101. package/guides/primitive-catch-consolidation.md +85 -0
  102. package/guides/primitive-history-consolidation.md +76 -0
  103. package/guides/primitive-status-consolidation.md +87 -0
  104. package/guides/primitive-storage-consolidation.md +128 -0
  105. package/guides/row-runtime-delivery-evidence.md +160 -0
  106. package/guides/row-storage-design.md +567 -0
  107. package/package.json +1 -1
  108. package/plugins/claude/.claude-plugin/plugin.json +1 -1
  109. package/plugins/codex/.codex-plugin/plugin.json +1 -1
  110. package/plugins/opencode/delivery.ts +11 -11
  111. package/plugins/opencode/index.ts +3 -3
  112. package/plugins/paseo/client/square-message.tsx +77 -64
  113. package/plugins/paseo/shared/message.ts +16 -0
  114. package/plugins/pi/square-pi.js +5 -1
  115. package/dist/activity.d.ts +0 -14
  116. package/dist/activity.js +0 -248
  117. package/dist/square-file-adapter.d.ts +0 -26
  118. package/dist/square-file-adapter.js +0 -85
  119. package/dist/square-state.d.ts +0 -6
  120. package/dist/square-state.js +0 -138
  121. package/dist/square-storage.d.ts +0 -14
  122. package/dist/square-storage.js +0 -188
  123. package/dist/square-wiring.d.ts +0 -33
  124. package/dist/square-wiring.js +0 -109
  125. package/dist/watch.d.ts +0 -8
  126. package/dist/watch.js +0 -252
package/dist/stream.d.ts CHANGED
@@ -1,10 +1,3 @@
1
- export type StreamStart = {
2
- readonly kind: 'tail';
3
- readonly last: number;
4
- } | {
5
- readonly kind: 'after';
6
- readonly after: number;
7
- };
8
- /** Machine-readable tailing stays available; interactive terminal rendering was retired. */
9
- export declare function cmdStreamNdjson(squarePath: string, recipient?: string, start?: StreamStart): Promise<void>;
10
- export declare function cmdStream(squarePath: string): Promise<void>;
1
+ import type { OpenOptions, OperationControl, StreamApplicationOptions, StreamApplicationRecord } from './square-facade.js';
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>;
package/dist/stream.js CHANGED
@@ -1,59 +1,88 @@
1
- import fs from 'node:fs';
2
- import path from 'node:path';
3
- import { once } from 'node:events';
4
- import { quoteShell } from './presentation.js';
5
- import { openSquare, observeSquareChanges } from './square-file-adapter.js';
6
- import { closeOpenSquare } from './open-square.js';
1
+ import fs from 'node:fs/promises';
2
+ import { SquareError } from './model.js';
3
+ import { observeSquareRevision } from './artifact.js';
4
+ import { openSquare, closeOpenSquare } from './open-square.js';
7
5
  import { streamProjection, streamTailProjection } from './views.js';
8
- /** Machine-readable tailing stays available; interactive terminal rendering was retired. */
9
- export async function cmdStreamNdjson(squarePath, recipient, start = { kind: 'tail', last: 10 }) {
10
- if (!fs.existsSync(squarePath)) {
11
- process.stderr.write(`square not found: ${squarePath}\n`);
12
- process.exitCode = 2;
13
- return;
14
- }
15
- let cursor = start.kind === 'after' ? start.after : -1;
16
- let initial = start.kind === 'tail' ? start : undefined;
17
- const observer = await observeSquareChanges(squarePath);
18
- try {
19
- while (true) {
20
- const generation = observer.generation;
21
- try {
22
- const baseline = await observer.read();
23
- const square = await openSquare(squarePath);
24
- let hasMore;
6
+ /** Pull-based observation; return interrupts an outstanding pull before awaiting its cleanup. */
7
+ export function streamSquare(squarePath, options = {}, control, openOptions = {}) {
8
+ return {
9
+ [Symbol.asyncIterator]() {
10
+ const disposal = new AbortController();
11
+ const signal = control?.signal === undefined ? disposal.signal : AbortSignal.any([control.signal, disposal.signal]);
12
+ const iterationControl = { ...control, signal };
13
+ const records = observe();
14
+ return {
15
+ next: () => records.next(),
16
+ return() {
17
+ disposal.abort();
18
+ return records.return(undefined);
19
+ },
20
+ };
21
+ async function* observe() {
25
22
  try {
26
- const projection = initial === undefined
27
- ? await streamProjection(square, cursor, recipient)
28
- : await streamTailProjection(square, initial.last, recipient);
29
- for (const item of projection.activities) {
30
- const line = { seq: item.activity.index, square: squarePath, ...item.activity,
31
- ...(item.route === undefined ? {} : { route: item.route }) };
32
- if (!process.stdout.write(`${JSON.stringify(line)}\n`))
33
- await once(process.stdout, 'drain');
23
+ signal.throwIfAborted();
24
+ try {
25
+ await fs.stat(squarePath);
26
+ }
27
+ catch {
28
+ signal.throwIfAborted();
29
+ throw new SquareError('unavailable', `Square is unavailable at ${squarePath}`);
30
+ }
31
+ signal.throwIfAborted();
32
+ const start = options.start ?? { kind: 'tail', last: 10 };
33
+ let cursor = start.kind === 'after' ? start.after : -1;
34
+ let initial = start.kind === 'tail' ? start : undefined;
35
+ const observer = await observeSquareRevision(squarePath);
36
+ const close = () => observer.close();
37
+ signal.addEventListener('abort', close, { once: true });
38
+ try {
39
+ signal.throwIfAborted();
40
+ while (true) {
41
+ const generation = observer.generation;
42
+ let baseline;
43
+ let projection;
44
+ try {
45
+ baseline = await observer.read(signal);
46
+ const square = await openSquare(squarePath, { ...openOptions, env: openOptions.env ?? {}, signal }, iterationControl);
47
+ try {
48
+ projection = initial === undefined
49
+ ? await streamProjection(square, cursor, options.recipient, iterationControl)
50
+ : await streamTailProjection(square, initial.last, options.recipient, iterationControl);
51
+ }
52
+ finally {
53
+ await closeOpenSquare(square);
54
+ }
55
+ }
56
+ catch (error) {
57
+ signal.throwIfAborted();
58
+ if (error instanceof SquareError && error.code === 'invalid_args')
59
+ throw error;
60
+ // Repair/replacement is a hint, not a reason to scan history on a timer.
61
+ await observer.hinted(generation, Infinity, signal);
62
+ continue;
63
+ }
64
+ for (const item of projection.activities) {
65
+ signal.throwIfAborted();
66
+ yield { seq: item.activity.index, square: squarePath, ...item.activity,
67
+ ...(item.route === undefined ? {} : { route: item.route }) };
68
+ }
69
+ cursor = projection.cursor;
70
+ initial = undefined;
71
+ if (!projection.hasMore)
72
+ await observer.changed(baseline, Infinity, signal);
73
+ }
74
+ }
75
+ finally {
76
+ signal.removeEventListener('abort', close);
77
+ observer.close();
34
78
  }
35
- cursor = projection.cursor;
36
- initial = undefined;
37
- hasMore = projection.hasMore;
38
79
  }
39
- finally {
40
- await closeOpenSquare(square);
80
+ catch (error) {
81
+ // Iterator disposal is completion; a caller cancellation still rejects the pull.
82
+ if (!disposal.signal.aborted || control?.signal?.aborted || error !== signal.reason)
83
+ throw error;
41
84
  }
42
- if (!hasMore)
43
- await observer.changed(baseline, Infinity);
44
85
  }
45
- catch {
46
- // Repair/replacement is a storage hint, not a reason to scan history on a timer.
47
- await observer.hinted(generation, Infinity);
48
- }
49
- }
50
- }
51
- finally {
52
- observer.close();
53
- }
54
- }
55
- export async function cmdStream(squarePath) {
56
- process.stderr.write('✕ interactive stream was removed\n');
57
- process.stderr.write(`square --location ${quoteShell(path.resolve(squarePath))} stream --ndjson\n`);
58
- process.exitCode = 2;
86
+ },
87
+ };
59
88
  }
package/dist/views.d.ts CHANGED
@@ -1,105 +1,37 @@
1
1
  import { type ActivityId } from './square-core.js';
2
- import { coreParticipants, coreStatus } from './decisions.js';
3
- import { type DeliveryModel, type PlannedNotification } from './delivery.js';
4
- import { type ActivitiesOptions, type PublicAct, type SquareState, type StoredAct } from './model.js';
2
+ import { type StoredAct } from './model.js';
5
3
  import type { OpenSquare } from './open-square.js';
6
- import type { Activity, HistoryQuery, OperationControl, ParticipantStatus, SquareSnapshot } from './square-facade.js';
7
- export interface ActivityPresentation {
8
- readonly name: string;
9
- readonly roster: readonly string[];
10
- readonly pendingPublic: readonly PublicAct[];
11
- readonly activities: readonly StoredAct[];
12
- readonly state: SquareState;
13
- readonly participantCount: number;
14
- readonly held: boolean;
15
- readonly holdReason?: string;
16
- readonly ownActivityCount: number;
17
- readonly hardCap: number | null;
18
- }
19
- export interface EntryPresentation {
20
- readonly joined: boolean;
21
- readonly scene: string;
22
- readonly context: string;
23
- readonly joinContext: string;
24
- readonly recentActivities: readonly StoredAct[];
25
- readonly state: SquareState;
26
- readonly sayNumbers: Readonly<Record<number, number>>;
27
- readonly participantCount: number;
28
- }
29
- export interface HistoryPresentation {
30
- readonly activities: readonly StoredAct[];
31
- readonly sayNumbers: Readonly<Record<number, number>>;
32
- readonly presenceAnchors: Readonly<Record<number, readonly string[]>>;
33
- readonly participantCount: number;
34
- }
35
- export interface ListPresentation {
36
- readonly context: readonly string[];
37
- readonly participants: readonly string[];
38
- readonly activities: number;
39
- }
40
- export interface StatusPresentation {
41
- readonly state: SquareState;
42
- readonly status: ReturnType<typeof coreStatus>;
43
- readonly latestActNumber?: number;
44
- }
45
- export interface WatchPresentation {
46
- readonly activities: readonly StoredAct[];
47
- readonly state: SquareState;
48
- readonly participantCount: number;
49
- readonly presence: {
50
- readonly participants: ReturnType<typeof coreParticipants>;
51
- readonly now: number;
52
- };
53
- readonly terminalStatus?: 'capped' | 'quorum';
54
- }
55
- export interface StreamProjection {
56
- readonly activities: readonly {
57
- readonly activity: StoredAct;
58
- readonly route?: string;
59
- }[];
60
- readonly cursor: number;
61
- readonly hasMore: boolean;
62
- }
63
- export interface PendingDeliveryProjection {
64
- readonly recipient: string;
65
- readonly notifications: readonly PlannedNotification[];
66
- }
4
+ import type { ActivityFilter, SquareRead } from './ports.js';
5
+ import type { Activity, ApplicationOutcome, ArchiveRecord, HistoryQuery, HistoryApplicationQuery, HistoryContinuation, OperationControl, ParticipantStatus, ParticipantsApplicationData, ParticipantsProjection, SquareSnapshot, RecoveryObservation, EntryPresentation, ListPresentation, StatusApplicationData, StatusProjection, SquareContextProjection, CatchPresence, StreamProjection, EventPresentation } from './square-facade.js';
6
+ export type { RecoveryObservation, EntryPresentation, ListPresentation, CatchPresence, StreamProjection } from './square-facade.js';
7
+ export declare const HISTORY_DEFAULT_LIMIT = 10;
8
+ export declare const HISTORY_MAX_LIMIT = 100;
9
+ export declare const NON_READ: readonly ["join", "done", "say", "hold", "resume", "listen", "ignore"];
67
10
  /** The one StoredAct-to-public-Activity field mapping. Rejects read and actorless acts. */
68
11
  export declare function toPublicActivity(stored: StoredAct): Activity;
69
12
  export declare function parseRequiredActivityId(id: ActivityId): number;
13
+ /** Compile the public query directly to typed selectors; only search hydrates unselected bodies. */
14
+ export declare function selectHistory(facts: SquareRead, query: HistoryApplicationQuery, limit: number | null, kinds: ActivityFilter['kinds']): {
15
+ continuation?: HistoryContinuation | undefined;
16
+ activities: StoredAct[];
17
+ visibleActivities: StoredAct[];
18
+ totalMatches: number;
19
+ };
20
+ export declare function publicActivities(activities: readonly ArchiveRecord[]): Activity[];
70
21
  export declare function history(square: OpenSquare, query?: HistoryQuery, control?: OperationControl): Promise<Activity[]>;
71
- export declare function participantHistory(square: OpenSquare, _name: string, query?: HistoryQuery, control?: OperationControl): Promise<Activity[]>;
72
22
  export declare function resolveParticipant(square: OpenSquare, name: string, control?: OperationControl): Promise<{
73
- readonly name: string;
74
- readonly roster: readonly string[];
23
+ name: string;
75
24
  }>;
76
- export declare function currentParticipant(square: OpenSquare, name: string): Promise<string | undefined>;
25
+ export declare function currentParticipant(square: OpenSquare, name: string, control?: OperationControl): Promise<string | undefined>;
77
26
  export declare function participants(square: OpenSquare): Promise<ParticipantStatus[]>;
78
27
  export declare function snapshot(square: OpenSquare, control?: OperationControl): Promise<SquareSnapshot>;
79
- export declare function activityPresentation(square: OpenSquare, name: string): Promise<ActivityPresentation>;
80
- export declare function entryPresentation(square: OpenSquare, name: string, lastN?: number | null): Promise<EntryPresentation>;
81
- export declare function historyPresentation(square: OpenSquare, options: ActivitiesOptions): Promise<HistoryPresentation>;
82
- export declare function participantsPresentation(square: OpenSquare): Promise<ReturnType<typeof coreParticipants>>;
83
- export declare function listPresentation(square: OpenSquare): Promise<ListPresentation>;
84
- export declare function statusPresentation(square: OpenSquare): Promise<StatusPresentation>;
85
- export declare function eventPresentation(square: OpenSquare, id: ActivityId): Promise<{
86
- readonly activity: StoredAct;
87
- readonly participantCount: number;
88
- readonly held: boolean;
89
- }>;
90
- export declare function watchPresentation(square: OpenSquare, name: string): Promise<WatchPresentation>;
91
- export declare function streamProjection(square: OpenSquare | {
92
- readonly cell: {
93
- read(): Promise<{
94
- state: SquareState;
95
- }>;
96
- };
97
- }, cursor: number, recipient?: string): Promise<StreamProjection>;
98
- export declare function streamTailProjection(square: OpenSquare | {
99
- readonly cell: {
100
- read(): Promise<{
101
- state: SquareState;
102
- }>;
103
- };
104
- }, last?: number, recipient?: string): Promise<StreamProjection>;
105
- export declare function pendingDeliveriesFromState(state: SquareState, delivery?: DeliveryModel): readonly PendingDeliveryProjection[];
28
+ export declare function recoveryObservation(square: OpenSquare, name: string, control?: OperationControl): Promise<RecoveryObservation>;
29
+ export declare function entryPresentation(square: OpenSquare, name: string, lastN?: number | null, control?: OperationControl): Promise<EntryPresentation>;
30
+ type ParticipantQueryContext = Pick<SquareContextProjection, 'location' | 'now' | 'automaticDeliveryAvailable'>;
31
+ export declare function queryParticipants(facts: SquareRead, context: ParticipantQueryContext): ApplicationOutcome<ParticipantsApplicationData, ParticipantsProjection>;
32
+ export declare function listPresentation(square: OpenSquare, control?: OperationControl): Promise<ListPresentation>;
33
+ export declare function queryStatus(facts: SquareRead, context: ParticipantQueryContext, viewer?: string): ApplicationOutcome<StatusApplicationData, StatusProjection>;
34
+ export declare function eventPresentation(square: OpenSquare, id: ActivityId, control?: OperationControl): Promise<EventPresentation>;
35
+ export declare function catchPresence(square: OpenSquare, control?: OperationControl): Promise<CatchPresence>;
36
+ export declare function streamProjection(square: OpenSquare, cursor: number, recipient?: string, control?: OperationControl): Promise<StreamProjection>;
37
+ export declare function streamTailProjection(square: OpenSquare, last?: number, recipient?: string, control?: OperationControl): Promise<StreamProjection>;