@fungi.computer/agar 0.0.0-stage → 0.0.1

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 (159) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +766 -2
  3. package/dist/agent-message-meta.d.ts +74 -0
  4. package/dist/agent-message-meta.js +63 -0
  5. package/dist/agents.d.ts +170 -0
  6. package/dist/agents.js +218 -0
  7. package/dist/app-build-contract.d.ts +43 -0
  8. package/dist/app-build-contract.js +24 -0
  9. package/dist/apps.d.ts +66 -0
  10. package/dist/apps.js +47 -0
  11. package/dist/backend-declaration.d.ts +6 -0
  12. package/dist/backend-declaration.js +65 -0
  13. package/dist/backend-definition.d.ts +88 -0
  14. package/dist/backend-definition.js +158 -0
  15. package/dist/backend-refusal.d.ts +10 -0
  16. package/dist/backend-refusal.js +10 -0
  17. package/dist/backend.d.ts +30 -0
  18. package/dist/backend.js +28 -0
  19. package/dist/capabilities.d.ts +30 -0
  20. package/dist/capabilities.js +50 -0
  21. package/dist/channels.d.ts +142 -0
  22. package/dist/channels.js +97 -0
  23. package/dist/commands.d.ts +33 -0
  24. package/dist/commands.js +46 -0
  25. package/dist/computer-contracts.d.ts +73 -0
  26. package/dist/computer-contracts.js +57 -0
  27. package/dist/computer.d.ts +294 -0
  28. package/dist/computer.js +319 -0
  29. package/dist/connect.d.ts +11 -0
  30. package/dist/connect.js +211 -0
  31. package/dist/errors.d.ts +34 -0
  32. package/dist/errors.js +106 -0
  33. package/dist/failure.d.ts +2 -0
  34. package/dist/failure.js +9 -0
  35. package/dist/files.d.ts +25 -0
  36. package/dist/files.js +84 -0
  37. package/dist/game-servers.d.ts +530 -0
  38. package/dist/game-servers.js +244 -0
  39. package/dist/gills.d.ts +43 -0
  40. package/dist/gills.js +174 -0
  41. package/dist/git-commit.d.ts +143 -0
  42. package/dist/git-commit.js +251 -0
  43. package/dist/git-rpc.d.ts +310 -0
  44. package/dist/git-rpc.js +166 -0
  45. package/dist/git-steps.d.ts +579 -0
  46. package/dist/git-steps.js +804 -0
  47. package/dist/git-wire.d.ts +33 -0
  48. package/dist/git-wire.js +240 -0
  49. package/dist/git.d.ts +322 -0
  50. package/dist/git.js +98 -0
  51. package/dist/host.d.ts +97 -0
  52. package/dist/host.js +732 -0
  53. package/dist/inbox.d.ts +99 -0
  54. package/dist/inbox.js +184 -0
  55. package/dist/index.d.ts +31 -0
  56. package/dist/index.js +15 -0
  57. package/dist/inference.d.ts +17 -0
  58. package/dist/inference.js +115 -0
  59. package/dist/internal/app-error.d.ts +8 -0
  60. package/dist/internal/app-error.js +36 -0
  61. package/dist/internal/app-session.d.ts +8 -0
  62. package/dist/internal/app-session.js +551 -0
  63. package/dist/internal/back-inputs.d.ts +22 -0
  64. package/dist/internal/back-inputs.js +93 -0
  65. package/dist/internal/browser-bridge.d.ts +30 -0
  66. package/dist/internal/browser-bridge.js +203 -0
  67. package/dist/internal/capabilities.d.ts +13 -0
  68. package/dist/internal/capabilities.js +138 -0
  69. package/dist/internal/commands.d.ts +9 -0
  70. package/dist/internal/commands.js +257 -0
  71. package/dist/internal/disconnect-host.d.ts +7 -0
  72. package/dist/internal/disconnect-host.js +19 -0
  73. package/dist/internal/git-edit-tree.d.ts +6 -0
  74. package/dist/internal/git-edit-tree.js +46 -0
  75. package/dist/internal/memory-fs.d.ts +39 -0
  76. package/dist/internal/memory-fs.js +154 -0
  77. package/dist/internal/protocol.d.ts +116 -0
  78. package/dist/internal/protocol.js +6 -0
  79. package/dist/internal/query-feed.d.ts +23 -0
  80. package/dist/internal/query-feed.js +111 -0
  81. package/dist/internal/result.d.ts +22 -0
  82. package/dist/internal/result.js +61 -0
  83. package/dist/internal/rpc-contract.d.ts +24 -0
  84. package/dist/internal/rpc-contract.js +78 -0
  85. package/dist/internal/schemas.d.ts +307 -0
  86. package/dist/internal/schemas.js +524 -0
  87. package/dist/internal/store.d.ts +8 -0
  88. package/dist/internal/store.js +30 -0
  89. package/dist/internal/terminal-gate.d.ts +17 -0
  90. package/dist/internal/terminal-gate.js +94 -0
  91. package/dist/lifecycle.d.ts +44 -0
  92. package/dist/lifecycle.js +1 -0
  93. package/dist/marketplace.d.ts +159 -0
  94. package/dist/marketplace.js +102 -0
  95. package/dist/media-json.d.ts +181 -0
  96. package/dist/media-json.js +204 -0
  97. package/dist/media-library.d.ts +11 -0
  98. package/dist/media-library.js +15 -0
  99. package/dist/media-request-id.d.ts +7 -0
  100. package/dist/media-request-id.js +16 -0
  101. package/dist/media.d.ts +354 -0
  102. package/dist/media.js +654 -0
  103. package/dist/method-refusal.d.ts +64 -0
  104. package/dist/method-refusal.js +48 -0
  105. package/dist/pending.d.ts +10 -0
  106. package/dist/pending.js +10 -0
  107. package/dist/query.d.ts +76 -0
  108. package/dist/query.js +195 -0
  109. package/dist/react-mount.d.ts +23 -0
  110. package/dist/react-mount.js +108 -0
  111. package/dist/react.d.ts +41 -0
  112. package/dist/react.js +111 -0
  113. package/dist/read-copy.d.ts +103 -0
  114. package/dist/read-copy.js +195 -0
  115. package/dist/roles/files.d.ts +295 -0
  116. package/dist/roles/files.js +184 -0
  117. package/dist/root.d.ts +21 -0
  118. package/dist/root.js +1 -0
  119. package/dist/rpc.d.ts +1 -0
  120. package/dist/rpc.js +1 -0
  121. package/dist/status.d.ts +17 -0
  122. package/dist/status.js +50 -0
  123. package/dist/storage-wire.d.ts +167 -0
  124. package/dist/storage-wire.js +115 -0
  125. package/dist/storage.d.ts +72 -0
  126. package/dist/storage.js +143 -0
  127. package/dist/store.d.ts +11 -0
  128. package/dist/store.js +1 -0
  129. package/dist/test-kit/git.d.ts +31 -0
  130. package/dist/test-kit/git.js +174 -0
  131. package/dist/ui.d.ts +169 -0
  132. package/dist/ui.js +10 -0
  133. package/dist/window.d.ts +41 -0
  134. package/dist/window.js +15 -0
  135. package/dist/world.d.ts +16 -0
  136. package/dist/world.js +17 -0
  137. package/docs/api/README.md +28 -0
  138. package/docs/api/app-build-contract.md +113 -0
  139. package/docs/api/backend-declaration.md +62 -0
  140. package/docs/api/backend-definition.md +215 -0
  141. package/docs/api/backend.md +269 -0
  142. package/docs/api/errors.md +169 -0
  143. package/docs/api/files.md +91 -0
  144. package/docs/api/gills.md +164 -0
  145. package/docs/api/git-commit.md +279 -0
  146. package/docs/api/git-rpc.md +243 -0
  147. package/docs/api/git-steps.md +1010 -0
  148. package/docs/api/git-wire.md +197 -0
  149. package/docs/api/git.md +579 -0
  150. package/docs/api/index.md +2880 -0
  151. package/docs/api/media-json.md +507 -0
  152. package/docs/api/media-request-id.md +32 -0
  153. package/docs/api/modules.md +32 -0
  154. package/docs/api/query.md +253 -0
  155. package/docs/api/react.md +216 -0
  156. package/docs/api/read-copy.md +204 -0
  157. package/docs/api/rpc.md +128 -0
  158. package/docs/api/storage.md +620 -0
  159. package/package.json +197 -3
