@astrosheep/square 0.3.92 → 0.3.94

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 (119) hide show
  1. package/dist/activity-feed.d.ts +3 -5
  2. package/dist/activity-feed.js +16 -14
  3. package/dist/artifact.js +2 -2
  4. package/dist/boundary-presentation.d.ts +2 -2
  5. package/dist/catch-decisions.d.ts +4 -6
  6. package/dist/catch-decisions.js +4 -4
  7. package/dist/claude-delivery-status.js +10 -4
  8. package/dist/claude-delivery.js +19 -11
  9. package/dist/claude-mod.js +24 -53
  10. package/dist/cli/context.d.ts +9 -4
  11. package/dist/cli/context.js +30 -25
  12. package/dist/cli/express-presentation.d.ts +3 -1
  13. package/dist/cli/express-presentation.js +26 -14
  14. package/dist/cli/json.d.ts +3 -0
  15. package/dist/cli/json.js +14 -0
  16. package/dist/cli/mcp-server-command.js +2 -2
  17. package/dist/cli/observation-commands.d.ts +1 -3
  18. package/dist/cli/observation-commands.js +43 -56
  19. package/dist/cli/program.js +2 -2
  20. package/dist/cli/registry.js +6 -3
  21. package/dist/cli/square-commands.d.ts +1 -1
  22. package/dist/cli/square-commands.js +46 -54
  23. package/dist/codex-hook.d.ts +3 -2
  24. package/dist/codex-hook.js +13 -4
  25. package/dist/codex-queue.js +4 -4
  26. package/dist/decisions.d.ts +5 -11
  27. package/dist/decisions.js +9 -20
  28. package/dist/delivery-deferral.js +2 -2
  29. package/dist/delivery-health.d.ts +0 -1
  30. package/dist/delivery-health.js +1 -3
  31. package/dist/delivery-operations.d.ts +2 -2
  32. package/dist/delivery-operations.js +38 -38
  33. package/dist/delivery.d.ts +1 -1
  34. package/dist/delivery.js +1 -1
  35. package/dist/harness-links.d.ts +1 -10
  36. package/dist/harness-links.js +144 -109
  37. package/dist/harness.js +4 -13
  38. package/dist/help.js +12 -10
  39. package/dist/inbox.d.ts +9 -22
  40. package/dist/inbox.js +23 -27
  41. package/dist/index.d.ts +1 -3
  42. package/dist/index.js +1 -1
  43. package/dist/mcp.d.ts +3 -0
  44. package/dist/mcp.js +23 -24
  45. package/dist/model.d.ts +8 -15
  46. package/dist/model.js +4 -7
  47. package/dist/notifications.d.ts +1 -1
  48. package/dist/notifications.js +6 -5
  49. package/dist/operation-presentation.d.ts +5 -4
  50. package/dist/operation-presentation.js +50 -45
  51. package/dist/owner.d.ts +11 -0
  52. package/dist/owner.js +32 -0
  53. package/dist/paseo-delivery.d.ts +4 -1
  54. package/dist/paseo-delivery.js +7 -12
  55. package/dist/paseo-state.d.ts +2 -2
  56. package/dist/paseo-state.js +6 -4
  57. package/dist/plugins/opencode/delivery.js +27 -15
  58. package/dist/ports.d.ts +13 -33
  59. package/dist/presentation-operations.js +4 -4
  60. package/dist/presentation.d.ts +5 -8
  61. package/dist/presentation.js +33 -43
  62. package/dist/runtime.d.ts +1 -7
  63. package/dist/runtime.js +0 -14
  64. package/dist/seats.d.ts +2 -3
  65. package/dist/seats.js +7 -15
  66. package/dist/session-lifecycle.d.ts +6 -2
  67. package/dist/session-lifecycle.js +39 -11
  68. package/dist/sqlite-square.d.ts +36 -22
  69. package/dist/sqlite-square.js +138 -161
  70. package/dist/square-api.d.ts +15 -10
  71. package/dist/square-api.js +26 -22
  72. package/dist/square-core.d.ts +0 -5
  73. package/dist/square-core.js +0 -9
  74. package/dist/square-domain.d.ts +4 -2
  75. package/dist/square-domain.js +56 -21
  76. package/dist/square-facade.d.ts +45 -87
  77. package/dist/square-index.d.ts +5 -13
  78. package/dist/square-index.js +13 -38
  79. package/dist/square-location.d.ts +1 -14
  80. package/dist/square-location.js +4 -69
  81. package/dist/square-migration-host-ledger.d.ts +2 -2
  82. package/dist/square-migration-host-ledger.js +6 -5
  83. package/dist/square-migration.d.ts +2 -1
  84. package/dist/square-migration.js +52 -30
  85. package/dist/square-sqlite.d.ts +6 -2
  86. package/dist/square-sqlite.js +54 -28
  87. package/dist/square-tools.d.ts +7 -10
  88. package/dist/square-tools.js +22 -54
  89. package/dist/stream.js +4 -5
  90. package/dist/views.d.ts +21 -10
  91. package/dist/views.js +38 -38
  92. package/dist/wakes.d.ts +1 -2
  93. package/dist/wakes.js +1 -1
  94. package/guides/application-facade-delivery-evidence.md +1 -1
  95. package/guides/claude-native.md +18 -9
  96. package/guides/codex-delivery.md +17 -6
  97. package/guides/mcp-connection-lifetime.md +1 -1
  98. package/guides/mcp.md +3 -3
  99. package/guides/migration.md +142 -151
  100. package/guides/operation-cancellation.md +1 -1
  101. package/guides/participant-ownership.md +78 -47
  102. package/guides/pi-tools.md +33 -4
  103. package/guides/primitive-history-consolidation.md +1 -1
  104. package/guides/row-storage-design.md +8 -8
  105. package/guides/square-api.md +244 -88
  106. package/package.json +2 -1
  107. package/plugins/claude/.claude-plugin/plugin.json +1 -1
  108. package/plugins/codex/.codex-plugin/plugin.json +1 -1
  109. package/plugins/opencode/delivery.ts +27 -17
  110. package/plugins/paseo/client/palette.ts +18 -18
  111. package/plugins/paseo/client/square-message.tsx +17 -23
  112. package/plugins/pi/square-pi.js +17 -17
  113. package/dist/square-backend.d.ts +0 -13
  114. package/dist/square-backend.js +0 -1
  115. package/dist/square-stdio.d.ts +0 -22
  116. package/dist/square-stdio.js +0 -235
  117. package/dist/stdio-server.d.ts +0 -3
  118. package/dist/stdio-server.js +0 -212
  119. package/guides/backends.md +0 -193
