@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/watch.js DELETED
@@ -1,252 +0,0 @@
1
- import { isSquareError, } from './model.js';
2
- import { STALE_MS, WATCH_HEARTBEAT_MS, countSays, inSquareCount, nowMs, } from './runtime.js';
3
- import { openSquare } from './square-file-adapter.js';
4
- import { closeOpenSquare } from './open-square.js';
5
- import { createSquareApplication } from './square-application.js';
6
- import { resolveParticipant, watchPresentation } from './views.js';
7
- import { acquireWatchLease, ownsWatchLease, pulseWatchLease, releaseWatchLease } from './wakes.js';
8
- import { renderWatchForceTakeover, renderWatchAlreadyActive, renderWatchReplaceMissing, renderWatchOutput, renderWatchReplaced, renderWatchStatus, formatRefusal, participantCommandPrefix, joinRecoveryCommand, participantsRecoveryCommand, withPathOutput, } from './presentation.js';
9
- import { hasAutomaticDeliveryIdentity } from './registry.js';
10
- import { parseActivityId } from './square-core.js';
11
- function watchStatusExitCode(status) {
12
- return status === 'capped' ? 1 : 0;
13
- }
14
- function leaseId() {
15
- return `watch_${process.pid}_${Date.now()}_${Math.random().toString(36).slice(2)}`;
16
- }
17
- function watchOutputResult(squarePath, presentation, name, caught, opts = {}) {
18
- const delivered = caught.activities.flatMap((activity) => {
19
- const index = parseActivityId(activity.id);
20
- const stored = index === undefined ? undefined : presentation.activities.find((item) => item.index === index);
21
- return stored === undefined ? [] : [{ activity: stored, perception: activity.perception }];
22
- });
23
- // Catch delivers only directed say activities, so there is no lifecycle list to split off.
24
- const publicItems = delivered.map(({ activity }) => activity).filter((item) => item.kind === 'say' || item.kind === 'done');
25
- const perceptions = new Map(delivered.map(({ activity, perception }) => [activity.index, perception]));
26
- return {
27
- type: 'output',
28
- stdout: renderWatchOutput([...presentation.activities], publicItems, {
29
- ...opts,
30
- viewer: name,
31
- perceptions,
32
- }) + (caught.remaining > 0
33
- ? `\n○ ${caught.remaining} matching ${caught.remaining === 1 ? 'activity remains' : 'activities remain'}\n${catchContinuationCommand(squarePath, name, opts)}`
34
- : ''),
35
- remaining: caught.remaining,
36
- ...(opts.status ? { status: opts.status } : {}),
37
- };
38
- }
39
- function catchContinuationCommand(squarePath, name, opts) {
40
- const args = ['--now'];
41
- if (opts.participants !== undefined && opts.participants.length > 0)
42
- args.push('--from', opts.participants.join(','));
43
- if (opts.mention !== undefined)
44
- args.push('--mention');
45
- if (opts.limit !== undefined)
46
- args.push('--limit', String(opts.limit));
47
- return `${participantCommandPrefix(squarePath, name)} catch ${args.join(' ')}`;
48
- }
49
- function writeWatchOutput(squarePath, name, presentation, stdout, remaining, status, idleMs) {
50
- const headerOpts = { participantCount: presentation.participantCount };
51
- const showCatchHint = !hasAutomaticDeliveryIdentity();
52
- if (status) {
53
- process.stdout.write(withPathOutput(squarePath, [renderWatchStatus({ status, squarePath, name, idleMs, presence: presentation.presence, showCatchHint }), stdout.trimEnd()].filter(Boolean).join('\n\n').trimEnd(), headerOpts));
54
- return;
55
- }
56
- const fallback = showCatchHint && remaining === 0
57
- ? `${participantCommandPrefix(squarePath, name)} catch --idle 30m\n stay available for new activity`
58
- : '';
59
- process.stdout.write(withPathOutput(squarePath, [stdout.trimEnd(), fallback].filter(Boolean).join('\n\n').trimEnd(), headerOpts));
60
- }
61
- function writeWatchTerminal(squarePath, name, presentation, status, idleMs) {
62
- process.stdout.write(withPathOutput(squarePath, renderWatchStatus({
63
- status,
64
- squarePath,
65
- name,
66
- ...(idleMs === undefined ? {} : { idleMs }),
67
- presence: presentation.presence,
68
- showCatchHint: !hasAutomaticDeliveryIdentity(),
69
- ownActivityCount: countSays(presentation.state.acts, name),
70
- hardCap: presentation.state.hardCap,
71
- }), { participantCount: presentation.participantCount }));
72
- }
73
- function writeWatchReplaced(squarePath, name, presentation) {
74
- process.stdout.write(withPathOutput(squarePath, renderWatchReplaced({ squarePath, name }), { participantCount: presentation.participantCount }));
75
- }
76
- async function finishWatchResult(square, squarePath, name, result, leaseId, idleMs) {
77
- if (result.type === 'output') {
78
- await endWatch(square, name, leaseId);
79
- writeWatchOutput(squarePath, name, await watchPresentation(square, name), result.stdout, result.remaining, result.status);
80
- process.exitCode = watchStatusExitCode(result.status);
81
- return true;
82
- }
83
- if (result.type === 'terminal') {
84
- await endWatch(square, name, leaseId);
85
- writeWatchTerminal(squarePath, name, await watchPresentation(square, name), result.status, idleMs);
86
- process.exitCode = watchStatusExitCode(result.status);
87
- return true;
88
- }
89
- if (result.type === 'replaced') {
90
- writeWatchReplaced(squarePath, name, await watchPresentation(square, name));
91
- process.exitCode = 0;
92
- return true;
93
- }
94
- return false;
95
- }
96
- async function beginWatch(square, squarePath, name, opts) {
97
- const id = leaseId();
98
- return acquireWatchLease(square, name, id, opts);
99
- }
100
- async function endWatch(square, name, id) {
101
- await releaseWatchLease(square, name, id);
102
- }
103
- function installWatchInterruptHandler(square, squarePath, name, currentLeaseId) {
104
- const onInterrupt = () => {
105
- void (async () => {
106
- await endWatch(square, name, currentLeaseId());
107
- process.stdout.write(withPathOutput(squarePath, '○ you step back — catch stopped'));
108
- process.exit(130);
109
- })().catch((error) => {
110
- process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
111
- process.exit(130);
112
- });
113
- };
114
- process.once('SIGINT', onInterrupt);
115
- return () => {
116
- process.off('SIGINT', onInterrupt);
117
- };
118
- }
119
- async function cmdWatchNow(squarePath, name, opts, caller) {
120
- const square = await openSquare(squarePath, { clock: nowMs, env: caller.env });
121
- const application = createSquareApplication({ cwd: caller.cwd, env: caller.env, squarePath, participant: name, clock: nowMs });
122
- try {
123
- const caught = await application.catch({
124
- ...(opts.id === undefined ? {} : { id: opts.id }),
125
- ...(opts.participants === undefined ? {} : { from: opts.participants }),
126
- ...(opts.mention === undefined ? {} : { mention: true }),
127
- ...(opts.limit === undefined ? {} : { limit: opts.limit }),
128
- });
129
- const presentation = await watchPresentation(square, name);
130
- const status = presentation.terminalStatus;
131
- const result = caught.activities.length > 0
132
- ? watchOutputResult(squarePath, presentation, name, caught, { mention: opts.mention, participants: opts.participants, limit: opts.limit, ...(status ? { status } : {}) })
133
- : { type: 'terminal', status: status ?? 'empty-now' };
134
- await finishWatchResult(square, squarePath, name, result, undefined);
135
- return caught.activities.length > 0;
136
- }
137
- finally {
138
- await closeOpenSquare(square);
139
- }
140
- }
141
- /** `false` is reserved for a quiet --now; idle completion preserves its existing sweep boundary. */
142
- export async function cmdWatch(squarePath, name, opts, caller = { cwd: process.cwd(), env: { ...process.env } }) {
143
- let square;
144
- let participantCount;
145
- try {
146
- square = await openSquare(squarePath, { clock: nowMs, env: caller.env });
147
- participantCount = inSquareCount((await square.artifact.read()).state);
148
- name = (await resolveParticipant(square, name)).name;
149
- }
150
- catch (err) {
151
- if (isSquareError(err)) {
152
- const bodyLines = [err.message];
153
- // The caller's own name has never joined; only a join admits it.
154
- if (err.facts?.reason === 'never_joined')
155
- bodyLines.push(joinRecoveryCommand(squarePath, name));
156
- process.stderr.write(formatRefusal(squarePath, bodyLines, participantCount === undefined ? {} : { participantCount }));
157
- process.exit(err.code === 'not_found' ? 1 : 2);
158
- }
159
- throw err;
160
- }
161
- try {
162
- if (opts.mention !== undefined)
163
- opts = { ...opts, mention: (await resolveParticipant(square, opts.mention)).name };
164
- if (opts.participants !== undefined && opts.participants.length > 0) {
165
- opts = { ...opts, participants: await Promise.all(opts.participants.map(async (participant) => (await resolveParticipant(square, participant)).name)) };
166
- }
167
- }
168
- catch (err) {
169
- let participantCount;
170
- try {
171
- participantCount = inSquareCount((await square.artifact.read()).state);
172
- }
173
- catch { /* the header count is best effort */ }
174
- await closeOpenSquare(square).catch(() => undefined);
175
- if (isSquareError(err)) {
176
- const bodyLines = [err.message];
177
- // A filter target is unknown, not the caller; the roster is the useful next read.
178
- if (err.facts?.reason === 'never_joined' || err.facts?.reason === 'not_standing')
179
- bodyLines.push(participantsRecoveryCommand(squarePath));
180
- process.stderr.write(formatRefusal(squarePath, bodyLines, participantCount === undefined ? {} : { participantCount }));
181
- process.exit(err.code === 'not_found' ? 1 : 2);
182
- }
183
- throw err;
184
- }
185
- if (opts.now) {
186
- await closeOpenSquare(square);
187
- return cmdWatchNow(squarePath, name, opts, caller);
188
- }
189
- const start = await beginWatch(square, squarePath, name, opts);
190
- if (start.type === 'active') {
191
- const presentation = await watchPresentation(square, name);
192
- process.stdout.write(withPathOutput(squarePath, renderWatchAlreadyActive({ squarePath, name }), { participantCount: presentation.participantCount }));
193
- await closeOpenSquare(square);
194
- process.exit(1);
195
- }
196
- let staleSince = nowMs();
197
- let wasHeld = false;
198
- let currentLeaseId = start.leaseId;
199
- let nextHeartbeatAt = start.heartbeatAt + WATCH_HEARTBEAT_MS;
200
- if (opts.replace) {
201
- const presentation = await watchPresentation(square, name);
202
- process.stdout.write(withPathOutput(squarePath, start.replaced
203
- ? renderWatchForceTakeover({ squarePath, name })
204
- : renderWatchReplaceMissing({ squarePath, name }), { participantCount: presentation.participantCount }));
205
- }
206
- const idleMs = opts.idleMs ?? STALE_MS;
207
- const removeInterruptHandler = installWatchInterruptHandler(square, squarePath, name, () => currentLeaseId);
208
- const application = createSquareApplication({ cwd: caller.cwd, env: caller.env, squarePath, participant: name, clock: nowMs });
209
- try {
210
- while (true) {
211
- // Capture before evaluation: changes during catch/lease checks must not be lost.
212
- const baseline = (await square.artifact.read()).version;
213
- const leaseState = await pulseWatchLease(square, name, currentLeaseId, opts, nowMs() >= nextHeartbeatAt);
214
- if ((leaseState.type === 'sleep' || leaseState.type === 'held') && leaseState.heartbeatAt !== undefined) {
215
- nextHeartbeatAt = leaseState.heartbeatAt + WATCH_HEARTBEAT_MS;
216
- }
217
- let result = leaseState;
218
- if (result.type === 'sleep') {
219
- const caught = await application.catch({
220
- ...(opts.participants === undefined ? {} : { from: opts.participants }),
221
- ...(opts.mention === undefined ? {} : { mention: true }),
222
- ...(opts.limit === undefined ? {} : { limit: opts.limit }),
223
- });
224
- if (caught.activities.length > 0) {
225
- result = watchOutputResult(squarePath, await watchPresentation(square, name), name, caught, { mention: opts.mention, participants: opts.participants, limit: opts.limit });
226
- }
227
- }
228
- if (await finishWatchResult(square, squarePath, name, result, currentLeaseId)) {
229
- currentLeaseId = undefined;
230
- return;
231
- }
232
- if (result.type === 'held' || wasHeld)
233
- staleSince = nowMs();
234
- wasHeld = result.type === 'held';
235
- if (!wasHeld && nowMs() - staleSince >= idleMs) {
236
- const result = !await ownsWatchLease(square, name, currentLeaseId)
237
- ? { type: 'replaced' }
238
- : { type: 'terminal', status: 'stale' };
239
- if (await finishWatchResult(square, squarePath, name, result, currentLeaseId, idleMs)) {
240
- currentLeaseId = undefined;
241
- return;
242
- }
243
- }
244
- const nextDeadline = Math.min(nextHeartbeatAt, wasHeld ? Infinity : staleSince + idleMs);
245
- await square.artifact.changed(baseline, Math.max(0, nextDeadline - nowMs()));
246
- }
247
- }
248
- finally {
249
- await closeOpenSquare(square);
250
- removeInterruptHandler();
251
- }
252
- }