@@ -0,0 +1,295 @@
1
+ /**
2
+ * The `files` App role contract. An App that fills the Team's files role
3
+ * receives a {@link FilesLocation} through an `apps.open` navigate intent, and
4
+ * file browsing, edit and snapshot payloads travel in these shapes. Role names
5
+ * belong to Puffball's App vocabulary; this module owns the files role's wire.
6
+ */
7
+ import * as z from "zod";
8
+ import type { AppNavigateIntent } from "../apps.js";
9
+ /** The App role this contract serves. */
10
+ export declare const filesRole = "files";
11
+ export declare const commit: z.ZodObject<{
12
+ hash: z.ZodString;
13
+ treeHash: z.ZodString;
14
+ message: z.ZodString;
15
+ author: z.ZodObject<{
16
+ name: z.ZodString;
17
+ email: z.ZodString;
18
+ }, z.core.$strict>;
19
+ committer: z.ZodObject<{
20
+ name: z.ZodString;
21
+ email: z.ZodString;
22
+ }, z.core.$strict>;
23
+ parents: z.ZodArray<z.ZodString>;
24
+ authoredAt: z.ZodNumber;
25
+ committedAt: z.ZodNumber;
26
+ }, z.core.$strict>;
27
+ export type Commit = z.infer<typeof commit>;
28
+ export declare const treeEntry: z.ZodObject<{
29
+ name: z.ZodString;
30
+ mode: z.ZodString;
31
+ hash: z.ZodString;
32
+ type: z.ZodEnum<{
33
+ blob: "blob";
34
+ tree: "tree";
35
+ commit: "commit";
36
+ }>;
37
+ }, z.core.$strict>;
38
+ export type TreeEntry = z.infer<typeof treeEntry>;
39
+ export declare const treeListing: z.ZodObject<{
40
+ ref: z.ZodString;
41
+ commit: z.ZodObject<{
42
+ hash: z.ZodString;
43
+ treeHash: z.ZodString;
44
+ message: z.ZodString;
45
+ author: z.ZodObject<{
46
+ name: z.ZodString;
47
+ email: z.ZodString;
48
+ }, z.core.$strict>;
49
+ committer: z.ZodObject<{
50
+ name: z.ZodString;
51
+ email: z.ZodString;
52
+ }, z.core.$strict>;
53
+ parents: z.ZodArray<z.ZodString>;
54
+ authoredAt: z.ZodNumber;
55
+ committedAt: z.ZodNumber;
56
+ }, z.core.$strict>;
57
+ path: z.ZodString;
58
+ entries: z.ZodArray<z.ZodObject<{
59
+ name: z.ZodString;
60
+ mode: z.ZodString;
61
+ hash: z.ZodString;
62
+ type: z.ZodEnum<{
63
+ blob: "blob";
64
+ tree: "tree";
65
+ commit: "commit";
66
+ }>;
67
+ }, z.core.$strict>>;
68
+ }, z.core.$strict>;
69
+ export type TreeListing = z.infer<typeof treeListing>;
70
+ /** Saved text stays bounded by the admitted file-edit request. */
71
+ export declare const repositoryFileByteLimit: number;
72
+ export declare const repositoryFilePath: z.ZodString;
73
+ /** A repository branch name as the files role carries it. */
74
+ export declare const repositoryBranch: z.ZodString;
75
+ export declare const fileEditState: z.ZodEnum<{
76
+ failed: "failed";
77
+ pending: "pending";
78
+ conflict: "conflict";
79
+ synced: "synced";
80
+ }>;
81
+ export declare const pendingFileEdit: z.ZodObject<{
82
+ text: z.ZodString;
83
+ revision: z.ZodNumber;
84
+ state: z.ZodEnum<{
85
+ failed: "failed";
86
+ pending: "pending";
87
+ conflict: "conflict";
88
+ synced: "synced";
89
+ }>;
90
+ theirs: z.ZodOptional<z.ZodObject<{
91
+ blob: z.ZodNullable<z.ZodString>;
92
+ commit: z.ZodString;
93
+ }, z.core.$strict>>;
94
+ failure: z.ZodOptional<z.ZodEnum<{
95
+ branch_missing: "branch_missing";
96
+ access_changed: "access_changed";
97
+ sync_failed: "sync_failed";
98
+ permanent_material: "permanent_material";
99
+ }>>;
100
+ }, z.core.$strict>;
101
+ export declare const fileSaveInput: z.ZodObject<{
102
+ baseBlob: z.ZodNullable<z.ZodString>;
103
+ baseCommit: z.ZodString;
104
+ text: z.ZodString;
105
+ revision: z.ZodNullable<z.ZodNumber>;
106
+ repo: z.ZodString;
107
+ branch: z.ZodString;
108
+ path: z.ZodString;
109
+ }, z.core.$strict>;
110
+ export declare const fileSaveResult: z.ZodUnion<readonly [z.ZodObject<{
111
+ kind: z.ZodLiteral<"saved">;
112
+ revision: z.ZodNumber;
113
+ state: z.ZodLiteral<"pending">;
114
+ }, z.core.$strict>, z.ZodObject<{
115
+ kind: z.ZodLiteral<"synced">;
116
+ revision: z.ZodNumber;
117
+ commit: z.ZodString;
118
+ }, z.core.$strict>, z.ZodObject<{
119
+ kind: z.ZodLiteral<"conflict">;
120
+ revision: z.ZodNumber;
121
+ theirs: z.ZodOptional<z.ZodOptional<z.ZodObject<{
122
+ blob: z.ZodNullable<z.ZodString>;
123
+ commit: z.ZodString;
124
+ }, z.core.$strict>>>;
125
+ }, z.core.$strict>, z.ZodObject<{
126
+ kind: z.ZodLiteral<"failed">;
127
+ revision: z.ZodNumber;
128
+ reason: z.ZodEnum<{
129
+ branch_missing: "branch_missing";
130
+ access_changed: "access_changed";
131
+ sync_failed: "sync_failed";
132
+ permanent_material: "permanent_material";
133
+ }>;
134
+ }, z.core.$strict>, z.ZodObject<{
135
+ kind: z.ZodLiteral<"refused">;
136
+ reason: z.ZodEnum<{
137
+ "not-source-writer": "not-source-writer";
138
+ "background-unavailable": "background-unavailable";
139
+ }>;
140
+ }, z.core.$strict>]>;
141
+ export declare const fileDiscardInput: z.ZodObject<{
142
+ revision: z.ZodNumber;
143
+ repo: z.ZodString;
144
+ branch: z.ZodString;
145
+ path: z.ZodString;
146
+ }, z.core.$strict>;
147
+ export declare const fileDiscardResult: z.ZodUnion<readonly [z.ZodObject<{
148
+ kind: z.ZodEnum<{
149
+ not_found: "not_found";
150
+ discarded: "discarded";
151
+ }>;
152
+ }, z.core.$strict>, z.ZodObject<{
153
+ kind: z.ZodLiteral<"conflict">;
154
+ revision: z.ZodNumber;
155
+ }, z.core.$strict>]>;
156
+ export declare const fileSyncResult: z.ZodObject<{
157
+ settled: z.ZodArray<z.ZodObject<{
158
+ result: z.ZodUnion<readonly [z.ZodObject<{
159
+ kind: z.ZodLiteral<"saved">;
160
+ revision: z.ZodNumber;
161
+ state: z.ZodLiteral<"pending">;
162
+ }, z.core.$strict>, z.ZodObject<{
163
+ kind: z.ZodLiteral<"synced">;
164
+ revision: z.ZodNumber;
165
+ commit: z.ZodString;
166
+ }, z.core.$strict>, z.ZodObject<{
167
+ kind: z.ZodLiteral<"conflict">;
168
+ revision: z.ZodNumber;
169
+ theirs: z.ZodOptional<z.ZodOptional<z.ZodObject<{
170
+ blob: z.ZodNullable<z.ZodString>;
171
+ commit: z.ZodString;
172
+ }, z.core.$strict>>>;
173
+ }, z.core.$strict>, z.ZodObject<{
174
+ kind: z.ZodLiteral<"failed">;
175
+ revision: z.ZodNumber;
176
+ reason: z.ZodEnum<{
177
+ branch_missing: "branch_missing";
178
+ access_changed: "access_changed";
179
+ sync_failed: "sync_failed";
180
+ permanent_material: "permanent_material";
181
+ }>;
182
+ }, z.core.$strict>, z.ZodObject<{
183
+ kind: z.ZodLiteral<"refused">;
184
+ reason: z.ZodEnum<{
185
+ "not-source-writer": "not-source-writer";
186
+ "background-unavailable": "background-unavailable";
187
+ }>;
188
+ }, z.core.$strict>]>;
189
+ repo: z.ZodString;
190
+ branch: z.ZodString;
191
+ path: z.ZodString;
192
+ }, z.core.$strict>>;
193
+ more: z.ZodBoolean;
194
+ }, z.core.$strict>;
195
+ export type FileSaveInput = z.output<typeof fileSaveInput>;
196
+ export type FileSaveResult = z.output<typeof fileSaveResult>;
197
+ export declare const fileContent: z.ZodObject<{
198
+ version: z.ZodNullable<z.ZodNumber>;
199
+ commit: z.ZodString;
200
+ blob: z.ZodNullable<z.ZodString>;
201
+ pending: z.ZodOptional<z.ZodObject<{
202
+ text: z.ZodString;
203
+ revision: z.ZodNumber;
204
+ state: z.ZodEnum<{
205
+ failed: "failed";
206
+ pending: "pending";
207
+ conflict: "conflict";
208
+ synced: "synced";
209
+ }>;
210
+ theirs: z.ZodOptional<z.ZodObject<{
211
+ blob: z.ZodNullable<z.ZodString>;
212
+ commit: z.ZodString;
213
+ }, z.core.$strict>>;
214
+ failure: z.ZodOptional<z.ZodEnum<{
215
+ branch_missing: "branch_missing";
216
+ access_changed: "access_changed";
217
+ sync_failed: "sync_failed";
218
+ permanent_material: "permanent_material";
219
+ }>>;
220
+ }, z.core.$strict>>;
221
+ ref: z.ZodString;
222
+ path: z.ZodString;
223
+ size: z.ZodNumber;
224
+ binary: z.ZodBoolean;
225
+ text: z.ZodNullable<z.ZodString>;
226
+ }, z.core.$strict>;
227
+ export type FileContent = z.infer<typeof fileContent>;
228
+ export declare const commitPage: z.ZodObject<{
229
+ ref: z.ZodString;
230
+ commits: z.ZodArray<z.ZodObject<{
231
+ commit: z.ZodObject<{
232
+ hash: z.ZodString;
233
+ treeHash: z.ZodString;
234
+ message: z.ZodString;
235
+ author: z.ZodObject<{
236
+ name: z.ZodString;
237
+ email: z.ZodString;
238
+ }, z.core.$strict>;
239
+ committer: z.ZodObject<{
240
+ name: z.ZodString;
241
+ email: z.ZodString;
242
+ }, z.core.$strict>;
243
+ parents: z.ZodArray<z.ZodString>;
244
+ authoredAt: z.ZodNumber;
245
+ committedAt: z.ZodNumber;
246
+ }, z.core.$strict>;
247
+ agent: z.ZodNullable<z.ZodString>;
248
+ }, z.core.$strict>>;
249
+ next: z.ZodOptional<z.ZodString>;
250
+ }, z.core.$strict>;
251
+ export type CommitPage = z.infer<typeof commitPage>;
252
+ /** Every path at a commit: files, and directories with a trailing slash. */
253
+ export declare const fileList: z.ZodObject<{
254
+ ref: z.ZodString;
255
+ commit: z.ZodObject<{
256
+ hash: z.ZodString;
257
+ treeHash: z.ZodString;
258
+ message: z.ZodString;
259
+ author: z.ZodObject<{
260
+ name: z.ZodString;
261
+ email: z.ZodString;
262
+ }, z.core.$strict>;
263
+ committer: z.ZodObject<{
264
+ name: z.ZodString;
265
+ email: z.ZodString;
266
+ }, z.core.$strict>;
267
+ parents: z.ZodArray<z.ZodString>;
268
+ authoredAt: z.ZodNumber;
269
+ committedAt: z.ZodNumber;
270
+ }, z.core.$strict>;
271
+ paths: z.ZodArray<z.ZodString>;
272
+ truncated: z.ZodBoolean;
273
+ }, z.core.$strict>;
274
+ export type FileList = z.infer<typeof fileList>;
275
+ /** A foreground copy rebuild needs another admitted method frame. */
276
+ export declare const readCopyRebuilding: z.ZodObject<{
277
+ kind: z.ZodLiteral<"rebuilding">;
278
+ }, z.core.$strict>;
279
+ export declare const copyRebuildPage: z.ZodObject<{
280
+ done: z.ZodBoolean;
281
+ cursor: z.ZodNullable<z.ZodString>;
282
+ }, z.core.$strict>;
283
+ /** Where the files role opens: a repository file at a branch, or a Computer file. */
284
+ export declare const filesLocation: z.ZodUnion<readonly [z.ZodObject<{
285
+ repository: z.ZodString;
286
+ branch: z.ZodString;
287
+ path: z.ZodString;
288
+ }, z.core.$strict>, z.ZodObject<{
289
+ path: z.ZodString;
290
+ }, z.core.$strict>]>;
291
+ export type FilesLocation = z.output<typeof filesLocation>;
292
+ /** The `apps.open` navigate intent that opens a location in the files role App. */
293
+ export declare function filesNavigateIntent(location: FilesLocation): AppNavigateIntent;
294
+ /** Decode a received navigate intent's params; null when they name no files location. */
295
+ export declare function readFilesLocation(params: AppNavigateIntent["params"]): FilesLocation | null;
@@ -0,0 +1,184 @@
1
+ /**
2
+ * The `files` App role contract. An App that fills the Team's files role
3
+ * receives a {@link FilesLocation} through an `apps.open` navigate intent, and
4
+ * file browsing, edit and snapshot payloads travel in these shapes. Role names
5
+ * belong to Puffball's App vocabulary; this module owns the files role's wire.
6
+ */
7
+ import * as z from "zod";
8
+ import { gitRepositoryNameSchema as repoName, gitSha1Schema as hash, } from "@fungi.computer/puffball/git-representation";
9
+ /** The App role this contract serves. */
10
+ export const filesRole = "files";
11
+ const person = z.strictObject({
12
+ name: z.string(),
13
+ email: z.string(),
14
+ });
15
+ export const commit = z.strictObject({
16
+ hash,
17
+ treeHash: hash,
18
+ message: z.string(),
19
+ author: person,
20
+ committer: person,
21
+ parents: z.array(hash),
22
+ authoredAt: z.number(),
23
+ committedAt: z.number(),
24
+ });
25
+ export const treeEntry = z.strictObject({
26
+ name: z.string(),
27
+ mode: z.string(),
28
+ hash,
29
+ /** Git object kind; executable and symlink permissions live in mode. */
30
+ type: z.enum(["blob", "tree", "commit"]),
31
+ });
32
+ export const treeListing = z.strictObject({
33
+ ref: z.string(),
34
+ commit: commit,
35
+ path: z.string(),
36
+ entries: z.array(treeEntry),
37
+ });
38
+ /** Saved text stays bounded by the admitted file-edit request. */
39
+ export const repositoryFileByteLimit = 64 * 1024;
40
+ export const repositoryFilePath = z
41
+ .string()
42
+ .min(1)
43
+ .max(1024)
44
+ .refine((path) => !path.startsWith("/") &&
45
+ !path.includes("\\") &&
46
+ !path.includes("\0") &&
47
+ path
48
+ .split("/")
49
+ .every((part) => part !== "" && part !== "." && part !== ".." && part !== ".git"), "Choose a relative repository file path.");
50
+ /** A repository branch name as the files role carries it. */
51
+ export const repositoryBranch = z.string().min(1).max(256);
52
+ const editKey = {
53
+ repo: repoName,
54
+ branch: repositoryBranch,
55
+ path: repositoryFilePath,
56
+ };
57
+ export const fileEditState = z.enum([
58
+ "pending",
59
+ "synced",
60
+ "conflict",
61
+ "failed",
62
+ ]);
63
+ export const pendingFileEdit = z.strictObject({
64
+ text: z.string(),
65
+ revision: z.number().int().positive(),
66
+ state: fileEditState,
67
+ theirs: z.strictObject({ blob: hash.nullable(), commit: hash }).optional(),
68
+ failure: z
69
+ .enum([
70
+ "branch_missing",
71
+ "access_changed",
72
+ "sync_failed",
73
+ "permanent_material",
74
+ ])
75
+ .optional(),
76
+ });
77
+ export const fileSaveInput = z.strictObject({
78
+ ...editKey,
79
+ baseBlob: hash.nullable(),
80
+ baseCommit: hash,
81
+ text: z.string().max(repositoryFileByteLimit),
82
+ revision: z.number().int().positive().nullable(),
83
+ });
84
+ export const fileSaveResult = z.union([
85
+ z.strictObject({
86
+ kind: z.literal("saved"),
87
+ revision: z.number().int().positive(),
88
+ state: z.literal("pending"),
89
+ }),
90
+ z.strictObject({
91
+ kind: z.literal("synced"),
92
+ revision: z.number().int().positive(),
93
+ commit: hash,
94
+ }),
95
+ z.strictObject({
96
+ kind: z.literal("conflict"),
97
+ revision: z.number().int().nonnegative(),
98
+ theirs: pendingFileEdit.shape.theirs.optional(),
99
+ }),
100
+ z.strictObject({
101
+ kind: z.literal("failed"),
102
+ revision: z.number().int().positive(),
103
+ reason: z.enum([
104
+ "branch_missing",
105
+ "access_changed",
106
+ "sync_failed",
107
+ "permanent_material",
108
+ ]),
109
+ }),
110
+ z.strictObject({
111
+ kind: z.literal("refused"),
112
+ reason: z.enum(["not-source-writer", "background-unavailable"]),
113
+ }),
114
+ ]);
115
+ export const fileDiscardInput = z.strictObject({
116
+ ...editKey,
117
+ revision: z.number().int().positive(),
118
+ });
119
+ export const fileDiscardResult = z.union([
120
+ z.strictObject({ kind: z.enum(["discarded", "not_found"]) }),
121
+ z.strictObject({
122
+ kind: z.literal("conflict"),
123
+ revision: z.number().int().positive(),
124
+ }),
125
+ ]);
126
+ export const fileSyncResult = z.strictObject({
127
+ settled: z.array(z.strictObject({ ...editKey, result: fileSaveResult })),
128
+ more: z.boolean(),
129
+ });
130
+ export const fileContent = z.strictObject({
131
+ /** This member's saved row revision; null for committed-only readers or no row. */
132
+ version: z.number().int().positive().nullable(),
133
+ commit: hash,
134
+ /** Null only for a path proven absent at this committed branch head. */
135
+ blob: hash.nullable(),
136
+ pending: pendingFileEdit.optional(),
137
+ ref: z.string(),
138
+ path: z.string(),
139
+ size: z.number(),
140
+ binary: z.boolean(),
141
+ /** Absent when binary or larger than the viewer limit. */
142
+ text: z.string().nullable(),
143
+ });
144
+ export const commitPage = z.strictObject({
145
+ ref: z.string(),
146
+ commits: z.array(z.strictObject({ commit, agent: z.string().nullable() })),
147
+ next: z.string().optional(),
148
+ });
149
+ /** Every path at a commit: files, and directories with a trailing slash. */
150
+ export const fileList = z.strictObject({
151
+ ref: z.string(),
152
+ commit,
153
+ paths: z.array(z.string()),
154
+ truncated: z.boolean(),
155
+ });
156
+ /** A foreground copy rebuild needs another admitted method frame. */
157
+ export const readCopyRebuilding = z.strictObject({
158
+ kind: z.literal("rebuilding"),
159
+ });
160
+ export const copyRebuildPage = z.strictObject({
161
+ done: z.boolean(),
162
+ cursor: z.string().nullable(),
163
+ });
164
+ /** Where the files role opens: a repository file at a branch, or a Computer file. */
165
+ export const filesLocation = z.union([
166
+ z.strictObject({
167
+ repository: repoName,
168
+ branch: repositoryBranch,
169
+ path: repositoryFilePath,
170
+ }),
171
+ z.strictObject({ path: z.string().min(1).max(1024) }),
172
+ ]);
173
+ /** The `apps.open` navigate intent that opens a location in the files role App. */
174
+ export function filesNavigateIntent(location) {
175
+ return {
176
+ kind: "navigate",
177
+ params: Object.entries(filesLocation.parse(location)).map(([key, value]) => ({ key, value })),
178
+ };
179
+ }
180
+ /** Decode a received navigate intent's params; null when they name no files location. */
181
+ export function readFilesLocation(params) {
182
+ const parsed = filesLocation.safeParse(Object.fromEntries(params.map(({ key, value }) => [key, value])));
183
+ return parsed.success ? parsed.data : null;
184
+ }
package/dist/root.d.ts ADDED
@@ -0,0 +1,21 @@
1
+ import type { CapabilityDirectory } from "./capabilities.js";
2
+ import type { AppCommands } from "./commands.js";
3
+ import type { AppContext, AppIdentity, AppLifecycle } from "./lifecycle.js";
4
+ import type { ReadonlyStore } from "./store.js";
5
+ import type { HostUi } from "./ui.js";
6
+ import type { AppWindow } from "./window.js";
7
+ /** The App's live connection to its host: its admitted capabilities,
8
+ * commands, context, theme, UI door and window, all torn down together
9
+ * by `dispose`. Returned by `connectApp` and passed to `mountApp`. */
10
+ export type AppRoot = {
11
+ readonly capabilities: CapabilityDirectory;
12
+ readonly commands: AppCommands;
13
+ readonly context: ReadonlyStore<AppContext>;
14
+ /** End this App's connection to its host and release everything it owns. */
15
+ dispose(): void;
16
+ readonly identity: Readonly<AppIdentity>;
17
+ readonly lifecycle: ReadonlyStore<AppLifecycle>;
18
+ readonly theme: ReadonlyStore<string>;
19
+ readonly ui: HostUi;
20
+ readonly window: AppWindow;
21
+ };
package/dist/root.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/dist/rpc.d.ts ADDED
@@ -0,0 +1 @@
1
+ export { rpcDataSchema, rpcHandleSchema, rpcMethod, rpcVoid, } from "./internal/rpc-contract.js";
package/dist/rpc.js ADDED
@@ -0,0 +1 @@
1
+ export { rpcDataSchema, rpcHandleSchema, rpcMethod, rpcVoid, } from "./internal/rpc-contract.js";
@@ -0,0 +1,17 @@
1
+ import type { AppStatusAction, AppStatusItem } from "./ui.js";
2
+ /**
3
+ * Control, separator, zero-width and bidi characters: anything that could
4
+ * break one line of host chrome or reorder what it says.
5
+ */
6
+ export declare function isUnsafeStatusCodeUnit(code: number): boolean;
7
+ /**
8
+ * Make person- or Computer-supplied text fit one status item: drop unsafe
9
+ * characters, collapse whitespace and shorten with an ellipsis.
10
+ */
11
+ export declare function statusText(value: string, max?: number): string;
12
+ /**
13
+ * Whether an action names something the App declares now: an enabled item,
14
+ * and for a menu exactly one enabled option. Every hop that delivers an
15
+ * action applies this rule against its own latest copy of the items.
16
+ */
17
+ export declare function statusActionAllowed(items: readonly AppStatusItem[], action: AppStatusAction): boolean;
package/dist/status.js ADDED
@@ -0,0 +1,50 @@
1
+ import { APP_STATUS_TEXT_MAX } from "./ui.js";
2
+ /**
3
+ * Control, separator, zero-width and bidi characters: anything that could
4
+ * break one line of host chrome or reorder what it says.
5
+ */
6
+ export function isUnsafeStatusCodeUnit(code) {
7
+ return (code < 0x20 ||
8
+ (code >= 0x7f && code <= 0x9f) ||
9
+ code === 0x061c ||
10
+ (code >= 0x200b && code <= 0x200f) ||
11
+ code === 0x2028 ||
12
+ code === 0x2029 ||
13
+ (code >= 0x202a && code <= 0x202e) ||
14
+ (code >= 0x2066 && code <= 0x2069) ||
15
+ code === 0xfeff);
16
+ }
17
+ /**
18
+ * Make person- or Computer-supplied text fit one status item: drop unsafe
19
+ * characters, collapse whitespace and shorten with an ellipsis.
20
+ */
21
+ export function statusText(value, max = APP_STATUS_TEXT_MAX) {
22
+ let clean = "";
23
+ for (let index = 0; index < value.length; index += 1) {
24
+ const code = value.charCodeAt(index);
25
+ clean += isUnsafeStatusCodeUnit(code) ? " " : value.charAt(index);
26
+ }
27
+ clean = clean.replace(/\s+/gu, " ").trim();
28
+ if (clean.length <= max)
29
+ return clean;
30
+ return `${clean.slice(0, Math.max(0, max - 1)).trimEnd()}…`;
31
+ }
32
+ /**
33
+ * Whether an action names something the App declares now: an enabled item,
34
+ * and for a menu exactly one enabled option. Every hop that delivers an
35
+ * action applies this rule against its own latest copy of the items.
36
+ */
37
+ export function statusActionAllowed(items, action) {
38
+ const item = items.find((candidate) => candidate.id === action.itemId);
39
+ if (item === undefined)
40
+ return false;
41
+ if (item.kind === "text")
42
+ return false;
43
+ if (item.kind === "menu") {
44
+ const option = item.options.find((candidate) => candidate.id === action.optionId);
45
+ return option !== undefined && option.disabled !== true;
46
+ }
47
+ if (action.optionId !== undefined)
48
+ return false;
49
+ return item.kind !== "button" || item.disabled !== true;
50
+ }