@astrosheep/square 0.3.11 → 0.3.13

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 (127) hide show
  1. package/codex-plugin/.codex-plugin/plugin.json +1 -1
  2. package/codex-plugin/hooks/hooks.json +9 -0
  3. package/dist/activity-feed.d.ts +14 -0
  4. package/dist/activity-feed.js +5 -5
  5. package/dist/activity.d.ts +9 -0
  6. package/dist/activity.js +112 -96
  7. package/dist/artifact.d.ts +20 -0
  8. package/dist/artifact.js +317 -648
  9. package/dist/automatic-session.d.ts +5 -0
  10. package/dist/automatic-session.js +86 -0
  11. package/dist/boundary-presentation.d.ts +5 -0
  12. package/dist/boundary-presentation.js +6 -5
  13. package/dist/claude-hook.d.ts +9 -0
  14. package/dist/claude-hook.js +35 -3
  15. package/dist/cli/context.d.ts +35 -0
  16. package/dist/cli/context.js +26 -31
  17. package/dist/cli/harness-command.d.ts +28 -0
  18. package/dist/cli/harness-command.js +30 -15
  19. package/dist/cli/maintenance-commands.d.ts +7 -0
  20. package/dist/cli/maintenance-commands.js +12 -69
  21. package/dist/cli/meta-commands.d.ts +5 -0
  22. package/dist/cli/observation-commands.d.ts +20 -0
  23. package/dist/cli/observation-commands.js +159 -139
  24. package/dist/cli/program.d.ts +2 -0
  25. package/dist/cli/program.js +3 -12
  26. package/dist/cli/registry.d.ts +9 -0
  27. package/dist/cli/registry.js +2 -4
  28. package/dist/cli/square-commands.d.ts +34 -0
  29. package/dist/cli/square-commands.js +90 -84
  30. package/dist/cmd/notify-once.d.ts +2 -0
  31. package/dist/codex-hook.d.ts +10 -0
  32. package/dist/codex-hook.js +35 -3
  33. package/dist/decisions.d.ts +92 -0
  34. package/dist/decisions.js +93 -81
  35. package/dist/delivery-health.d.ts +21 -0
  36. package/dist/delivery-health.js +41 -34
  37. package/dist/delivery.d.ts +81 -0
  38. package/dist/delivery.js +71 -69
  39. package/dist/file-lock.d.ts +6 -0
  40. package/dist/harness-claude.d.ts +19 -0
  41. package/dist/harness-claude.js +8 -3
  42. package/dist/harness-codex.d.ts +29 -0
  43. package/dist/harness-codex.js +2 -2
  44. package/dist/harness-links.d.ts +17 -0
  45. package/dist/harness-links.js +2 -2
  46. package/dist/harness-pi.d.ts +11 -0
  47. package/dist/harness-pi.js +2 -2
  48. package/dist/harness-stage.d.ts +6 -0
  49. package/dist/harness.d.ts +20 -0
  50. package/dist/harness.js +5 -3
  51. package/dist/help.d.ts +6 -0
  52. package/dist/help.js +12 -13
  53. package/dist/identity.d.ts +13 -0
  54. package/dist/inbox.d.ts +2 -0
  55. package/dist/inbox.js +15 -19
  56. package/dist/index.d.ts +13 -0
  57. package/dist/index.js +31 -67
  58. package/dist/landing.d.ts +10 -0
  59. package/dist/landing.js +95 -0
  60. package/dist/list.d.ts +1 -0
  61. package/dist/list.js +39 -61
  62. package/dist/model.d.ts +147 -0
  63. package/dist/model.js +12 -8
  64. package/dist/notifications.d.ts +30 -0
  65. package/dist/notifications.js +83 -91
  66. package/dist/open-square.d.ts +11 -0
  67. package/dist/open-square.js +4 -0
  68. package/dist/participant-identity.d.ts +1 -0
  69. package/dist/participant-identity.js +3 -0
  70. package/dist/paseo-connection.d.ts +15 -0
  71. package/dist/paseo-delivery.d.ts +14 -0
  72. package/dist/paseo-state.d.ts +11 -0
  73. package/dist/paseo-timeline.d.ts +16 -0
  74. package/dist/presence.d.ts +3 -0
  75. package/dist/presence.js +42 -0
  76. package/dist/presentation.d.ts +91 -0
  77. package/dist/presentation.js +52 -63
  78. package/dist/presented.d.ts +11 -0
  79. package/dist/registry.d.ts +58 -0
  80. package/dist/registry.js +36 -3
  81. package/dist/routes.d.ts +42 -0
  82. package/dist/runtime.d.ts +45 -0
  83. package/dist/runtime.js +48 -55
  84. package/dist/search.d.ts +11 -0
  85. package/dist/square-core.d.ts +111 -0
  86. package/dist/square-core.js +63 -9
  87. package/dist/square-facade.d.ts +86 -0
  88. package/dist/square-facade.js +1 -0
  89. package/dist/square-file-adapter.d.ts +18 -0
  90. package/dist/square-file-adapter.js +70 -0
  91. package/dist/square-storage.d.ts +20 -0
  92. package/dist/square-storage.js +171 -0
  93. package/dist/square-wiring.d.ts +19 -0
  94. package/dist/square-wiring.js +70 -0
  95. package/dist/square.d.ts +2 -0
  96. package/dist/state-cell.d.ts +14 -0
  97. package/dist/state-cell.js +1 -0
  98. package/dist/stream.d.ts +3 -0
  99. package/dist/stream.js +19 -23
  100. package/dist/time.d.ts +6 -0
  101. package/dist/views.d.ts +95 -0
  102. package/dist/views.js +81 -0
  103. package/dist/wake-attempts.d.ts +39 -0
  104. package/dist/wake-attempts.js +8 -4
  105. package/dist/wake-evidence.d.ts +12 -0
  106. package/dist/wake-evidence.js +7 -10
  107. package/dist/wake-port.d.ts +20 -0
  108. package/dist/wake-sink.d.ts +12 -0
  109. package/dist/wakes.d.ts +40 -0
  110. package/dist/wakes.js +62 -0
  111. package/dist/watch.d.ts +2 -0
  112. package/dist/watch.js +89 -210
  113. package/extensions/square-opencode.js +27 -1
  114. package/extensions/square-pi.js +13 -0
  115. package/guides/participant.md +7 -174
  116. package/package.json +5 -4
  117. package/skills/brainstorm/SKILL.md +30 -30
  118. package/skills/square/.claude-plugin/plugin.json +1 -1
  119. package/skills/square/SKILL.md +56 -29
  120. package/skills/square/hooks/hooks.json +9 -0
  121. package/skills/square-feedback/SKILL.md +9 -9
  122. package/dist/compact.js +0 -26
  123. package/dist/doctor.js +0 -36
  124. package/dist/square-application.js +0 -262
  125. package/template.md +0 -4
  126. package/templates/architect.md +0 -4
  127. package/templates/brainstorm.md +0 -4