package/dist/seats.js CHANGED
@@ -1,9 +1,9 @@
1
- import { SquareError, sameBody, sameName, validateBody, validateName } from './model.js';
2
- export function requireBody(body) {
3
- if (body === undefined)
4
- throw new SquareError('invalid_args', 'Participant writes require an explicit body: channel and session.');
5
- validateBody(body);
6
- return body;
1
+ import { SquareError, validateOwner, validateName } from './model.js';
2
+ export function requireOwner(owner) {
3
+ if (owner === undefined)
4
+ throw new SquareError('invalid_args', 'Participant writes require an explicit owner.');
5
+ validateOwner(owner);
6
+ return owner;
7
7
  }
8
8
  export function requireJoinName(name) {
9
9
  if (name === undefined)
@@ -12,16 +12,8 @@ export function requireJoinName(name) {
12
12
  return name;
13
13
  }
14
14
  export function asSeatRef(seat) {
15
- const { wakeAddress: _wakeAddress, ...ref } = seat;
16
- return ref;
15
+ return { participant: seat.participant, owner: seat.owner, generation: seat.generation };
17
16
  }
18
17
  export function participantAuthority(seat) {
19
18
  return { kind: 'participant', seat: asSeatRef(seat) };
20
19
  }
21
- export function requireSeat(seat, body, participant) {
22
- if (seat === undefined || !sameName(seat.participant, participant))
23
- throw new SquareError('already_joined', `${participant} needs a current participant handle; join first`);
24
- if (!sameBody(seat.body, requireBody(body)))
25
- throw new SquareError('already_joined', `${participant} is not held by this body`);
26
- return seat;
27
- }
@@ -1,3 +1,7 @@
1
+ import { type Owner } from './owner.js';
1
2
  import type { AutomaticProvider } from './participant-identity.js';
2
- /** Retire only seats held by this exact body, discovered through the rebuildable index. */
3
- export declare function endSessionMemberships(provider: AutomaticProvider, sessionId: string, env?: NodeJS.ProcessEnv): Promise<void>;
3
+ import type { WakeAddress } from './model.js';
4
+ /** Host shutdown suspends execution, not membership. Discovery never grants custody. */
5
+ export declare function detachSessionSeats(provider: AutomaticProvider, sessionId: string, env?: NodeJS.ProcessEnv): Promise<void>;
6
+ /** Restore only detached, standing seats of this exact owner before starting a receiver. */
7
+ export declare function restoreSessionSeats(owner: Owner, env?: NodeJS.ProcessEnv, wakeAddress?: WakeAddress, signal?: AbortSignal): Promise<void>;
@@ -1,19 +1,47 @@
1
1
  import { Square } from './square-api.js';
2
- import { projectSessionSeats } from './inbox.js';
3
- function bodyFor(provider, sessionId) {
4
- return { channel: provider === 'claude' ? 'claude-code' : provider, session: sessionId };
2
+ import { harnessOwner } from './owner.js';
3
+ import { projectSessionCandidates, projectSessionSeats } from './inbox.js';
4
+ function ownerFor(provider, sessionId) {
5
+ return harnessOwner({ channel: provider === 'claude' ? 'claude-code' : provider, session: sessionId });
5
6
  }
6
- /** Retire only seats held by this exact body, discovered through the rebuildable index. */
7
- export async function endSessionMemberships(provider, sessionId, env = process.env) {
8
- const body = bodyFor(provider, sessionId);
9
- const seats = await projectSessionSeats({ body, env });
10
- for (const { location, seat } of seats) {
11
- const square = await Square.at({ path: location, env, body, participant: seat.participant });
7
+ /** Host shutdown suspends execution, not membership. Discovery never grants custody. */
8
+ export async function detachSessionSeats(provider, sessionId, env = process.env) {
9
+ const owner = ownerFor(provider, sessionId);
10
+ for (const { location, seat } of await projectSessionSeats({ owner, env })) {
11
+ let square;
12
12
  try {
13
- await square.endOwnedSession(seat.participant, sessionId, seat.generation, body);
13
+ square = await Square.at({ path: location, env });
14
+ await square.detach(seat.participant, { owner, generation: seat.generation });
14
15
  }
16
+ catch { /* One unavailable or replaced seat must not block cleanup of the others. */ }
15
17
  finally {
16
- await square.close();
18
+ await square?.close();
19
+ }
20
+ }
21
+ }
22
+ /** Restore only detached, standing seats of this exact owner before starting a receiver. */
23
+ export async function restoreSessionSeats(owner, env = process.env, wakeAddress, signal) {
24
+ const locations = new Set((await projectSessionCandidates({ owner, env })).map(candidate => candidate.location));
25
+ for (const location of locations) {
26
+ if (signal?.aborted)
27
+ return;
28
+ let square;
29
+ try {
30
+ square = await Square.at({ path: location, env }, { signal });
31
+ for (const seat of await square.seatsOf(owner)) {
32
+ if (signal?.aborted)
33
+ return;
34
+ if (seat.attachment !== 'detached')
35
+ continue;
36
+ try {
37
+ await square.reattach(seat.name, { owner, wakeAddress }, { signal });
38
+ }
39
+ catch { /* A replacement or one failed seat does not block its peers. */ }
40
+ }
41
+ }
42
+ catch { /* An indexed location is only a candidate, not a promise of availability. */ }
43
+ finally {
44
+ await square?.close();
17
45
  }
18
46
  }
19
47
  }
@@ -1,5 +1,5 @@
1
- import { type Body } from './model.js';
2
- import type { ActivityResult, HistoryQuery, HistoryResult, JoinOptions, JoinResult, ObservationOptions, OperationControl, Participant, SquareAtInput, SquareBuildInput, SquareLocation, StatusOptions, StatusResult, ParticipantsResult, RecoveryResult, DiscoveryOptions, InboxOptions, InboxResult, StreamOptions } from './square-facade.js';
1
+ import { type Owner } from './model.js';
2
+ import type { HistoryQuery, HistoryResult, JoinOptions, JoinResult, LifecycleResult, ObservationOptions, OperationControl, Participant, SquareAtInput, SquareBuildInput, SquareLocation, StatusOptions, StatusResult, ParticipantsResult, RecoveryResult, DiscoveryOptions, InboxOptions, InboxResult, StreamOptions, StreamRecord, Activity, PerceivedActivity } from './square-facade.js';
3
3
  export type * from './square-facade.js';
4
4
  export { createSquareResourceOwner } from './artifact.js';
5
5
  export { formatActivityId, parseActivityId, MAX_IDENTITY_SET_SIZE } from './square-core.js';
@@ -13,41 +13,55 @@ export declare class SqliteSquare {
13
13
  readonly location: string;
14
14
  private readonly artifact;
15
15
  private readonly clock;
16
- private readonly body?;
17
- private readonly wakeAddress?;
18
16
  private readonly wakeTransport?;
19
17
  private readonly indexPath?;
20
- private readonly automaticDelivery;
21
- private readonly ownsArtifact;
22
- private readonly defaultParticipant?;
18
+ private readonly closesArtifact;
19
+ private readonly deliveryLocation;
23
20
  private constructor();
24
- static at(input: SquareAtInput, control?: OperationControl, automaticDelivery?: boolean): Promise<SqliteSquare>;
25
- static build(input: SquareBuildInput, control?: OperationControl, automaticDelivery?: boolean): Promise<SqliteSquare>;
21
+ static at(input: SquareAtInput, control?: OperationControl): Promise<SqliteSquare>;
22
+ static build(input: SquareBuildInput, control?: OperationControl): Promise<SqliteSquare>;
26
23
  static inMemory(input: Omit<SquareBuildInput, 'path' | 'resources'>): SqliteSquare;
27
- /** Discovery is best effort and never grants write authority. Finish it before returning. */
28
- private publishIdentity;
24
+ /** Discovery is best effort and never grants write authority. */
25
+ private publishSeat;
29
26
  private observation;
30
27
  private contextObservation;
31
28
  private handle;
32
29
  private static readonly ParticipantHandle;
33
- participant(requested?: string): Promise<Participant>;
34
- join(requested?: string, options?: JoinOptions, control?: OperationControl): Promise<JoinResult>;
35
- implicitJoin(name: string, control?: OperationControl): Promise<{
36
- readonly state: 'joined' | 'active' | 'done';
37
- readonly participant?: Participant;
38
- }>;
30
+ participant(name: string, { owner }: {
31
+ readonly owner: Owner;
32
+ }): Promise<Participant>;
33
+ join(requested: string, options: JoinOptions, control?: OperationControl): Promise<JoinResult>;
34
+ /** Restore only a standing seat; a concurrent departure or takeover cannot be revived. */
35
+ reattach(name: string, { owner, wakeAddress }: Pick<JoinOptions, 'owner' | 'wakeAddress'>, control?: OperationControl): Promise<Participant | null>;
39
36
  snapshot(control?: OperationControl): Promise<import("./square-facade.js").SquareSnapshot>;
40
37
  history(query?: HistoryQuery, control?: OperationControl): Promise<HistoryResult>;
41
38
  status(options?: StatusOptions, control?: OperationControl): Promise<StatusResult>;
42
39
  participants(options?: ObservationOptions, control?: OperationControl): Promise<ParticipantsResult>;
43
40
  recovery(requested?: string, control?: OperationControl): Promise<RecoveryResult>;
44
- stream(options: StreamOptions, control?: OperationControl): AsyncIterable<import("./square-facade.js").StreamRecord>;
45
- recognize(): Promise<readonly Participant[]>;
41
+ stream(options: StreamOptions & {
42
+ readonly recipient: string;
43
+ }, control?: OperationControl): AsyncIterable<PerceivedActivity>;
44
+ stream(options: StreamOptions & {
45
+ readonly recipient?: undefined;
46
+ }, control?: OperationControl): AsyncIterable<Activity>;
47
+ stream(options: StreamOptions, control?: OperationControl): AsyncIterable<StreamRecord>;
48
+ seatsOf(owner: Owner): Promise<readonly import('./square-facade.js').HeldSeat[]>;
46
49
  close(): Promise<void>;
47
- cancelDeliveries(name: string, expectedGeneration: import('./square-core.js').ActivityId): Promise<boolean>;
48
- endOwnedSession(name: string, sessionId: string, expectedGeneration?: import('./square-core.js').ActivityId, body?: Body): Promise<ActivityResult | null>;
50
+ private heldSeat;
51
+ cancelDeliveries(name: string, identity: {
52
+ readonly owner: Owner;
53
+ readonly generation: import('./square-core.js').ActivityId;
54
+ }): Promise<boolean>;
55
+ detach(name: string, identity: {
56
+ readonly owner: Owner;
57
+ readonly generation: import('./square-core.js').ActivityId;
58
+ }): Promise<true | null>;
59
+ endHeld(name: string, identity: {
60
+ readonly owner: Owner;
61
+ readonly generation: import('./square-core.js').ActivityId;
62
+ }): Promise<LifecycleResult | null>;
49
63
  }
50
64
  export declare function diagnoseSquare(input: SquareLocation, control?: OperationControl): Promise<import("./artifact.js").DiagnoseResult>;
51
65
  export declare function migrateSquare(input: SquareLocation, control?: OperationControl): Promise<import("./square-migration.js").MigrationOutcome>;
52
66
  export declare function discover(input: SquareAtInput, options?: DiscoveryOptions, control?: OperationControl): Promise<import("./square-facade.js").DiscoveryResult>;
53
- export declare function inbox(input: SquareAtInput, identity: string | Body, options?: InboxOptions, control?: OperationControl): Promise<InboxResult>;
67
+ export declare function inbox(input: SquareAtInput, owner: Owner, options?: InboxOptions, control?: OperationControl): Promise<InboxResult>;