@joe-broadhead/opencode-mem 0.9.14 → 0.11.3

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 (143) hide show
  1. package/CHANGELOG.md +1856 -0
  2. package/README.md +15 -7
  3. package/SECURITY.md +3 -1
  4. package/docs/agent-instructions.md +1 -1
  5. package/docs/agent-protocol.md +7 -7
  6. package/docs/permissions.md +16 -0
  7. package/package.json +8921 -1070
  8. package/shared/page-paths.js +44 -0
  9. package/skills/mem.pages/SKILL.md +3 -1
  10. package/skills/mem.usage/SKILL.md +15 -15
  11. package/src/action-grant-keys.js +159 -0
  12. package/src/action-grant.js +439 -0
  13. package/src/actions.js +1690 -0
  14. package/src/backend/records.js +25 -2
  15. package/src/backend/v3.js +76 -22
  16. package/src/call-shapes.js +17 -16
  17. package/src/collector-lock.js +533 -62
  18. package/src/collector-service.js +153 -26
  19. package/src/collector.js +623 -30
  20. package/src/config.js +88 -7
  21. package/src/connect.js +106 -8
  22. package/src/credentials.js +123 -25
  23. package/src/events.js +174 -3
  24. package/src/forget-turn.js +141 -0
  25. package/src/host-refusal.js +78 -0
  26. package/src/index.js +209 -22
  27. package/src/jobs/host.js +557 -0
  28. package/src/ops/codes.js +110 -0
  29. package/src/ops/copy-lineage.js +42 -0
  30. package/src/ops/index.js +28 -0
  31. package/src/ops/space-ops.js +1936 -0
  32. package/src/outlinks.js +103 -0
  33. package/src/p2-reservation.js +151 -0
  34. package/src/permissions.js +30 -0
  35. package/src/plugins/descriptor.js +62 -0
  36. package/src/plugins/discovery.js +318 -0
  37. package/src/plugins/grants.js +178 -0
  38. package/src/plugins/locate.js +319 -0
  39. package/src/plugins/manifest.js +1162 -0
  40. package/src/plugins/source-contract/index.js +34 -0
  41. package/src/plugins/source-contract/policy.js +102 -0
  42. package/src/plugins/source-contract/vendor/PROVENANCE.json +17 -0
  43. package/src/plugins/source-contract/vendor/RELEASE-SHA256SUMS +3 -0
  44. package/src/plugins/source-contract/vendor/RELEASE.json +17 -0
  45. package/src/plugins/source-contract/vendor/SHA256SUMS +41 -0
  46. package/src/plugins/source-contract/vendor/THIRD-PARTY-NOTICES.md +35 -0
  47. package/src/plugins/source-contract/vendor/broker-client.js +93 -0
  48. package/src/plugins/source-contract/vendor/chunks/chunk-3M5PAKSS.js +84 -0
  49. package/src/plugins/source-contract/vendor/chunks/chunk-4ERCA4TK.js +185 -0
  50. package/src/plugins/source-contract/vendor/chunks/chunk-6HDIB2SA.js +183 -0
  51. package/src/plugins/source-contract/vendor/chunks/chunk-ELPJD3ND.js +10 -0
  52. package/src/plugins/source-contract/vendor/chunks/chunk-HLVAKAYG.js +10 -0
  53. package/src/plugins/source-contract/vendor/chunks/chunk-I2RXJJJM.js +81 -0
  54. package/src/plugins/source-contract/vendor/chunks/chunk-KWEWSZ4V.js +505 -0
  55. package/src/plugins/source-contract/vendor/chunks/chunk-KYWBTAF4.js +182 -0
  56. package/src/plugins/source-contract/vendor/chunks/chunk-Q3RQA5J2.js +249 -0
  57. package/src/plugins/source-contract/vendor/chunks/chunk-RRUAIQ4I.js +156 -0
  58. package/src/plugins/source-contract/vendor/chunks/chunk-RYNKNCPP.js +165 -0
  59. package/src/plugins/source-contract/vendor/chunks/chunk-W5SHR7DQ.js +9477 -0
  60. package/src/plugins/source-contract/vendor/chunks/chunk-ZUKF7P6U.js +653 -0
  61. package/src/plugins/source-contract/vendor/cursor.js +26 -0
  62. package/src/plugins/source-contract/vendor/descriptor.js +34 -0
  63. package/src/plugins/source-contract/vendor/events.js +257 -0
  64. package/src/plugins/source-contract/vendor/index.js +10 -0
  65. package/src/plugins/source-contract/vendor/params.js +22 -0
  66. package/src/plugins/source-contract/vendor/permission.js +28 -0
  67. package/src/plugins/source-contract/vendor/pick.js +22 -0
  68. package/src/plugins/source-contract/vendor/read.js +29 -0
  69. package/src/plugins/source-contract/vendor/registry.js +23 -0
  70. package/src/plugins/source-contract/vendor/schema.js +17 -0
  71. package/src/plugins/source-contract/vendor/schemas/output.agenda.json +96 -0
  72. package/src/plugins/source-contract/vendor/schemas/output.countdown.json +28 -0
  73. package/src/plugins/source-contract/vendor/schemas/output.image.json +28 -0
  74. package/src/plugins/source-contract/vendor/schemas/output.inbox.json +84 -0
  75. package/src/plugins/source-contract/vendor/schemas/output.links.json +46 -0
  76. package/src/plugins/source-contract/vendor/schemas/output.list.json +57 -0
  77. package/src/plugins/source-contract/vendor/schemas/output.metric.json +61 -0
  78. package/src/plugins/source-contract/vendor/schemas/output.note.json +14 -0
  79. package/src/plugins/source-contract/vendor/schemas/output.progress.json +50 -0
  80. package/src/plugins/source-contract/vendor/schemas/output.record.json +38 -0
  81. package/src/plugins/source-contract/vendor/schemas/output.table.json +61 -0
  82. package/src/plugins/source-contract/vendor/schemas/output.thread.json +62 -0
  83. package/src/plugins/source-contract/vendor/schemas/sources.json +819 -0
  84. package/src/plugins/source-contract/vendor/schemas.js +19 -0
  85. package/src/plugins/source-contract/vendor/tools-rpc.js +42 -0
  86. package/src/plugins/verify.js +56 -0
  87. package/src/protocol.js +11 -6
  88. package/src/recall.js +92 -5
  89. package/src/records.js +61 -2
  90. package/src/requests.js +216 -0
  91. package/src/runtime.js +89 -7
  92. package/src/setup-time.js +68 -0
  93. package/src/skills.js +230 -8
  94. package/src/source-ids.js +25 -0
  95. package/src/sources/declaration.js +365 -0
  96. package/src/sources/reads.js +772 -0
  97. package/src/sources/rpc.js +151 -0
  98. package/src/sources.js +389 -92
  99. package/src/spaces.js +283 -11
  100. package/src/spool.js +61 -4
  101. package/src/stated.js +10 -5
  102. package/src/storable.js +139 -0
  103. package/src/tools/commitments.js +74 -23
  104. package/src/tools/held-write.js +46 -19
  105. package/src/tools/index.js +28 -0
  106. package/src/tools/ingest.js +38 -2
  107. package/src/tools/memory.js +56 -25
  108. package/src/tools/page.js +212 -95
  109. package/src/tools/recall.js +218 -4
  110. package/src/tools/share.js +42 -3
  111. package/src/tools/shared.js +84 -6
  112. package/src/tools/space-lifecycle.js +278 -0
  113. package/src/tools/spaces.js +381 -30
  114. package/src/tools/status.js +9 -2
  115. package/src/tools/wiki.js +231 -116
  116. package/src/util.js +110 -6
  117. package/src/vendor/source-contract/README.md +24 -0
  118. package/src/vendor/source-contract/THIRD-PARTY-NOTICES.md +35 -0
  119. package/src/vendor/source-contract/VENDOR.json +81 -0
  120. package/src/vendor/source-contract/chunks/chunk-3M5PAKSS.js +84 -0
  121. package/src/vendor/source-contract/chunks/chunk-6HDIB2SA.js +183 -0
  122. package/src/vendor/source-contract/chunks/chunk-HLVAKAYG.js +10 -0
  123. package/src/vendor/source-contract/chunks/chunk-I2RXJJJM.js +81 -0
  124. package/src/vendor/source-contract/chunks/chunk-KWEWSZ4V.js +505 -0
  125. package/src/vendor/source-contract/chunks/chunk-W5SHR7DQ.js +9477 -0
  126. package/src/vendor/source-contract/chunks/chunk-ZUKF7P6U.js +653 -0
  127. package/src/vendor/source-contract/cursor.js +26 -0
  128. package/src/vendor/source-contract/events.js +257 -0
  129. package/src/vendor/source-contract/registry.js +23 -0
  130. package/src/vendor/source-contract/tools-rpc.js +42 -0
  131. package/src/views/access-reads.js +256 -0
  132. package/src/views/communities.js +77 -0
  133. package/src/views/contracts.js +1082 -23
  134. package/src/views/inbox-bytes.js +103 -0
  135. package/src/views/profile.js +31 -0
  136. package/src/views/receipt.js +26 -1
  137. package/src/views/records-reads.js +520 -41
  138. package/src/views/rpc.js +153 -25
  139. package/src/views/shape.js +8 -5
  140. package/src/views/write-state.js +89 -0
  141. package/src/wiki-ingest.js +215 -0
  142. package/src/wiki-state.js +228 -0
  143. package/views/pages.html +2 -2
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Memory's consumer side of the shared source contract, version 1
3
+ * (`we-the-rebel-alliance/app#2346`; Memory's part in comment 6 and
4
+ * DESIGN-MEMORY-JOBS §8.3).
5
+ *
6
+ * The contract's package is `we-the-rebel-alliance/source-contract`. **It is
7
+ * vendored, not depended on** (`vendor/`, the locked v0.1.0 release at
8
+ * `381e6c91`, with `PROVENANCE.json` and `SHA256SUMS`), so an install of Memory
9
+ * runs no build and there is no runtime dependency. Everything the contract
10
+ * defines comes from it:
11
+ *
12
+ * - `descriptor`: read, validate and hash a plugin's `sources` from the
13
+ * installed package on disk;
14
+ * - `permission`: exact session rules from a grant;
15
+ * - `read`: `events_list`, `snapshot_read`, `probe` and detail reads, in a
16
+ * fenced session, with the embedded path when there is no broker;
17
+ * - `cursor`: the scope-bound cursor codec (`CURSOR_INVALID`, `CURSOR_EXPIRED`);
18
+ * - `events`: the page's shape, the error table and the secret refusal;
19
+ * - `params`, `pick`, `registry`: relative windows, `$me`, field selection and
20
+ * the output schemas.
21
+ *
22
+ * `policy.js` is Memory's own and stays Memory's: when to move the cursor, one
23
+ * resync a day, and what a code means for a binding.
24
+ */
25
+ export { CONTRACT_VERSION, SUPPORTED_CONTRACT_VERSIONS } from "./vendor/index.js"
26
+ export { DEFAULT_MAX_BYTES, DETAIL_FIELDS, MAX_BYTES_LIMIT, canonicalJson, checkSources, descriptorHash, findInstalledPackage, findSource, maxBytesOf, readInstalledDescriptor } from "./vendor/descriptor.js"
27
+ export { DENY_ALL, ACCOUNT_PATTERN, accountProblem, methodAction, namespaceOf, operationRule, sessionRules } from "./vendor/permission.js"
28
+ export { acceptAnswer, checkReadRequest, detailFields, probe, read, readDetail } from "./vendor/read.js"
29
+ export { bindingHash, canonicalScope, decodeBoundCursor, decodeCursor, encodeBoundCursor, encodeCursor } from "./vendor/cursor.js"
30
+ export { ERROR_CODES, EVENT_KINDS, SourceError, canonicalCode, eventProblems, parseSourceError, resultProblems, screenEvents, secretKinds } from "./vendor/events.js"
31
+ export { ME, WINDOWS, resolveParams, resolveRelativeTime, resolveSince, resolveWindow } from "./vendor/params.js"
32
+ export { missingPaths, pick, pickProblems, pickProblemsForOutput } from "./vendor/pick.js"
33
+ export { canonicalJson as canonicalJSON } from "./vendor/descriptor.js"
34
+ export { cursorAdvance, failureAction, failureFromError, isErrorState, utcDay } from "./policy.js"
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Memory's own policy on top of the contract's page result (DESIGN-MEMORY-JOBS
3
+ * §8.3.4; the contract's own module is `vendor/events.js`).
4
+ *
5
+ * The contract says what a page holds. Memory decides what to do with it, and
6
+ * keeps doing so itself:
7
+ *
8
+ * - **the cursor** is saved in the same transaction as the page it accepts;
9
+ * `failed[]` holds it back, `refused[]` does not;
10
+ * - **one resync per binding per day**, so a plugin that loses history twice
11
+ * cannot make Memory backfill twice;
12
+ * - a source's error becomes a **pause**, a **hold** or a **reset**, by code:
13
+ * `SOURCE_DISABLED` is the person's own switch (not an error), `SCOPE_MISSING`
14
+ * is the provider sign-in losing a scope, and `BUDGET_EXCEEDED` is spent money,
15
+ * never mistaken for `RATE_LIMITED`.
16
+ */
17
+ import { canonicalCode, parseSourceError } from "./vendor/events.js"
18
+
19
+ /**
20
+ * Whether this page may move Memory's cursor:
21
+ * `failed[]` holds it; `refused[]` is an answer; a `gap` advances with the hole.
22
+ *
23
+ * @param {{ failed?: object[], refused?: object[], gap?: object | null }} page
24
+ * @returns {{ advance: boolean, reason: "accepted" | "failed", hidden: string | null }}
25
+ */
26
+ export function cursorAdvance(page) {
27
+ const failed = Array.isArray(page?.failed) ? page.failed : []
28
+ if (failed.length > 0) {
29
+ const first = failed[0]
30
+ return { advance: false, reason: "failed", hidden: String(first?.code ?? first?.reason ?? "a retryable drop").slice(0, 100) }
31
+ }
32
+ return { advance: true, reason: "accepted", hidden: null }
33
+ }
34
+
35
+ /** The UTC day a resync is counted against. */
36
+ export function utcDay(now = Date.now()) {
37
+ return new Date(now).toISOString().slice(0, 10)
38
+ }
39
+
40
+ /**
41
+ * What a failed read means for the binding.
42
+ *
43
+ * @param {string} code
44
+ * @returns {{ action: "pause" | "hold" | "reset", reset: "none" | "since" | "gap", resync: boolean, reason: string }}
45
+ */
46
+ export function failureAction(code) {
47
+ switch (canonicalCode(code) ?? code) {
48
+ case "SCOPE_MISSING":
49
+ return { action: "pause", reset: "none", resync: false, reason: "the provider sign-in lost a scope; sign in again" }
50
+ case "NEEDS_SIGN_IN":
51
+ return { action: "pause", reset: "none", resync: false, reason: "the source needs a sign-in" }
52
+ case "SOURCE_DISABLED":
53
+ return { action: "pause", reset: "none", resync: false, reason: "the person turned this source off" }
54
+ case "BUDGET_EXCEEDED":
55
+ return { action: "hold", reset: "none", resync: false, reason: "the person's budget is spent; retry on the cadence, never at once" }
56
+ case "RATE_LIMITED":
57
+ return { action: "hold", reset: "none", resync: false, reason: "the provider rate-limited the read; retry after the delay it gave" }
58
+ case "ACCOUNT_MISMATCH":
59
+ // jelly's own word for an account that is not the agent's (source-contract#29: an alias, once it merges).
60
+ case "ACCOUNT_UNKNOWN":
61
+ return { action: "pause", reset: "none", resync: false, reason: "the account changed; the person confirms it again" }
62
+ case "PERMISSION_DENIED":
63
+ return { action: "pause", reset: "none", resync: false, reason: "a grant the source needs was not confirmed" }
64
+ case "CURSOR_INVALID":
65
+ return { action: "reset", reset: "since", resync: false, reason: "the cursor belongs to another binding; start from the window" }
66
+ case "CURSOR_EXPIRED":
67
+ return { action: "reset", reset: "gap", resync: true, reason: "history was lost; one resync, and the hole is marked" }
68
+ // v0.1.0's two codes (D3 (a)): neither is a retryable unknown. A source that is no longer declared is
69
+ // gone until the plugin changes, and a request Memory sent wrong will be sent wrong again next tick.
70
+ case "SOURCE_UNKNOWN":
71
+ return { action: "pause", reset: "none", resync: false, reason: "the source is no longer declared by its plugin; the binding waits for the plugin to declare it again" }
72
+ case "INPUT_INVALID":
73
+ return { action: "pause", reset: "none", resync: false, reason: "Memory sent a request the source refused; the binding waits for the plugin or Memory to be updated" }
74
+ default:
75
+ return { action: "hold", reset: "none", resync: false, reason: "the read failed; retry on the next cadence" }
76
+ }
77
+ }
78
+
79
+ /** True when a code is a state the person chose, not an error (`SOURCE_DISABLED`). */
80
+ export function isErrorState(code) {
81
+ return canonicalCode(code) !== "SOURCE_DISABLED"
82
+ }
83
+
84
+ /**
85
+ * A read that threw, read as the contract's failure: its code when the table
86
+ * knows it (`AUTH_REQUIRED` is `NEEDS_SIGN_IN`), what happened, and the next
87
+ * step the message already carries.
88
+ *
89
+ * @param {unknown} error
90
+ * @returns {{ code: string, message: string, next: string | null }}
91
+ */
92
+ /** jelly's own word for an account that is not the agent's: the package aliases it once #29 merges, and an
93
+ * older table does not know it, so Memory reads it as the mismatch it means. */
94
+ export const CODE_ALIASES = Object.freeze({ ACCOUNT_UNKNOWN: "ACCOUNT_MISMATCH" })
95
+
96
+ export function failureFromError(error) {
97
+ const read = parseSourceError(error)
98
+ const canonical = canonicalCode(read?.code ?? "") ?? (read?.code || undefined)
99
+ const code = canonical === undefined ? "UNAVAILABLE" : CODE_ALIASES[canonical] ?? canonical
100
+ const message = typeof error?.message === "string" && error.message ? error.message : `${code}: the read failed.`
101
+ return { code, message, next: read?.next ?? null }
102
+ }
@@ -0,0 +1,17 @@
1
+ {
2
+ "package": "@we-the-rebel-alliance/source-contract",
3
+ "repo": "https://github.com/we-the-rebel-alliance/source-contract",
4
+ "version": "0.1.0",
5
+ "commit": "8ace21db949557740c6dd8fd837c6efc50c367b7",
6
+ "tag": "v0.1.0",
7
+ "tagObject": "1bf9466b3d3745900bad4abb1c83f922956887de",
8
+ "release": "https://github.com/we-the-rebel-alliance/source-contract/releases/tag/v0.1.0",
9
+ "commitNote": "The release's tag: annotated tag v0.1.0 (1bf9466b) on 8ace21db, which is 381e6c91 plus the probe rule of #8 item 1 (#26). Copied from the release tarball's dist/ after verifying the tarball, the conformance kit and the schemas against the release's SHA256SUMS.",
10
+ "path": "dist/",
11
+ "files": 41,
12
+ "sha256sums": "SHA256SUMS",
13
+ "releaseSha256sums": "RELEASE-SHA256SUMS",
14
+ "manifestSha256": "cd613a1994b45cc1faf459f3c9a4862d3adb6afcfd8c7e149266eb79a60ffbf6",
15
+ "vendored": "2026-11-14",
16
+ "note": "Memory bundles it, so an install runs no build and there is no runtime dependency. dist/*.d.ts are not vendored: Memory reads JavaScript. test/source-contract.test.js checks every file against SHA256SUMS and this manifest hash; test/contract-release.test.js checks them against the release tarball pinned in test/fixtures/contract/."
17
+ }
@@ -0,0 +1,3 @@
1
+ 7ce8140e9c413f1d8bc1956bcac68b733908dd6c02a1f11e6f69e76c8fc3e91d source-contract-0.1.0.tgz
2
+ 5761082a10c8f96be0a6e159dcf80cfd7785889befcc4d887d7c2a632e02a113 source-contract-conformance-0.1.0.mjs
3
+ e59dc291e40c382880bc4e33c0171a755cd11041b5232b5e1177b8335734a395 source-contract-schemas-0.1.0.json
@@ -0,0 +1,17 @@
1
+ {
2
+ "tag": "v0.1.0",
3
+ "tagObject": "1bf9466b3d3745900bad4abb1c83f922956887de",
4
+ "commit": "8ace21db949557740c6dd8fd837c6efc50c367b7",
5
+ "url": "https://github.com/we-the-rebel-alliance/source-contract/releases/tag/v0.1.0",
6
+ "published": "2026-11-14T21:53:00Z",
7
+ "sha256sums": {
8
+ "file": "RELEASE-SHA256SUMS",
9
+ "sha256": "5a3fe019effbc64be422ddeb0f18c870658fd7a9c20dec059c83d803abbf8124"
10
+ },
11
+ "assets": {
12
+ "source-contract-0.1.0.tgz": "7ce8140e9c413f1d8bc1956bcac68b733908dd6c02a1f11e6f69e76c8fc3e91d",
13
+ "source-contract-conformance-0.1.0.mjs": "5761082a10c8f96be0a6e159dcf80cfd7785889befcc4d887d7c2a632e02a113",
14
+ "source-contract-schemas-0.1.0.json": "e59dc291e40c382880bc4e33c0171a755cd11041b5232b5e1177b8335734a395"
15
+ },
16
+ "pinnedAt": "test/fixtures/contract/"
17
+ }
@@ -0,0 +1,41 @@
1
+ 1a00d3f937d6c65cd6987bbd0f0da1591d6f423bd7751aedfdc8cdd152bfa04e THIRD-PARTY-NOTICES.md
2
+ 0b79307d2d1f33db24d3dd53184a3166627b51dffbdbb81f7cb4cf7a5ecafadd broker-client.js
3
+ d5a610aab777cff819b2d4fb4ebc9b4903f14345a1ebe5f52842f41119290f13 chunks/chunk-3M5PAKSS.js
4
+ b91fefade14e3988d5817431a0a72476f5f03c8ce40e5c0448034e0572f8975b chunks/chunk-4ERCA4TK.js
5
+ a4f9d76b5e98c2994cdd9e2dc9d6ad4f796977fa7a7720519f498cb8996ed047 chunks/chunk-6HDIB2SA.js
6
+ d8e1a5c27078e5ce1cfe2ef7e3f6381fffe242e625fa6370251b6fbfc03105ff chunks/chunk-ELPJD3ND.js
7
+ d0c7a4785744974cc4cf01af0f21495fc13b5ecea729aa8d162f800f16a56d6f chunks/chunk-HLVAKAYG.js
8
+ 6f9f2b56ea30e3aa7629f823cc19b9438b5178f7448e2c292d2b07d28b0bc8e8 chunks/chunk-I2RXJJJM.js
9
+ 9789db2ecce07e4ef24e46afe7f0b6669b45e7fe544c9aa302048dcfb20f6c34 chunks/chunk-KWEWSZ4V.js
10
+ b2efb36e7e70f930f23d2375f79a825a14ba682b86986ad038588747797743c7 chunks/chunk-KYWBTAF4.js
11
+ a4887f98e83f3ecea7ddfd1da9a5518f4c44ac0032f91aa1bdaf057a5bdfa630 chunks/chunk-Q3RQA5J2.js
12
+ 1e431825a38c3b8ec14d94b312f9b255b019c151277fc5ae304deafbf43a0729 chunks/chunk-RRUAIQ4I.js
13
+ c384c7af7ae1fc1d58999221adc1a4830001fb467b86cdb7678016eea174daaa chunks/chunk-RYNKNCPP.js
14
+ 2b17357118874b1052601e8062dc2aa24c182d5a55c2642400cba7572577d151 chunks/chunk-W5SHR7DQ.js
15
+ 6971bb13eb9a9ea9a3708d7e99b76292d4f82170c58cdafbd2443e1d47a34153 chunks/chunk-ZUKF7P6U.js
16
+ d939fa44dbe5536e0e6bfaf1560b9b1abd2380cb0849fa9361a1b224da986ca3 conformance.js
17
+ 28482ff668ec5680fe7c3e38ae7ee87c36da99ee447dbb851d055cdc49b0bea1 cursor.js
18
+ 684cf95c0ddfb7d1b4e13c10fe5307a96971771e8e2ca71ab9a992d5deb6ebd2 descriptor.js
19
+ ce67038a5d442dd57d554a59eda98adcf726e3d7f5210c544c4e4f78200dd852 events.js
20
+ 52208818a550d9317dc263906f9a001bf0b4b56fb3d19319c43fe8fe68a7cc28 index.js
21
+ e5168b149699c793eccf1ad4c0f8a07df777aec675f093754ec3194d62c44ca7 params.js
22
+ 2ca7ea60b48cab16d5e14fc3f447469ad736f506a9c9a29f22ccef83e292da12 permission.js
23
+ 572ab1bd6534215d59f99b774ff1d2dfff399dc94439e45b7ed048ab9ea6bdf1 pick.js
24
+ 5890bea19273e20a2c4726f855c66c2470e68c0deb732309b7122b81f02d6081 read.js
25
+ 52ac92e7c0bb4c651e42d9a7ae6e7ae029a2c8677dfa240426271bbe4721164f registry.js
26
+ 826b66a5c8e44c029795b2db9aaf8bc63092be99b75a6a866705312ed238b11b schema.js
27
+ 98fb19d5d3974668d31e949bdbb238b682326b22b8bca6a2b4c5c1105ca3c53f schemas.js
28
+ afdcaa972b3294394883025d8c531ff51d4117cb8f5d2240b5f55319cf646b10 schemas/output.agenda.json
29
+ 2bb069201056c91056b3590417918970e3b79950df39f45f1537cc59eb3b9933 schemas/output.countdown.json
30
+ b162cf16515ffb3eb324c4cc62d9898e6c894ba882d91af60025b60cf33129f9 schemas/output.image.json
31
+ 035a570bbccb36950d0e1af40bed15d48fe76a7f77a219f78b7c3498a5db7438 schemas/output.inbox.json
32
+ 37e583b99519ee9f96aa1f96fc2c1585f67afd4b797da5efce534e6761d94f75 schemas/output.links.json
33
+ 07b63a0a2eec2aa4282d10cb5bba50b4790fa7e75ecdb64465610320af78a487 schemas/output.list.json
34
+ 76c03b348ee77415032d709e065ecae4b5316dcbe860bc4cb28624251552f6d4 schemas/output.metric.json
35
+ aa806aeb1f800c179648c7d3ad2d2ee67fa3c39977087d6f03c733ad28d14dcd schemas/output.note.json
36
+ 3d9be5dbf10713ef516bc08154bf92380c1cddd4450b2061601195a108d958e8 schemas/output.progress.json
37
+ 30fbb81a6f8df5d0601e428f2503eb726eca603cc350805852dc7c909a9b59a1 schemas/output.record.json
38
+ 3d9695004dbf803576efcca0ff5bcef94af2d9475131db2fc694f974bc217dae schemas/output.table.json
39
+ ffaaaa5107a2a6b7b36230e2e458383591b687af77c1be2e1876194bdeb40f90 schemas/output.thread.json
40
+ 160d6c9fff25809ae4eaa4d3d2275b7048b57e5606bf277e6924d6064dd1ca95 schemas/sources.json
41
+ bdac6baf1f7fa35fa800aa59269aaee22e770a76247b81f324b2d263a75447a1 tools-rpc.js
@@ -0,0 +1,35 @@
1
+ # Bundled packages
2
+
3
+ dist/ bundles these packages and this data, so an install needs none of them.
4
+
5
+ ## zod 4.6.7 (MIT)
6
+
7
+ MIT License
8
+
9
+ Copyright (c) 2025 Colin McDonnell
10
+
11
+ Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ of this software and associated documentation files (the "Software"), to deal
13
+ in the Software without restriction, including without limitation the rights
14
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
+ copies of the Software, and to permit persons to whom the Software is
16
+ furnished to do so, subject to the following conditions:
17
+
18
+ The above copyright notice and this permission notice shall be included in all
19
+ copies or substantial portions of the Software.
20
+
21
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
+ SOFTWARE.
28
+
29
+ ## Public Suffix List (MPL-2.0)
30
+
31
+ The conformance kit bundles the Public Suffix List, ICANN and PRIVATE sections, from
32
+ https://publicsuffix.org/list/public_suffix_list.dat.
33
+
34
+ This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not
35
+ distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
@@ -0,0 +1,93 @@
1
+ // @we-the-rebel-alliance/source-contract 0.1.0. Built by scripts/build.mjs; do not edit.
2
+ import {
3
+ acceptAnswer,
4
+ checkReadRequest,
5
+ failureFromError,
6
+ read
7
+ } from "./chunks/chunk-Q3RQA5J2.js";
8
+ import "./chunks/chunk-KYWBTAF4.js";
9
+ import "./chunks/chunk-RRUAIQ4I.js";
10
+ import "./chunks/chunk-KWEWSZ4V.js";
11
+ import "./chunks/chunk-ELPJD3ND.js";
12
+ import "./chunks/chunk-ZUKF7P6U.js";
13
+ import {
14
+ canonicalScope
15
+ } from "./chunks/chunk-I2RXJJJM.js";
16
+ import "./chunks/chunk-RYNKNCPP.js";
17
+ import "./chunks/chunk-3M5PAKSS.js";
18
+ import "./chunks/chunk-4ERCA4TK.js";
19
+ import "./chunks/chunk-6HDIB2SA.js";
20
+ import "./chunks/chunk-W5SHR7DQ.js";
21
+ import "./chunks/chunk-HLVAKAYG.js";
22
+
23
+ // src/broker-client.ts
24
+ var BROKER_CODE_ALIASES = {
25
+ NOT_GRANTED: "PERMISSION_DENIED",
26
+ UNKNOWN_SOURCE: "UNAVAILABLE",
27
+ INVALID_INPUT: "SCHEMA_VIOLATION",
28
+ PROVIDER_ERROR: "UNAVAILABLE"
29
+ };
30
+ function brokerRequest(request) {
31
+ const asked = request.scope ?? request.grant.scope;
32
+ const scope = asked === void 0 ? void 0 : canonicalScope(asked);
33
+ return {
34
+ package: request.installed.package,
35
+ version: request.installed.version,
36
+ descriptorHash: request.installed.hash,
37
+ consumer: request.consumer,
38
+ source: request.source,
39
+ account: request.grant.account,
40
+ ...scope === void 0 ? {} : { scope },
41
+ ...request.cursor === void 0 ? {} : { cursor: request.cursor },
42
+ ...request.since === void 0 ? {} : { since: request.since },
43
+ ...request.limit === void 0 ? {} : { limit: request.limit },
44
+ ...request.params === void 0 ? {} : { params: request.params },
45
+ ...request.pick === void 0 ? {} : { pick: request.pick }
46
+ };
47
+ }
48
+ var plain = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
49
+ function isBrokerAnswer(answer) {
50
+ if (!plain(answer)) return false;
51
+ if (answer["offered"] === false) return true;
52
+ if (answer["offered"] !== true) return false;
53
+ if (answer["ok"] === true) return "value" in answer;
54
+ return answer["ok"] === false && typeof answer["code"] === "string" && typeof answer["message"] === "string";
55
+ }
56
+ function sourceReader(options) {
57
+ const { host, broker } = options;
58
+ const embedded = async (request) => ({ ...await read(host, request), via: "embedded" });
59
+ if (!broker) return { read: embedded };
60
+ return {
61
+ async read(request) {
62
+ const checked = checkReadRequest(request);
63
+ if ("ok" in checked) return { ...checked, via: "embedded" };
64
+ let answer;
65
+ try {
66
+ answer = await broker(brokerRequest(request), request.signal);
67
+ } catch {
68
+ return embedded(request);
69
+ }
70
+ if (!isBrokerAnswer(answer) || !answer.offered) return embedded(request);
71
+ if (!answer.ok) {
72
+ const code = BROKER_CODE_ALIASES[answer.code] ?? answer.code;
73
+ const failure = failureFromError({
74
+ code,
75
+ message: answer.message,
76
+ data: { ...answer.next === void 0 ? {} : { next: answer.next }, ...answer.retryAfterSec === void 0 ? {} : { retryAfterSec: answer.retryAfterSec } }
77
+ });
78
+ return { ok: false, failure, via: "broker" };
79
+ }
80
+ const accepted = acceptAnswer(checked.source, request.grant.account, answer.value, {
81
+ ...request.limit === void 0 ? {} : { limit: request.limit },
82
+ ...request.pick === void 0 ? {} : { pick: request.pick }
83
+ });
84
+ return { ...accepted, via: "broker", ...answer.cached === void 0 ? {} : { cached: answer.cached } };
85
+ }
86
+ };
87
+ }
88
+ export {
89
+ BROKER_CODE_ALIASES,
90
+ brokerRequest,
91
+ isBrokerAnswer,
92
+ sourceReader
93
+ };
@@ -0,0 +1,84 @@
1
+ // @we-the-rebel-alliance/source-contract 0.1.0. Built by scripts/build.mjs; do not edit.
2
+
3
+ // src/permission.ts
4
+ var DENY_ALL = { action: "*", resource: "*", effect: "deny" };
5
+ var ACCOUNT_PATTERN = /^[^\s*?:\u0000-\u001f\u007f]{1,320}$/;
6
+ var WILDCARD = /[*?]/;
7
+ function accountProblem(account) {
8
+ if (typeof account !== "string" || !ACCOUNT_PATTERN.test(account)) {
9
+ return "the account must be 1 to 320 characters with no wildcard (* or ?), no colon and no whitespace";
10
+ }
11
+ return void 0;
12
+ }
13
+ var allow = (action, resource) => ({ action, resource, effect: "allow" });
14
+ function namespaceOf(source) {
15
+ return source.id.split(".")[0] ?? source.id;
16
+ }
17
+ function operationRule(source, operation, account) {
18
+ const namespace = namespaceOf(source);
19
+ return operation.includes(".") ? allow(`${namespace}.read`, `${account}:${operation}`) : allow(`${namespace}_${operation}`, "*");
20
+ }
21
+ function fenced(rules) {
22
+ const loose = rules.find((rule) => WILDCARD.test(rule.action) || rule.resource !== "*" && WILDCARD.test(rule.resource));
23
+ if (loose) return { ok: false, problems: [`the rule for ${loose.action} on ${loose.resource} has a wildcard, which would widen the grant`] };
24
+ const seen = /* @__PURE__ */ new Set();
25
+ const unique = rules.filter((rule) => {
26
+ const key = `${rule.action}\0${rule.resource}`;
27
+ if (seen.has(key)) return false;
28
+ seen.add(key);
29
+ return true;
30
+ });
31
+ return { ok: true, value: [DENY_ALL, ...unique] };
32
+ }
33
+ function methodAction(source) {
34
+ return source.kind === "events" ? source.permission.events : source.permission.tool;
35
+ }
36
+ function sessionRules(source, grant) {
37
+ if (grant.source !== source.id) return { ok: false, problems: [`the grant is for ${grant.source}, not ${source.id}`] };
38
+ const problem = accountProblem(grant.account);
39
+ if (problem) return { ok: false, problems: [problem] };
40
+ const method = methodAction(source);
41
+ if (method === void 0) return { ok: false, problems: [`${source.id} names no action for its method`] };
42
+ const declared = source.permission.rules;
43
+ if (declared !== void 0) return fenced([allow(method, "*"), ...declared.map((rule) => allow(rule.action, rule.resource))]);
44
+ const operations = source.permission.operations ?? [];
45
+ if (operations.length === 0) return { ok: false, problems: [`${source.id} declares neither operations nor rules`] };
46
+ return fenced([allow(method, "*"), ...operations.map((operation) => operationRule(source, operation, grant.account))]);
47
+ }
48
+ function detailRules(source, detailId, grant) {
49
+ if (!source.details?.some((entry) => entry.id === detailId)) return { ok: false, problems: [`${source.id} declares no detail read ${detailId}`] };
50
+ return sessionRules(source, grant);
51
+ }
52
+ function probeRules(source, account, identityOperations, probeAction) {
53
+ const problem = accountProblem(account);
54
+ if (problem) return { ok: false, problems: [problem] };
55
+ const method = probeAction ?? methodAction(source);
56
+ if (method === void 0) return { ok: false, problems: [`${source.id} names no action for its method`] };
57
+ return fenced([allow(method, "*"), ...identityOperations.map((operation) => operationRule(source, operation, account))]);
58
+ }
59
+ function evaluate(rules, action, resource = "*") {
60
+ return rules.findLast((rule) => wildcard(rule.action, action) && wildcard(rule.resource, resource))?.effect ?? "ask";
61
+ }
62
+ var wildcard = (pattern, value) => new RegExp(`^${pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*").replace(/\?/g, ".")}$`).test(value);
63
+ function grantCovers(grant, request) {
64
+ if (grant.source !== request.source || grant.account !== request.account) return false;
65
+ for (const [key, values] of Object.entries(request.scope ?? {})) {
66
+ const granted = grant.scope?.[key];
67
+ if (!granted || values.some((value) => !granted.includes(value))) return false;
68
+ }
69
+ return true;
70
+ }
71
+
72
+ export {
73
+ DENY_ALL,
74
+ ACCOUNT_PATTERN,
75
+ accountProblem,
76
+ namespaceOf,
77
+ operationRule,
78
+ methodAction,
79
+ sessionRules,
80
+ detailRules,
81
+ probeRules,
82
+ evaluate,
83
+ grantCovers
84
+ };
@@ -0,0 +1,185 @@
1
+ // @we-the-rebel-alliance/source-contract 0.1.0. Built by scripts/build.mjs; do not edit.
2
+ import {
3
+ isExtensionOutput,
4
+ outputValidator
5
+ } from "./chunk-6HDIB2SA.js";
6
+
7
+ // src/pick.ts
8
+ var MAX_PICK_PATHS = 50;
9
+ var MAX_PICK_PATH_LENGTH = 200;
10
+ var SEGMENT = "[A-Za-z0-9_$-]+(?:\\[\\])?";
11
+ var PICK_PATH = new RegExp(`^${SEGMENT}(?:\\.${SEGMENT})*$`);
12
+ var MISSING = /* @__PURE__ */ Symbol("missing");
13
+ var plain = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
14
+ function segments(path) {
15
+ return path.split(".").map((part) => {
16
+ const maps = part.endsWith("[]");
17
+ return { name: maps ? part.slice(0, -2) : part, maps };
18
+ });
19
+ }
20
+ function project(value, path) {
21
+ const [segment, ...rest] = path;
22
+ if (segment === void 0) return value;
23
+ if (!plain(value) || !Object.hasOwn(value, segment.name)) return MISSING;
24
+ const child = value[segment.name];
25
+ if (!segment.maps) {
26
+ const projected = project(child, rest);
27
+ return projected === MISSING ? MISSING : { [segment.name]: projected };
28
+ }
29
+ if (!Array.isArray(child)) return MISSING;
30
+ return {
31
+ [segment.name]: child.map((item) => {
32
+ const projected = project(item, rest);
33
+ return projected === MISSING ? {} : projected;
34
+ })
35
+ };
36
+ }
37
+ function reaches(value, path) {
38
+ const [segment, ...rest] = path;
39
+ if (segment === void 0) return true;
40
+ if (!plain(value) || !Object.hasOwn(value, segment.name)) return false;
41
+ const child = value[segment.name];
42
+ if (!segment.maps) return reaches(child, rest);
43
+ if (!Array.isArray(child)) return false;
44
+ return child.length === 0 || child.some((item) => reaches(item, rest));
45
+ }
46
+ function merge(left, right) {
47
+ if (Array.isArray(left) && Array.isArray(right)) {
48
+ if (left.length !== right.length) return MISSING;
49
+ const merged = [];
50
+ for (let index = 0; index < left.length; index += 1) {
51
+ const item = merge(left[index], right[index]);
52
+ if (item === MISSING) return MISSING;
53
+ merged.push(item);
54
+ }
55
+ return merged;
56
+ }
57
+ if (plain(left) && plain(right)) {
58
+ const merged = { ...left };
59
+ for (const [key, value] of Object.entries(right)) {
60
+ const item = Object.hasOwn(merged, key) ? merge(merged[key], value) : value;
61
+ if (item === MISSING) return MISSING;
62
+ Object.defineProperty(merged, key, { value: item, enumerable: true, configurable: true, writable: true });
63
+ }
64
+ return merged;
65
+ }
66
+ if (plain(right) && Object.keys(right).length === 0) return left;
67
+ return right;
68
+ }
69
+ function pick(data, paths) {
70
+ if (!plain(data)) return { ok: false };
71
+ let picked = {};
72
+ for (const path of paths) {
73
+ const projected = project(data, segments(path));
74
+ if (projected === MISSING) continue;
75
+ const merged = merge(picked, projected);
76
+ if (merged === MISSING || !plain(merged)) continue;
77
+ picked = merged;
78
+ }
79
+ return { ok: true, data: picked };
80
+ }
81
+ function missingPaths(data, paths) {
82
+ return paths.filter((path) => !reaches(data, segments(path)));
83
+ }
84
+ var MAX_REF_DEPTH = 32;
85
+ function branches(schema, root, depth = 0) {
86
+ if (typeof schema === "boolean" || depth > MAX_REF_DEPTH) return [schema];
87
+ const ref = schema["$ref"];
88
+ if (typeof ref === "string") {
89
+ const target = resolveRef(ref, root);
90
+ return target === void 0 ? [true] : branches(target, root, depth + 1);
91
+ }
92
+ const options = [schema["anyOf"], schema["oneOf"], schema["allOf"]].filter(Array.isArray).flat();
93
+ if (options.length === 0) return [schema];
94
+ return options.flatMap((option) => branches(option, root, depth + 1));
95
+ }
96
+ function resolveRef(ref, root) {
97
+ if (!ref.startsWith("#/") || typeof root === "boolean") return void 0;
98
+ let node = root;
99
+ for (const part of ref.slice(2).split("/").map((piece) => piece.replaceAll("~1", "/").replaceAll("~0", "~"))) {
100
+ if (!plain(node) || !Object.hasOwn(node, part)) return void 0;
101
+ node = node[part];
102
+ }
103
+ return plain(node) || typeof node === "boolean" ? node : void 0;
104
+ }
105
+ var types = (schema) => {
106
+ const type = schema["type"];
107
+ return typeof type === "string" ? [type] : Array.isArray(type) ? type.filter((item) => typeof item === "string") : void 0;
108
+ };
109
+ function property(schema, name, root) {
110
+ return branches(schema, root).flatMap((branch) => {
111
+ if (branch === true) return [true];
112
+ if (branch === false) return [];
113
+ const kinds = types(branch);
114
+ if (kinds && !kinds.includes("object")) return [];
115
+ const properties = branch["properties"];
116
+ if (plain(properties) && Object.hasOwn(properties, name)) return [properties[name]];
117
+ const additional = branch["additionalProperties"];
118
+ if (additional === false) return [];
119
+ if (plain(additional)) return [additional];
120
+ return [true];
121
+ });
122
+ }
123
+ function items(schema, root) {
124
+ return branches(schema, root).flatMap((branch) => {
125
+ if (branch === true) return [true];
126
+ if (branch === false) return [];
127
+ const kinds = types(branch);
128
+ if (kinds && !kinds.includes("array")) return [];
129
+ const item = branch["items"];
130
+ return [plain(item) || typeof item === "boolean" ? item : true];
131
+ });
132
+ }
133
+ function schemaReaches(schema, path, root) {
134
+ const [segment, ...rest] = path;
135
+ if (segment === void 0) return true;
136
+ for (const child of property(schema, segment.name, root)) {
137
+ const next = segment.maps ? items(child, root) : [child];
138
+ if (next.some((item) => schemaReaches(item, rest, root))) return true;
139
+ }
140
+ return false;
141
+ }
142
+ function pickProblems(paths, schema) {
143
+ if (!Array.isArray(paths)) return ["pick must be a list of paths"];
144
+ const problems = [];
145
+ if (paths.length === 0) problems.push("pick must name at least one path");
146
+ if (paths.length > MAX_PICK_PATHS) problems.push(`pick names ${paths.length} paths, over ${MAX_PICK_PATHS}`);
147
+ const seen = /* @__PURE__ */ new Set();
148
+ for (const [index, path] of paths.entries()) {
149
+ if (typeof path !== "string" || path.length === 0) {
150
+ problems.push(`pick[${index}] must be a path such as items[].title`);
151
+ continue;
152
+ }
153
+ if (path.length > MAX_PICK_PATH_LENGTH) {
154
+ problems.push(`pick[${index}] is ${path.length} characters, over ${MAX_PICK_PATH_LENGTH}`);
155
+ continue;
156
+ }
157
+ if (!PICK_PATH.test(path)) {
158
+ problems.push(`pick[${index}] "${path}" must be dotted names of letters, digits, _, $ or -, each optionally ending in [] to map over a list`);
159
+ continue;
160
+ }
161
+ if (seen.has(path)) problems.push(`pick[${index}] "${path}" repeats a path`);
162
+ seen.add(path);
163
+ if (schema !== void 0 && !schemaReaches(schema, segments(path), schema)) problems.push(`pick[${index}] "${path}" is not a path of the output`);
164
+ }
165
+ return problems;
166
+ }
167
+ function pickProblemsForOutput(output, paths, schema) {
168
+ const found = outputValidator(output);
169
+ if (found) return pickProblems(paths, found.jsonSchema());
170
+ if (isExtensionOutput(output)) {
171
+ if (schema === void 0) return [`"${output}" is an extension output and its source states no outputSchema`];
172
+ return pickProblems(paths, schema);
173
+ }
174
+ return [`"${output}" is not a registered output`];
175
+ }
176
+
177
+ export {
178
+ MAX_PICK_PATHS,
179
+ MAX_PICK_PATH_LENGTH,
180
+ PICK_PATH,
181
+ pick,
182
+ missingPaths,
183
+ pickProblems,
184
+ pickProblemsForOutput
185
+ };