@astrosheep/square 0.3.70 → 0.3.71

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 (115) 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/perception-projection.d.ts +6 -15
  51. package/dist/perception-projection.js +6 -26
  52. package/dist/plugins/opencode/delivery.js +9 -9
  53. package/dist/plugins/opencode/index.js +3 -3
  54. package/dist/ports.d.ts +156 -11
  55. package/dist/presentation-operations.d.ts +1 -1
  56. package/dist/presentation-operations.js +35 -44
  57. package/dist/presentation.d.ts +12 -19
  58. package/dist/presentation.js +33 -54
  59. package/dist/routes.d.ts +7 -14
  60. package/dist/routes.js +33 -62
  61. package/dist/runtime.d.ts +12 -39
  62. package/dist/runtime.js +33 -164
  63. package/dist/square-actions.d.ts +11 -21
  64. package/dist/square-actions.js +171 -271
  65. package/dist/square-application.d.ts +31 -55
  66. package/dist/square-application.js +637 -141
  67. package/dist/square-core.d.ts +3 -94
  68. package/dist/square-core.js +8 -353
  69. package/dist/square-domain.d.ts +24 -0
  70. package/dist/square-domain.js +77 -0
  71. package/dist/square-facade.d.ts +360 -9
  72. package/dist/square-migration.d.ts +24 -0
  73. package/dist/square-migration.js +211 -0
  74. package/dist/square-projections.d.ts +2 -42
  75. package/dist/square-projections.js +1 -37
  76. package/dist/square-sqlite.d.ts +59 -0
  77. package/dist/square-sqlite.js +702 -0
  78. package/dist/stream.d.ts +3 -10
  79. package/dist/stream.js +81 -52
  80. package/dist/views.d.ts +27 -95
  81. package/dist/views.js +217 -87
  82. package/dist/wake-eligibility.d.ts +15 -5
  83. package/dist/wake-eligibility.js +32 -16
  84. package/dist/wakes.d.ts +3 -3
  85. package/dist/wakes.js +31 -27
  86. package/guides/application-facade-delivery-evidence.md +200 -0
  87. package/guides/application-facade-design.md +95 -0
  88. package/guides/change-waits.md +4 -4
  89. package/guides/migration.md +77 -0
  90. package/guides/primitive-catch-consolidation.md +85 -0
  91. package/guides/primitive-history-consolidation.md +76 -0
  92. package/guides/primitive-status-consolidation.md +87 -0
  93. package/guides/primitive-storage-consolidation.md +128 -0
  94. package/guides/row-runtime-delivery-evidence.md +160 -0
  95. package/guides/row-storage-design.md +567 -0
  96. package/package.json +1 -1
  97. package/plugins/claude/.claude-plugin/plugin.json +1 -1
  98. package/plugins/codex/.codex-plugin/plugin.json +1 -1
  99. package/plugins/opencode/delivery.ts +11 -11
  100. package/plugins/opencode/index.ts +3 -3
  101. package/plugins/paseo/client/square-message.tsx +70 -52
  102. package/plugins/paseo/shared/message.ts +15 -0
  103. package/plugins/pi/square-pi.js +3 -0
  104. package/dist/activity.d.ts +0 -14
  105. package/dist/activity.js +0 -248
  106. package/dist/square-file-adapter.d.ts +0 -26
  107. package/dist/square-file-adapter.js +0 -85
  108. package/dist/square-state.d.ts +0 -6
  109. package/dist/square-state.js +0 -138
  110. package/dist/square-storage.d.ts +0 -14
  111. package/dist/square-storage.js +0 -188
  112. package/dist/square-wiring.d.ts +0 -33
  113. package/dist/square-wiring.js +0 -109
  114. package/dist/watch.d.ts +0 -8
  115. package/dist/watch.js +0 -252