@@ -1,262 +0,0 @@
1
- import fs from 'node:fs';
2
- import path from 'node:path';
3
- import { emptyRuntimeState, loadRuntimeSidecar, loadSquare, mergeRuntimeState, renderArtifactAct, renderSquare, renderSquareDoc, saveRuntimeSidecar } from './artifact.js';
4
- import { coreCompact, coreDone, coreHold, coreResume, decideAct, decideJoin, resolveKnownName } from './decisions.js';
5
- import { planRepair } from './doctor.js';
6
- import { withFileLock } from './file-lock.js';
7
- import { stageReplacement } from './harness-stage.js';
8
- import { SquareError } from './model.js';
9
- import { advanceCursor, freshWatchLease, LOCK_RETRY_MS, LOCK_STALE_MS, removeWatchLease, touchPresenceCursor, watchLease, writeWatchLease } from './runtime.js';
10
- /** The only persistence primitive: one per-square lock, one Markdown write, one sidecar write. */
11
- export async function withSquareLock(squarePath, fn) {
12
- return withFileLock(`${squarePath}.lock`, { retryMs: LOCK_RETRY_MS, staleMs: LOCK_STALE_MS }, fn);
13
- }
14
- export function writeSquareDoc(squarePath, doc) {
15
- const temporary = path.join(path.dirname(squarePath), `.${path.basename(squarePath)}.${process.pid}.${Date.now()}.tmp`);
16
- fs.writeFileSync(temporary, renderSquareDoc(doc));
17
- fs.renameSync(temporary, squarePath);
18
- saveRuntimeSidecar(squarePath, doc.runtime);
19
- }
20
- export function appendAct(squarePath, doc, act) {
21
- const stored = applyActs(doc, [act])[0];
22
- writeSquareDoc(squarePath, doc);
23
- return stored;
24
- }
25
- function applyActs(doc, acts, mutateRuntime) {
26
- const stored = [];
27
- for (const act of acts) {
28
- const item = { ...act, index: doc.runtime.nextActIndex };
29
- doc.runtime.nextActIndex++;
30
- doc.acts.push(item);
31
- if (item.actor !== undefined)
32
- touchPresenceCursor(doc, item.actor, item.at, item.index);
33
- stored.push(item);
34
- }
35
- mutateRuntime?.(doc);
36
- return stored;
37
- }
38
- /**
39
- * Publish a dependent persistence file before the Square document. A retained
40
- * backup lets a failed document commit restore the prior file exactly.
41
- */
42
- function prepareAppend(filePath, block, existing = fs.existsSync(filePath) ? fs.readFileSync(filePath, 'utf8') : '') {
43
- return stageReplacement(filePath, (stage) => {
44
- fs.writeFileSync(stage, `${existing}${existing === '' ? '' : '\n'}${block}\n`);
45
- });
46
- }
47
- function plan(doc, intent) {
48
- switch (intent.type) {
49
- case 'join': {
50
- const decision = decideJoin(doc, intent.name, intent.now);
51
- return { result: decision, acts: [decision.joinAct] };
52
- }
53
- case 'say': {
54
- const decision = decideAct(doc, intent);
55
- return {
56
- result: decision,
57
- acts: decision.type === 'sent' ? [decision.act] : [],
58
- };
59
- }
60
- case 'hold':
61
- return { result: undefined, acts: [coreHold(doc, intent.actor, intent.body, intent.now)] };
62
- case 'resume':
63
- return { result: undefined, acts: [coreResume(doc, intent.actor, intent.now)] };
64
- case 'done':
65
- return { result: undefined, acts: [coreDone(doc, intent.name, intent.body, intent.now)] };
66
- case 'lease': {
67
- const name = resolveKnownName(doc, intent.name);
68
- const existing = freshWatchLease(doc, name, intent.at);
69
- if (existing !== undefined && !intent.force) {
70
- return { result: { type: 'active', lease: existing }, acts: [] };
71
- }
72
- return {
73
- result: { type: 'started', name, replaced: existing !== undefined },
74
- acts: [],
75
- mutateRuntime: (nextDoc) => {
76
- writeWatchLease(nextDoc, name, {
77
- leaseId: intent.leaseId,
78
- ...(intent.ownerId === undefined ? {} : { ownerId: intent.ownerId }),
79
- heartbeatAt: intent.at,
80
- expiresAt: intent.expiresAt,
81
- ...(intent.filter === undefined ? {} : { filter: intent.filter }),
82
- });
83
- touchPresenceCursor(nextDoc, name, intent.at);
84
- },
85
- };
86
- }
87
- case 'release-lease': {
88
- const name = resolveKnownName(doc, intent.name);
89
- if (watchLease(doc, name)?.leaseId !== intent.leaseId) {
90
- return { result: { released: false }, acts: [] };
91
- }
92
- return {
93
- result: { released: true },
94
- acts: [],
95
- mutateRuntime: (nextDoc) => { removeWatchLease(nextDoc, name, intent.leaseId); },
96
- };
97
- }
98
- case 'claim-notify': {
99
- const current = doc.runtime.notifyLeases[intent.key];
100
- if (current !== undefined && current.expiresAt > intent.at)
101
- return { result: { type: 'busy' }, acts: [] };
102
- if (current?.phase === 'dispatching')
103
- return { result: { type: 'ambiguous', lease: current }, acts: [] };
104
- return {
105
- result: { type: 'acquired', leaseId: intent.leaseId },
106
- acts: [],
107
- mutateRuntime: (nextDoc) => {
108
- nextDoc.runtime.notifyLeases[intent.key] = {
109
- leaseId: intent.leaseId,
110
- expiresAt: intent.expiresAt,
111
- phase: 'claimed',
112
- };
113
- },
114
- };
115
- }
116
- case 'transition-notify': {
117
- if (doc.runtime.notifyLeases[intent.key]?.leaseId !== intent.leaseId)
118
- return { result: { updated: false }, acts: [] };
119
- return {
120
- result: { updated: true },
121
- acts: [],
122
- mutateRuntime: (nextDoc) => {
123
- nextDoc.runtime.notifyLeases[intent.key] = {
124
- leaseId: intent.leaseId,
125
- expiresAt: intent.expiresAt,
126
- phase: intent.phase,
127
- ...(intent.attemptN === undefined ? {} : { attemptN: intent.attemptN }),
128
- ...(intent.routeKind === undefined ? {} : { routeKind: intent.routeKind }),
129
- };
130
- },
131
- };
132
- }
133
- case 'release-notify': {
134
- if (doc.runtime.notifyLeases[intent.key]?.leaseId !== intent.leaseId)
135
- return { result: { released: false }, acts: [] };
136
- return {
137
- result: { released: true },
138
- acts: [],
139
- mutateRuntime: (nextDoc) => { delete nextDoc.runtime.notifyLeases[intent.key]; },
140
- };
141
- }
142
- case 'consume': {
143
- const name = resolveKnownName(doc, intent.name);
144
- return {
145
- result: { name },
146
- acts: [],
147
- mutateRuntime: (nextDoc) => { advanceCursor(nextDoc, name, intent.throughIndex, intent.at); },
148
- };
149
- }
150
- case 'compact': {
151
- const result = coreCompact(doc, intent.keep);
152
- const archive = result.archived;
153
- return {
154
- result,
155
- acts: [],
156
- replaceDoc: result.doc,
157
- preparePersistence: archive.length === 0
158
- ? undefined
159
- : () => {
160
- const existing = fs.existsSync(intent.archivePath) ? fs.readFileSync(intent.archivePath, 'utf8') : '';
161
- const block = archive
162
- .map((act, index) => renderArtifactAct(act, { first: existing === '' && index === 0 }))
163
- .join('\n');
164
- return prepareAppend(intent.archivePath, block, existing);
165
- },
166
- };
167
- }
168
- case 'repair':
169
- return {
170
- result: undefined,
171
- acts: [],
172
- replaceDoc: intent.doc,
173
- preparePersistence: intent.quarantine === undefined || intent.quarantine.blocks.length === 0
174
- ? undefined
175
- : () => {
176
- const block = intent.quarantine.blocks.join('\n\n');
177
- return prepareAppend(intent.quarantine.path, block);
178
- },
179
- };
180
- }
181
- }
182
- function commitPlan(squarePath, doc, planned) {
183
- const nextDoc = planned.replaceDoc ?? doc;
184
- const committed = { result: planned.result, acts: applyActs(nextDoc, planned.acts, planned.mutateRuntime) };
185
- if (planned.acts.length === 0 && planned.mutateRuntime === undefined && planned.replaceDoc === undefined) {
186
- return committed;
187
- }
188
- let persistence;
189
- try {
190
- persistence = planned.preparePersistence?.();
191
- writeSquareDoc(squarePath, nextDoc);
192
- persistence?.finalize();
193
- return committed;
194
- }
195
- catch (error) {
196
- try {
197
- persistence?.rollback();
198
- }
199
- catch { }
200
- throw error;
201
- }
202
- }
203
- /** The one mutation pipeline shared by package and CLI adapters. */
204
- export async function execute(squarePath, intent) {
205
- return withSquareLock(squarePath, () => {
206
- const doc = loadSquare(squarePath);
207
- return commitPlan(squarePath, doc, plan(doc, intent));
208
- });
209
- }
210
- /** Application-owned artifact creation; adapters provide validated options and stdin text only. */
211
- export async function createSquare(squarePath, options, snippet) {
212
- await withSquareLock(squarePath, () => {
213
- if (fs.existsSync(squarePath) && !options.force) {
214
- throw new SquareError('conflict', `Refusing to overwrite existing square: ${squarePath}\nPass -f to overwrite.`);
215
- }
216
- const temporary = path.join(path.dirname(squarePath), `.${path.basename(squarePath)}.${process.pid}.${Date.now()}.tmp`);
217
- fs.mkdirSync(path.dirname(squarePath), { recursive: true });
218
- fs.writeFileSync(temporary, renderSquare(options, snippet));
219
- fs.renameSync(temporary, squarePath);
220
- saveRuntimeSidecar(squarePath, emptyRuntimeState(0));
221
- });
222
- }
223
- /** Keep artifact repair planning and dependent quarantine persistence inside the application boundary. */
224
- export async function repairSquare(squarePath) {
225
- const result = await withSquareLock(squarePath, () => {
226
- let text;
227
- try {
228
- text = fs.readFileSync(squarePath, 'utf8');
229
- }
230
- catch (error) {
231
- if (error.code === 'ENOENT')
232
- throw new SquareError('not_found', `square file not found: ${squarePath}`);
233
- throw error;
234
- }
235
- const repair = planRepair(text);
236
- if (repair.diagnosis.unfixable || repair.repaired === undefined)
237
- return { repair };
238
- // Repair changes Markdown only. Keep the sidecar's runtime metadata and
239
- // merge history boundaries so a doctor run cannot erase delivery state or
240
- // reuse a stable activity index.
241
- const sidecarRuntime = loadRuntimeSidecar(squarePath, repair.repaired.doc.runtime);
242
- const indexesPreserved = repair.diagnosis.acts.every(({ act }, index) => repair.repaired.doc.acts[index]?.index === act.index);
243
- if (indexesPreserved) {
244
- repair.repaired.doc.runtime = mergeRuntimeState(repair.repaired.doc.runtime, sidecarRuntime);
245
- }
246
- else {
247
- repair.repaired.doc.runtime = emptyRuntimeState(Math.max(repair.repaired.doc.runtime.nextActIndex, sidecarRuntime.nextActIndex));
248
- repair.repaired.actions.push({ message: 'reset runtime delivery metadata because act indexes changed' });
249
- }
250
- const quarantinePath = squarePath.replace(/\.md$/, '') + '.quarantine.md';
251
- const intent = {
252
- type: 'repair',
253
- doc: repair.repaired.doc,
254
- ...(repair.repaired.quarantinedBlocks.length === 0
255
- ? {}
256
- : { quarantine: { path: quarantinePath, blocks: repair.repaired.quarantinedBlocks } }),
257
- };
258
- commitPlan(squarePath, repair.repaired.doc, plan(repair.repaired.doc, intent));
259
- return { repair };
260
- });
261
- return result.repair;
262
- }
package/template.md DELETED
@@ -1,4 +0,0 @@
1
- ---
2
-
3
- ## Activities
4
- <!-- square:activities -->
@@ -1,4 +0,0 @@
1
- ---
2
-
3
- ## Activities
4
- <!-- square:activities -->
@@ -1,4 +0,0 @@
1
- ---
2
-
3
- ## Activities
4
- <!-- square:activities -->