@@ -1,7 +1,5 @@
1
- import { type InboxMembership, type SquareState } from './model.js';
2
- import type { HostLedgerPort, SquareArtifactPort, PresentationEvidenceProjection, PresentationProjection, SessionBindingProjection } from './ports.js';
3
- import { deriveDeliveryModel } from './delivery.js';
4
- import { type WakeEligibility } from './wake-eligibility.js';
1
+ import { type InboxMembership } from './model.js';
2
+ import type { HostLedgerPort, PresentationEvidenceProjection, SessionBindingProjection } from './ports.js';
5
3
  /** A fresh blocking catch owns only the notifications admitted by its filter. */
6
4
  export declare function pendingAtBoundary(inbox: InboxMembership[]): InboxMembership[];
7
5
  /**
@@ -21,36 +19,6 @@ export declare function projectSessionBindings(input: {
21
19
  readonly location?: string;
22
20
  readonly now?: number;
23
21
  }): Promise<readonly SessionBindingProjection[]>;
24
- export declare function projectPresentation(input: {
25
- readonly artifact: SquareArtifactPort;
26
- readonly binding: SessionBindingProjection;
27
- readonly now?: number;
28
- }): Promise<PresentationProjection>;
29
- export interface NativePendingPreview {
30
- readonly payload: string;
31
- readonly clipped: boolean;
32
- }
33
- /** The one native pending preview. `epoch` matches exactly, and each harness pins its own address entry. */
34
- export type NativePendingPreviewInput = {
35
- readonly location: string;
36
- readonly sessionId: string;
37
- readonly participant: string;
38
- readonly actIndex: number;
39
- readonly epoch?: number;
40
- readonly cancelledThrough?: number;
41
- readonly now: number;
42
- } & ({
43
- readonly routeKind: 'claude-native';
44
- readonly address: {
45
- readonly endpoint: string;
46
- };
47
- } | {
48
- readonly routeKind: 'opencode-server';
49
- readonly address: {
50
- readonly sessionId: string;
51
- };
52
- });
53
- export declare function nativePendingPreview(state: SquareState, input: NativePendingPreviewInput): NativePendingPreview | undefined;
54
22
  export declare function projectPresentationEvidence(input: {
55
23
  readonly hostLedger: HostLedgerPort;
56
24
  readonly location?: string;
@@ -61,11 +29,3 @@ export declare function projectPresentationEvidence(input: {
61
29
  }): Promise<readonly PresentationEvidenceProjection[]>;
62
30
  /** Successful boundary output, including a clipped preview, suppresses awareness wake. */
63
31
  export declare function presentationSuppressesWake(evidence: readonly Pick<PresentationEvidenceProjection, 'outcome'>[]): boolean;
64
- /** Read primary evidence once; wake behavior belongs to the pure eligibility projection. */
65
- export declare function projectWakeEvidenceFromState(input: {
66
- readonly location: string;
67
- readonly state: SquareState;
68
- readonly hostLedger: HostLedgerPort;
69
- readonly now: number;
70
- readonly delivery?: ReturnType<typeof deriveDeliveryModel>;
71
- }): Promise<WakeEligibility>;
@@ -1,10 +1,7 @@
1
1
  import { formatActivityId } from './square-core.js';
2
2
  import { nameKey } from './model.js';
3
- import { deriveDeliveryModel, leaseOwnsNotification } from './delivery.js';
4
- import { freshWatchLease } from './runtime.js';
5
- import { attentionBodyIsClipped, renderAttentionPreview } from './attention-presentation.js';
3
+ import { leaseOwnsNotification } from './delivery.js';
6
4
  import { canonicalPath } from './canonical-path.js';
7
- import { projectWakeEligibility } from './wake-eligibility.js';
8
5
  /** A fresh blocking catch owns only the notifications admitted by its filter. */
9
6
  export function pendingAtBoundary(inbox) {
10
7
  return inbox.map((membership) => {
@@ -57,29 +54,6 @@ export async function projectSessionBindings(input) {
57
54
  updatedAt: record.updatedAt ?? 0,
58
55
  }));
59
56
  }
60
- export async function projectPresentation(input) {
61
- const { state } = await input.artifact.read();
62
- const delivery = deriveDeliveryModel(state);
63
- const known = delivery.knownParticipant(input.binding.participant);
64
- if (known === undefined || !delivery.joinedRecipients().some((recipient) => recipient.toLocaleLowerCase() === known.toLocaleLowerCase()))
65
- return { binding: input.binding, joined: false, notifications: [] };
66
- const binding = input.binding.participant === known ? input.binding : { ...input.binding, participant: known };
67
- const notifications = delivery.pendingFor(known).map(({ item, route }) => ({ actIndex: item.index, actor: item.actor, at: item.at, route, body: item.body }));
68
- const lease = freshWatchLease(state, known, input.now ?? Date.now());
69
- return { binding, joined: true, notifications, ...(lease === undefined ? {} : { catchLease: lease }) };
70
- }
71
- export function nativePendingPreview(state, input) {
72
- const route = state.routes?.find((candidate) => candidate.kind === input.routeKind && candidate.sessionId === input.sessionId
73
- && candidate.epoch === input.epoch && nameKey(candidate.participant) === nameKey(input.participant)
74
- && (input.routeKind === 'claude-native' ? candidate.address.endpoint === input.address.endpoint : candidate.address.sessionId === input.address.sessionId));
75
- if (!route || input.actIndex <= (input.cancelledThrough ?? -1))
76
- return undefined;
77
- const notification = deriveDeliveryModel(state).pendingFor(input.participant).find((entry) => entry.item.index === input.actIndex);
78
- const lease = freshWatchLease(state, input.participant, input.now);
79
- if (!notification || (lease !== undefined && leaseOwnsNotification(lease, { ...notification.item, recipient: input.participant, route: notification.route })))
80
- return undefined;
81
- return { payload: renderAttentionPreview({ squarePath: input.location, recipient: input.participant, actIndex: input.actIndex, actor: notification.item.actor, route: notification.route, body: notification.item.body }), clipped: attentionBodyIsClipped(notification.item.body) };
82
- }
83
57
  export async function projectPresentationEvidence(input) {
84
58
  const rows = await input.hostLedger.listEvidence({ kind: 'presentation', location: input.location, participant: input.participant, session: input.sessionId, activity: input.activity, now: input.now });
85
59
  return rows.map((row) => ({ location: row.location, participant: row.participant, sessionId: row.session, activity: row.activity, outcome: row.outcome, ...(row.at === undefined ? {} : { at: row.at }) }));
@@ -88,13 +62,3 @@ export async function projectPresentationEvidence(input) {
88
62
  export function presentationSuppressesWake(evidence) {
89
63
  return evidence.some((row) => row.outcome === 'clipped' || row.outcome === 'presented');
90
64
  }
91
- /** Read primary evidence once; wake behavior belongs to the pure eligibility projection. */
92
- export async function projectWakeEvidenceFromState(input) {
93
- const canonicalLocation = await canonicalPath(input.location);
94
- const delivery = input.delivery ?? deriveDeliveryModel(input.state);
95
- const owners = await input.hostLedger.listPresence({ location: canonicalLocation, now: input.now });
96
- const evidence = await input.hostLedger.listEvidence({ location: canonicalLocation, now: input.now });
97
- const wakeRecords = evidence.filter((row) => row.kind === 'wake');
98
- const presentations = evidence.filter((row) => row.kind === 'presentation').map((row) => ({ location: row.location, participant: row.participant, sessionId: row.session, activity: row.activity, outcome: row.outcome, ...(row.at === undefined ? {} : { at: row.at }) }));
99
- return projectWakeEligibility({ state: input.state, location: canonicalLocation, owners, wakeRecords, presentations, now: input.now, delivery });
100
- }
@@ -0,0 +1,59 @@
1
+ import { type DatabaseSync } from 'node:sqlite';
2
+ import { SquareError, type ActivityObservation, type HardCap, type StoredAct, type WakeRoute, type WatchLease } from './model.js';
3
+ import type { SquareRead, RouteFact } from './ports.js';
4
+ import { type LandingWriter } from './square-domain.js';
5
+ /** Explicit import/export DTOs, not a runtime transaction model. */
6
+ export interface SquareRuntimeState {
7
+ nextActIndex: number;
8
+ observations: Record<string, Record<string, ActivityObservation>>;
9
+ leases: Record<string, WatchLease>;
10
+ }
11
+ export interface SquareState {
12
+ hardCap: HardCap;
13
+ throttlePerMinute?: number;
14
+ preamble: string[];
15
+ warmup: string[];
16
+ acts: StoredAct[];
17
+ routes?: WakeRoute[];
18
+ runtime: SquareRuntimeState;
19
+ }
20
+ export declare function emptyRuntimeState(nextActIndex?: number): SquareRuntimeState;
21
+ export declare const APPLICATION_ID = 1397838405;
22
+ export declare const V1_SNAPSHOT_TABLE = "square_snapshot";
23
+ export interface LegacyFraming {
24
+ readonly applicationId: number;
25
+ readonly userVersion: number;
26
+ readonly journalMode: string;
27
+ }
28
+ /**
29
+ * The one recovery command for an owned legacy artifact, with a shell-quoted
30
+ * path. Kept beside framing recognition so the refusal and migration
31
+ * instruction cannot drift apart. This codec stays free of the renderer.
32
+ */
33
+ export declare function migrationRecoveryCommand(location: string): string;
34
+ /**
35
+ * Read-only legacy framing: application id, format version, journal mode and the
36
+ * exact owned snapshot schema. It decodes no snapshot payload, writes no pragma
37
+ * and runs no DDL, so ordinary open can establish ownership before offering
38
+ * the migration command. Anything else is unrelated or unsupported, not repaired.
39
+ */
40
+ export declare function validateLegacyFraming(database: DatabaseSync, applicationId: number, location?: string): LegacyFraming;
41
+ export declare const SCHEMA_SQL = "CREATE TABLE square_meta (\n id INTEGER PRIMARY KEY CHECK (id = 1),\n revision INTEGER NOT NULL CHECK (revision BETWEEN 0 AND 9007199254740991),\n next_act_index INTEGER NOT NULL CHECK (next_act_index BETWEEN 0 AND 9007199254740991),\n hard_cap INTEGER CHECK (hard_cap BETWEEN 1 AND 9007199254740991),\n throttle_per_minute INTEGER CHECK (throttle_per_minute BETWEEN 1 AND 9007199254740991),\n preamble_json TEXT NOT NULL CHECK (json_valid(preamble_json)),\n warmup_json TEXT NOT NULL CHECK (json_valid(warmup_json))\n);\nCREATE TABLE activities (\n act_index INTEGER PRIMARY KEY CHECK (act_index BETWEEN 0 AND 9007199254740991),\n at REAL NOT NULL,\n kind TEXT NOT NULL CHECK (kind IN ('join','done','say','hold','resume','read','listen','ignore')),\n actor_json TEXT COLLATE BINARY,\n actor_key_json TEXT COLLATE BINARY,\n reach TEXT CHECK (reach = 'bell'),\n reply_index INTEGER CHECK (reply_index >= 0 AND reply_index < act_index),\n payload_json TEXT NOT NULL CHECK (json_valid(payload_json)),\n CHECK ((actor_json IS NULL) = (actor_key_json IS NULL)),\n CHECK (kind IN ('hold','resume') OR actor_json IS NOT NULL),\n CHECK (kind = 'say' OR (reach IS NULL AND reply_index IS NULL))\n);\nCREATE INDEX activity_kind_index ON activities(kind, act_index);\nCREATE INDEX activity_actor_index ON activities(actor_key_json, act_index);\nCREATE INDEX activity_say_actor_index ON activities(actor_key_json, act_index) WHERE kind='say';\nCREATE INDEX activity_say_time ON activities(at, act_index) WHERE kind='say';\nCREATE INDEX activity_bell_actor_time ON activities(actor_key_json, at, act_index) WHERE kind='say' AND reach='bell';\n\nCREATE TABLE receipts (\n owner_json TEXT COLLATE BINARY NOT NULL,\n act_index INTEGER NOT NULL CHECK (act_index BETWEEN 0 AND 9007199254740991),\n at REAL NOT NULL,\n PRIMARY KEY (owner_json, act_index)\n) WITHOUT ROWID;\nCREATE INDEX receipt_owner_time ON receipts(owner_json, at);\nCREATE TABLE catch_leases (\n owner_json TEXT COLLATE BINARY PRIMARY KEY NOT NULL,\n lease_id_json TEXT NOT NULL,\n heartbeat_at REAL NOT NULL,\n expires_at REAL NOT NULL CHECK (expires_at >= heartbeat_at),\n filter_json TEXT CHECK (filter_json IS NULL OR json_valid(filter_json))\n) WITHOUT ROWID;\n\nCREATE TABLE routes (\n position INTEGER PRIMARY KEY CHECK (position >= 0),\n participant_key_json TEXT COLLATE BINARY NOT NULL,\n session_json TEXT COLLATE BINARY NOT NULL,\n kind TEXT NOT NULL CHECK (kind IN ('opencode-server','codex-queue','claude-native','paseo')),\n updated_at REAL NOT NULL,\n payload_json TEXT NOT NULL CHECK (json_valid(payload_json))\n);\nCREATE INDEX route_participant ON routes(participant_key_json, position);\nCREATE INDEX route_session ON routes(session_json, position);\n\nCREATE TABLE participants (\n name_key_json TEXT COLLATE BINARY PRIMARY KEY NOT NULL,\n name_json TEXT NOT NULL,\n first_index INTEGER NOT NULL UNIQUE,\n joined INTEGER NOT NULL CHECK (joined IN (0,1)),\n done INTEGER NOT NULL CHECK (done IN (0,1)),\n say_count INTEGER NOT NULL CHECK (say_count >= 0),\n last_active_at REAL,\n last_join_index INTEGER,\n CHECK (NOT (joined=1 AND done=1))\n) WITHOUT ROWID;\nCREATE TABLE attention (\n listener_key_json TEXT COLLATE BINARY NOT NULL,\n target_key_json TEXT COLLATE BINARY NOT NULL,\n target_json TEXT NOT NULL,\n kind TEXT NOT NULL CHECK (kind IN ('listen','ignore')),\n since_index INTEGER NOT NULL,\n PRIMARY KEY (listener_key_json, target_key_json)\n) WITHOUT ROWID;\nCREATE INDEX attention_target ON attention(target_key_json, kind, listener_key_json);\nCREATE TABLE landed_audience (\n act_index INTEGER NOT NULL,\n recipient_key_json TEXT COLLATE BINARY NOT NULL,\n recipient_order INTEGER NOT NULL CHECK (recipient_order >= 0),\n route TEXT NOT NULL CHECK (route IN ('mention','reply','attention','bell')),\n PRIMARY KEY (act_index, recipient_key_json),\n UNIQUE (act_index, recipient_order)\n) WITHOUT ROWID;\nCREATE INDEX audience_recipient ON landed_audience(recipient_key_json, act_index);";
42
+ export declare function invalidArtifact(detail: string): SquareError;
43
+ export declare function validateStoredActivity(value: unknown): StoredAct;
44
+ export declare function validateWatchLease(value: unknown): WatchLease;
45
+ export declare function validateRoute(value: unknown): RouteFact;
46
+ export declare function validateSqliteHeader(db: DatabaseSync, location?: string): void;
47
+ export interface SqliteDriver extends SquareRead, LandingWriter {
48
+ readonly changed: boolean;
49
+ }
50
+ export declare function createSqliteDriver(db: DatabaseSync): SqliteDriver;
51
+ export declare function legacyRouteFact(value: Record<string, unknown>): RouteFact;
52
+ /** Explicit import only. Caller owns transaction, legacy validation and format publication. */
53
+ export declare function initializeSqlite(db: DatabaseSync, state: SquareState, revision?: number): void;
54
+ /** Exceptional export projection for fixtures, never a runtime fallback. */
55
+ export declare function exportSqliteState(db: DatabaseSync): SquareState;
56
+ /** Full read-only integrity inspection, including maintained-index replay comparison. */
57
+ export declare function inspectSqlite(db: DatabaseSync): {
58
+ standingCount: number;
59
+ };