@looply/core 0.0.0-stage → 0.2.0

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 (315) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +16 -3
  3. package/dist/acceptance-environment.d.ts +147 -0
  4. package/dist/acceptance-environment.d.ts.map +1 -0
  5. package/dist/acceptance-environment.js +205 -0
  6. package/dist/acceptance-environment.js.map +1 -0
  7. package/dist/action-canonical.d.ts +51 -0
  8. package/dist/action-canonical.d.ts.map +1 -0
  9. package/dist/action-canonical.js +86 -0
  10. package/dist/action-canonical.js.map +1 -0
  11. package/dist/action.d.ts +249 -0
  12. package/dist/action.d.ts.map +1 -0
  13. package/dist/action.js +473 -0
  14. package/dist/action.js.map +1 -0
  15. package/dist/activation-code.d.ts +76 -0
  16. package/dist/activation-code.d.ts.map +1 -0
  17. package/dist/activation-code.js +112 -0
  18. package/dist/activation-code.js.map +1 -0
  19. package/dist/approval-gate.d.ts +363 -0
  20. package/dist/approval-gate.d.ts.map +1 -0
  21. package/dist/approval-gate.js +442 -0
  22. package/dist/approval-gate.js.map +1 -0
  23. package/dist/approval.d.ts +240 -0
  24. package/dist/approval.d.ts.map +1 -0
  25. package/dist/approval.js +258 -0
  26. package/dist/approval.js.map +1 -0
  27. package/dist/at-this-tree.d.ts +80 -0
  28. package/dist/at-this-tree.d.ts.map +1 -0
  29. package/dist/at-this-tree.js +81 -0
  30. package/dist/at-this-tree.js.map +1 -0
  31. package/dist/autonomy-transition.d.ts +63 -0
  32. package/dist/autonomy-transition.d.ts.map +1 -0
  33. package/dist/autonomy-transition.js +39 -0
  34. package/dist/autonomy-transition.js.map +1 -0
  35. package/dist/brain-proposal.d.ts +189 -0
  36. package/dist/brain-proposal.d.ts.map +1 -0
  37. package/dist/brain-proposal.js +424 -0
  38. package/dist/brain-proposal.js.map +1 -0
  39. package/dist/candidate-replay.d.ts +132 -0
  40. package/dist/candidate-replay.d.ts.map +1 -0
  41. package/dist/candidate-replay.js +69 -0
  42. package/dist/candidate-replay.js.map +1 -0
  43. package/dist/concurrency.d.ts +99 -0
  44. package/dist/concurrency.d.ts.map +1 -0
  45. package/dist/concurrency.js +108 -0
  46. package/dist/concurrency.js.map +1 -0
  47. package/dist/converge.d.ts +112 -0
  48. package/dist/converge.d.ts.map +1 -0
  49. package/dist/converge.js +92 -0
  50. package/dist/converge.js.map +1 -0
  51. package/dist/cross-repo-depends.d.ts +109 -0
  52. package/dist/cross-repo-depends.d.ts.map +1 -0
  53. package/dist/cross-repo-depends.js +184 -0
  54. package/dist/cross-repo-depends.js.map +1 -0
  55. package/dist/cross-repo.d.ts +121 -0
  56. package/dist/cross-repo.d.ts.map +1 -0
  57. package/dist/cross-repo.js +143 -0
  58. package/dist/cross-repo.js.map +1 -0
  59. package/dist/depends-proposal.d.ts +198 -0
  60. package/dist/depends-proposal.d.ts.map +1 -0
  61. package/dist/depends-proposal.js +226 -0
  62. package/dist/depends-proposal.js.map +1 -0
  63. package/dist/depends-standing.d.ts +70 -0
  64. package/dist/depends-standing.d.ts.map +1 -0
  65. package/dist/depends-standing.js +77 -0
  66. package/dist/depends-standing.js.map +1 -0
  67. package/dist/envelope.d.ts +145 -0
  68. package/dist/envelope.d.ts.map +1 -0
  69. package/dist/envelope.js +162 -0
  70. package/dist/envelope.js.map +1 -0
  71. package/dist/events.d.ts +438 -0
  72. package/dist/events.d.ts.map +1 -0
  73. package/dist/events.js +88 -0
  74. package/dist/events.js.map +1 -0
  75. package/dist/exemption.d.ts +45 -0
  76. package/dist/exemption.d.ts.map +1 -0
  77. package/dist/exemption.js +41 -0
  78. package/dist/exemption.js.map +1 -0
  79. package/dist/goal-attested.d.ts +31 -0
  80. package/dist/goal-attested.d.ts.map +1 -0
  81. package/dist/goal-attested.js +83 -0
  82. package/dist/goal-attested.js.map +1 -0
  83. package/dist/goal-coverage-gate.d.ts +244 -0
  84. package/dist/goal-coverage-gate.d.ts.map +1 -0
  85. package/dist/goal-coverage-gate.js +225 -0
  86. package/dist/goal-coverage-gate.js.map +1 -0
  87. package/dist/goal-coverage.d.ts +226 -0
  88. package/dist/goal-coverage.d.ts.map +1 -0
  89. package/dist/goal-coverage.js +241 -0
  90. package/dist/goal-coverage.js.map +1 -0
  91. package/dist/goal-links.d.ts +69 -0
  92. package/dist/goal-links.d.ts.map +1 -0
  93. package/dist/goal-links.js +110 -0
  94. package/dist/goal-links.js.map +1 -0
  95. package/dist/goal.d.ts +339 -0
  96. package/dist/goal.d.ts.map +1 -0
  97. package/dist/goal.js +169 -0
  98. package/dist/goal.js.map +1 -0
  99. package/dist/governed-execution.d.ts +178 -0
  100. package/dist/governed-execution.d.ts.map +1 -0
  101. package/dist/governed-execution.js +212 -0
  102. package/dist/governed-execution.js.map +1 -0
  103. package/dist/governed-recovery.d.ts +115 -0
  104. package/dist/governed-recovery.d.ts.map +1 -0
  105. package/dist/governed-recovery.js +106 -0
  106. package/dist/governed-recovery.js.map +1 -0
  107. package/dist/governed-resolution.d.ts +73 -0
  108. package/dist/governed-resolution.d.ts.map +1 -0
  109. package/dist/governed-resolution.js +94 -0
  110. package/dist/governed-resolution.js.map +1 -0
  111. package/dist/graph-context.d.ts +97 -0
  112. package/dist/graph-context.d.ts.map +1 -0
  113. package/dist/graph-context.js +145 -0
  114. package/dist/graph-context.js.map +1 -0
  115. package/dist/graph-queries.d.ts +124 -0
  116. package/dist/graph-queries.d.ts.map +1 -0
  117. package/dist/graph-queries.js +295 -0
  118. package/dist/graph-queries.js.map +1 -0
  119. package/dist/ids.d.ts +115 -0
  120. package/dist/ids.d.ts.map +1 -0
  121. package/dist/ids.js +160 -0
  122. package/dist/ids.js.map +1 -0
  123. package/dist/index.d.ts +78 -0
  124. package/dist/index.d.ts.map +1 -0
  125. package/dist/index.js +94 -0
  126. package/dist/index.js.map +1 -0
  127. package/dist/integrated-receipt.d.ts +155 -0
  128. package/dist/integrated-receipt.d.ts.map +1 -0
  129. package/dist/integrated-receipt.js +144 -0
  130. package/dist/integrated-receipt.js.map +1 -0
  131. package/dist/item-cross-repo.d.ts +83 -0
  132. package/dist/item-cross-repo.d.ts.map +1 -0
  133. package/dist/item-cross-repo.js +90 -0
  134. package/dist/item-cross-repo.js.map +1 -0
  135. package/dist/item-depends.d.ts +111 -0
  136. package/dist/item-depends.d.ts.map +1 -0
  137. package/dist/item-depends.js +200 -0
  138. package/dist/item-depends.js.map +1 -0
  139. package/dist/item.d.ts +411 -0
  140. package/dist/item.d.ts.map +1 -0
  141. package/dist/item.js +301 -0
  142. package/dist/item.js.map +1 -0
  143. package/dist/judged-by.d.ts +151 -0
  144. package/dist/judged-by.d.ts.map +1 -0
  145. package/dist/judged-by.js +132 -0
  146. package/dist/judged-by.js.map +1 -0
  147. package/dist/ledger.d.ts +102 -0
  148. package/dist/ledger.d.ts.map +1 -0
  149. package/dist/ledger.js +160 -0
  150. package/dist/ledger.js.map +1 -0
  151. package/dist/loop-safety.d.ts +298 -0
  152. package/dist/loop-safety.d.ts.map +1 -0
  153. package/dist/loop-safety.js +410 -0
  154. package/dist/loop-safety.js.map +1 -0
  155. package/dist/memory-context.d.ts +86 -0
  156. package/dist/memory-context.d.ts.map +1 -0
  157. package/dist/memory-context.js +187 -0
  158. package/dist/memory-context.js.map +1 -0
  159. package/dist/observation-retention.d.ts +78 -0
  160. package/dist/observation-retention.d.ts.map +1 -0
  161. package/dist/observation-retention.js +62 -0
  162. package/dist/observation-retention.js.map +1 -0
  163. package/dist/partial-question.d.ts +132 -0
  164. package/dist/partial-question.d.ts.map +1 -0
  165. package/dist/partial-question.js +87 -0
  166. package/dist/partial-question.js.map +1 -0
  167. package/dist/plan-check.d.ts +80 -0
  168. package/dist/plan-check.d.ts.map +1 -0
  169. package/dist/plan-check.js +117 -0
  170. package/dist/plan-check.js.map +1 -0
  171. package/dist/project-graph.d.ts +376 -0
  172. package/dist/project-graph.d.ts.map +1 -0
  173. package/dist/project-graph.js +502 -0
  174. package/dist/project-graph.js.map +1 -0
  175. package/dist/project-index.d.ts +239 -0
  176. package/dist/project-index.d.ts.map +1 -0
  177. package/dist/project-index.js +259 -0
  178. package/dist/project-index.js.map +1 -0
  179. package/dist/project-memory.d.ts +243 -0
  180. package/dist/project-memory.d.ts.map +1 -0
  181. package/dist/project-memory.js +233 -0
  182. package/dist/project-memory.js.map +1 -0
  183. package/dist/project-origin.d.ts +84 -0
  184. package/dist/project-origin.d.ts.map +1 -0
  185. package/dist/project-origin.js +84 -0
  186. package/dist/project-origin.js.map +1 -0
  187. package/dist/proposal-record.d.ts +86 -0
  188. package/dist/proposal-record.d.ts.map +1 -0
  189. package/dist/proposal-record.js +103 -0
  190. package/dist/proposal-record.js.map +1 -0
  191. package/dist/publication-ruling.d.ts +77 -0
  192. package/dist/publication-ruling.d.ts.map +1 -0
  193. package/dist/publication-ruling.js +61 -0
  194. package/dist/publication-ruling.js.map +1 -0
  195. package/dist/report.d.ts +92 -0
  196. package/dist/report.d.ts.map +1 -0
  197. package/dist/report.js +215 -0
  198. package/dist/report.js.map +1 -0
  199. package/dist/requirement-receipt.d.ts +202 -0
  200. package/dist/requirement-receipt.d.ts.map +1 -0
  201. package/dist/requirement-receipt.js +110 -0
  202. package/dist/requirement-receipt.js.map +1 -0
  203. package/dist/retention-apply.d.ts +191 -0
  204. package/dist/retention-apply.d.ts.map +1 -0
  205. package/dist/retention-apply.js +198 -0
  206. package/dist/retention-apply.js.map +1 -0
  207. package/dist/retention.d.ts +132 -0
  208. package/dist/retention.d.ts.map +1 -0
  209. package/dist/retention.js +147 -0
  210. package/dist/retention.js.map +1 -0
  211. package/dist/review-applies.d.ts +166 -0
  212. package/dist/review-applies.d.ts.map +1 -0
  213. package/dist/review-applies.js +194 -0
  214. package/dist/review-applies.js.map +1 -0
  215. package/dist/round-lines.d.ts +59 -0
  216. package/dist/round-lines.d.ts.map +1 -0
  217. package/dist/round-lines.js +62 -0
  218. package/dist/round-lines.js.map +1 -0
  219. package/dist/round-notes.d.ts +99 -0
  220. package/dist/round-notes.d.ts.map +1 -0
  221. package/dist/round-notes.js +205 -0
  222. package/dist/round-notes.js.map +1 -0
  223. package/dist/round.d.ts +64 -0
  224. package/dist/round.d.ts.map +1 -0
  225. package/dist/round.js +90 -0
  226. package/dist/round.js.map +1 -0
  227. package/dist/schedule.d.ts +363 -0
  228. package/dist/schedule.d.ts.map +1 -0
  229. package/dist/schedule.js +578 -0
  230. package/dist/schedule.js.map +1 -0
  231. package/dist/served-text.d.ts +92 -0
  232. package/dist/served-text.d.ts.map +1 -0
  233. package/dist/served-text.js +106 -0
  234. package/dist/served-text.js.map +1 -0
  235. package/dist/session-adapter.d.ts +196 -0
  236. package/dist/session-adapter.d.ts.map +1 -0
  237. package/dist/session-adapter.js +194 -0
  238. package/dist/session-adapter.js.map +1 -0
  239. package/dist/session-adoption.d.ts +161 -0
  240. package/dist/session-adoption.d.ts.map +1 -0
  241. package/dist/session-adoption.js +189 -0
  242. package/dist/session-adoption.js.map +1 -0
  243. package/dist/session-checkpoint.d.ts +139 -0
  244. package/dist/session-checkpoint.d.ts.map +1 -0
  245. package/dist/session-checkpoint.js +125 -0
  246. package/dist/session-checkpoint.js.map +1 -0
  247. package/dist/session-control.d.ts +152 -0
  248. package/dist/session-control.d.ts.map +1 -0
  249. package/dist/session-control.js +164 -0
  250. package/dist/session-control.js.map +1 -0
  251. package/dist/session-direction.d.ts +125 -0
  252. package/dist/session-direction.d.ts.map +1 -0
  253. package/dist/session-direction.js +128 -0
  254. package/dist/session-direction.js.map +1 -0
  255. package/dist/session-observe.d.ts +245 -0
  256. package/dist/session-observe.d.ts.map +1 -0
  257. package/dist/session-observe.js +253 -0
  258. package/dist/session-observe.js.map +1 -0
  259. package/dist/settings.d.ts +98 -0
  260. package/dist/settings.d.ts.map +1 -0
  261. package/dist/settings.js +490 -0
  262. package/dist/settings.js.map +1 -0
  263. package/dist/shared-contract.d.ts +141 -0
  264. package/dist/shared-contract.d.ts.map +1 -0
  265. package/dist/shared-contract.js +117 -0
  266. package/dist/shared-contract.js.map +1 -0
  267. package/dist/source-attest.d.ts +73 -0
  268. package/dist/source-attest.d.ts.map +1 -0
  269. package/dist/source-attest.js +53 -0
  270. package/dist/source-attest.js.map +1 -0
  271. package/dist/source-classify.d.ts +214 -0
  272. package/dist/source-classify.d.ts.map +1 -0
  273. package/dist/source-classify.js +515 -0
  274. package/dist/source-classify.js.map +1 -0
  275. package/dist/source-intake.d.ts +174 -0
  276. package/dist/source-intake.d.ts.map +1 -0
  277. package/dist/source-intake.js +270 -0
  278. package/dist/source-intake.js.map +1 -0
  279. package/dist/source-plan.d.ts +86 -0
  280. package/dist/source-plan.d.ts.map +1 -0
  281. package/dist/source-plan.js +73 -0
  282. package/dist/source-plan.js.map +1 -0
  283. package/dist/source-reconcile.d.ts +111 -0
  284. package/dist/source-reconcile.d.ts.map +1 -0
  285. package/dist/source-reconcile.js +239 -0
  286. package/dist/source-reconcile.js.map +1 -0
  287. package/dist/source-tables.d.ts +175 -0
  288. package/dist/source-tables.d.ts.map +1 -0
  289. package/dist/source-tables.js +229 -0
  290. package/dist/source-tables.js.map +1 -0
  291. package/dist/status.d.ts +138 -0
  292. package/dist/status.d.ts.map +1 -0
  293. package/dist/status.js +256 -0
  294. package/dist/status.js.map +1 -0
  295. package/dist/surface.d.ts +149 -0
  296. package/dist/surface.d.ts.map +1 -0
  297. package/dist/surface.js +199 -0
  298. package/dist/surface.js.map +1 -0
  299. package/dist/task-packet.d.ts +137 -0
  300. package/dist/task-packet.d.ts.map +1 -0
  301. package/dist/task-packet.js +203 -0
  302. package/dist/task-packet.js.map +1 -0
  303. package/dist/touched-vs-changed.d.ts +37 -0
  304. package/dist/touched-vs-changed.d.ts.map +1 -0
  305. package/dist/touched-vs-changed.js +49 -0
  306. package/dist/touched-vs-changed.js.map +1 -0
  307. package/dist/trailer.d.ts +55 -0
  308. package/dist/trailer.d.ts.map +1 -0
  309. package/dist/trailer.js +85 -0
  310. package/dist/trailer.js.map +1 -0
  311. package/dist/wording-change.d.ts +86 -0
  312. package/dist/wording-change.d.ts.map +1 -0
  313. package/dist/wording-change.js +138 -0
  314. package/dist/wording-change.js.map +1 -0
  315. package/package.json +49 -6
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 vuedale
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,16 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
1
+ # @looply/core
2
+
3
+ The shared model behind `looply-cli`:
4
+ the round protocol, the event ledger, the queue and item states, the settings
5
+ registry, and the commit trailer.
6
+
7
+ It is published because the CLI depends on it at runtime. There is no reason to
8
+ install it directly — install `looply-cli` instead.
9
+
10
+ ```sh
11
+ npx looply-cli init
12
+ ```
13
+
14
+ Documentation: <https://looply-agent-app.web.app/docs/>
15
+
16
+ MIT © vuedale
@@ -0,0 +1,147 @@
1
+ export declare const ACCEPTANCE_PROFILE_DOMAIN = "looply-verification-profile-v1";
2
+ /**
3
+ * THE CLOSED SET OF FACTS THAT MAY BE ACCEPTANCE IDENTITY.
4
+ *
5
+ * 🔴 A LIST, NOT A CONVENTION. Rule 1 forbids username, credentials, home
6
+ * directory, pid and machine-specific paths from being acceptance identity, and
7
+ * a comment saying so is how a reader stops looking. `normaliseObserved` keeps
8
+ * ONLY these keys (plus a declared `probe.<name>`), so a capture that grew a
9
+ * `user` field could not reach the digest or the matcher: the smuggled fact is
10
+ * dropped before either sees it.
11
+ *
12
+ * ⚠️ THE ORDER IS THE CANONICAL ORDER. `canonicalProfile` iterates THIS array
13
+ * and the sorted probe keys, never `Object.keys(observed)`, whose order is
14
+ * insertion-dependent — two identical profiles built by different call sites
15
+ * must digest identically.
16
+ */
17
+ export declare const ACCEPTANCE_FACTS: readonly ["os", "arch", "runtime", "lock", "deps", "gates", "containment"];
18
+ export type CoreFact = (typeof ACCEPTANCE_FACTS)[number];
19
+ export declare function isAcceptanceFact(key: string): boolean;
20
+ /**
21
+ * What a gate pass was observed to happen under.
22
+ *
23
+ * ⚠️ THREE STATES PER FACT, AND COLLAPSING ANY TWO IS THE DEFECT. Absent means
24
+ * NOBODY ASKED; `null` means it was asked and could not be read; a string is an
25
+ * answer. They send a person to three different places, exactly as
26
+ * `check-not-executed` and `check-skipped` do one module over.
27
+ */
28
+ export type ObservedProfile = Readonly<Record<string, string | null>>;
29
+ export type FactPredicate = {
30
+ readonly kind: 'equals';
31
+ readonly value: string;
32
+ } | {
33
+ readonly kind: 'one-of';
34
+ readonly values: readonly string[];
35
+ }
36
+ /** Dotted-numeric only; anything else is a ConfigError at parse time. */
37
+ | {
38
+ readonly kind: 'at-least';
39
+ readonly version: string;
40
+ }
41
+ /** Any value, but it must be KNOWN. */
42
+ | {
43
+ readonly kind: 'known';
44
+ };
45
+ /**
46
+ * WHAT THE ACCEPTANCE SPECIFICATION DEMANDS.
47
+ *
48
+ * 🔴 IRRELEVANCE IS DECLARED, NOT GUESSED. A fact this object does not name
49
+ * cannot invalidate anything, because `matchProfile` never reads it. That is
50
+ * the whole implementation of "changes to IRRELEVANT facts must NOT invalidate
51
+ * acceptance": no heuristic, no allow-list of volatile fields, and no digest
52
+ * equality anywhere on an accept path.
53
+ *
54
+ * ⚠️ AN EMPTY PREDICATE ACCEPTS EVERY ENVIRONMENT, and that is today's
55
+ * behaviour byte for byte. There is deliberately NO default profile: the only
56
+ * core fact that could ever be unknown is `lock`, so a default demanding every
57
+ * core fact be known would refuse every project that is not npm-shaped, for
58
+ * ever — the shape `integration-runtime.ts:397-401` reverted a feature over.
59
+ */
60
+ export type RequiredProfile = Readonly<Record<string, FactPredicate>>;
61
+ export type EnvironmentRefusal =
62
+ /** The capture never asked about a fact the specification requires. Write the probe. */
63
+ {
64
+ readonly kind: 'fact-unobserved';
65
+ readonly fact: string;
66
+ readonly required: string;
67
+ }
68
+ /** It was asked and could not be read. Fix the machine. Rule 1: not evidence. */
69
+ | {
70
+ readonly kind: 'fact-unreadable';
71
+ readonly fact: string;
72
+ readonly required: string;
73
+ }
74
+ /** It was read and it is the wrong one. Move the work, or widen the predicate. */
75
+ | {
76
+ readonly kind: 'fact-mismatch';
77
+ readonly fact: string;
78
+ readonly required: string;
79
+ readonly observed: string;
80
+ };
81
+ export declare function describePredicate(p: FactPredicate): string;
82
+ /**
83
+ * THE TRUSTED MATCHER. PURE, AND THE ONLY THING THAT DECIDES.
84
+ *
85
+ * 🔴 THE LOOP IS OVER `required`, AND THAT ONE LINE IS THE WHOLE
86
+ * "IRRELEVANT FACTS MUST NOT INVALIDATE" CLAUSE. An observation may carry ten
87
+ * facts while a specification names one: the nine are recorded, printed and
88
+ * debuggable, and structurally incapable of refusing anything. There is no
89
+ * statement below that reads a key absent from `required`.
90
+ *
91
+ * Returns every refusal rather than the first, because a person fixing a
92
+ * machine wants the whole list in one pass. Empty means accepted.
93
+ */
94
+ export declare function matchProfile(required: RequiredProfile, observed: ObservedProfile): EnvironmentRefusal[];
95
+ /**
96
+ * ⚠️ A SENTINEL NO READABLE VALUE CAN PRODUCE. Without it a fact whose value is
97
+ * literally the word `unreadable` digests identically to one that could not be
98
+ * read, and the digest stops discriminating exactly where it matters most.
99
+ */
100
+ export declare const UNREADABLE = " unreadable";
101
+ export declare function canonicalProfile(facts: ObservedProfile): string;
102
+ /**
103
+ * A deterministic digest of the facts, STORED BESIDE THEM AND NEVER INSTEAD.
104
+ *
105
+ * ⚠️ IDENTITY FOR QUOTING AND DEDUP, NEVER THE ACCEPTANCE TEST. Comparing two
106
+ * digests would make a node patch bump invalidate every receipt — the precise
107
+ * thing Rule 1 forbids — so nothing in this package or its callers compares
108
+ * one. `matchProfile` decides; this labels. A person reading a refusal needs
109
+ * `runtime was node@20.11.0 and the specification wanted node@22`, not that
110
+ * `a91c…` is not `4f2e…`.
111
+ */
112
+ export declare function environmentDigest(facts: ObservedProfile): string;
113
+ /**
114
+ * ONE STEP OF THE ACCEPTANCE MAP, structurally — so this package keeps no
115
+ * dependency on the CLI's `StepSpec` while digesting exactly the same thing.
116
+ */
117
+ export interface AcceptanceStepShape {
118
+ readonly name: string;
119
+ readonly run: string;
120
+ readonly when?: string;
121
+ readonly required?: boolean;
122
+ readonly timeoutS?: number;
123
+ }
124
+ /**
125
+ * THE DIGEST OF THE ACCEPTANCE MAP ITSELF.
126
+ *
127
+ * 🔴 `provenBy` IS A STEP NAME, SO THE NAME ALONE IS NOT THE SPECIFICATION. A
128
+ * receipt that says "proved by jest" is about whatever `jest` RAN. Change the
129
+ * command, the filter or whether it is required, and the old receipt describes a
130
+ * check that no longer exists under that name — which is exactly the staleness
131
+ * Rule #2 asks to be caught rather than inherited.
132
+ *
133
+ * ⚠️ ORDER IS PART OF THE MAP and is NOT sorted away. `.looply/config.yaml`
134
+ * documents its gate order as the execution order ("cheapest first… a broken
135
+ * typecheck should not wait on a full suite"), so reordering is a real change to
136
+ * what a pass means.
137
+ *
138
+ * ⚠️ `timeoutS` IS INCLUDED, and that is a judgement rather than an oversight: a
139
+ * step whose budget was cut can newly time out, and a timeout is a failure with
140
+ * a different cause. Absent fields are written as the empty string so that
141
+ * adding `required: false` to a step that never had it does not move the digest.
142
+ */
143
+ export declare function acceptanceMapDigest(steps: readonly AcceptanceStepShape[]): string;
144
+ /** Keep only the closed set and declared probes. Anything else a capture invented is DROPPED here. */
145
+ export declare function normaliseObserved(raw: Readonly<Record<string, unknown>>): ObservedProfile;
146
+ export declare function describeEnvironmentRefusal(r: EnvironmentRefusal): string;
147
+ //# sourceMappingURL=acceptance-environment.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"acceptance-environment.d.ts","sourceRoot":"","sources":["../src/acceptance-environment.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,yBAAyB,mCAAmC,CAAC;AAE1E;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,gBAAgB,4EAsBnB,CAAC;AAEX,MAAM,MAAM,QAAQ,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC;AAWzD,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAErD;AAED;;;;;;;GAOG;AACH,MAAM,MAAM,eAAe,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC;AAEtE,MAAM,MAAM,aAAa,GACrB;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACnD;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE;AACjE,yEAAyE;GACvE;IAAE,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;CAAE;AACzD,uCAAuC;GACrC;IAAE,QAAQ,CAAC,IAAI,EAAE,OA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CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,SAAS,mBAAmB,EAAE,GAAG,MAAM,CAQjF;AAED,sGAAsG;AACtG,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,eAAe,CAQzF;AAED,wBAAgB,0BAA0B,CAAC,CAAC,EAAE,kBAAkB,GAAG,MAAM,CASxE"}
@@ -0,0 +1,205 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UNREADABLE = exports.ACCEPTANCE_FACTS = exports.ACCEPTANCE_PROFILE_DOMAIN = void 0;
4
+ exports.isAcceptanceFact = isAcceptanceFact;
5
+ exports.describePredicate = describePredicate;
6
+ exports.matchProfile = matchProfile;
7
+ exports.canonicalProfile = canonicalProfile;
8
+ exports.environmentDigest = environmentDigest;
9
+ exports.acceptanceMapDigest = acceptanceMapDigest;
10
+ exports.normaliseObserved = normaliseObserved;
11
+ exports.describeEnvironmentRefusal = describeEnvironmentRefusal;
12
+ const node_crypto_1 = require("node:crypto");
13
+ exports.ACCEPTANCE_PROFILE_DOMAIN = 'looply-verification-profile-v1';
14
+ /**
15
+ * THE CLOSED SET OF FACTS THAT MAY BE ACCEPTANCE IDENTITY.
16
+ *
17
+ * 🔴 A LIST, NOT A CONVENTION. Rule 1 forbids username, credentials, home
18
+ * directory, pid and machine-specific paths from being acceptance identity, and
19
+ * a comment saying so is how a reader stops looking. `normaliseObserved` keeps
20
+ * ONLY these keys (plus a declared `probe.<name>`), so a capture that grew a
21
+ * `user` field could not reach the digest or the matcher: the smuggled fact is
22
+ * dropped before either sees it.
23
+ *
24
+ * ⚠️ THE ORDER IS THE CANONICAL ORDER. `canonicalProfile` iterates THIS array
25
+ * and the sorted probe keys, never `Object.keys(observed)`, whose order is
26
+ * insertion-dependent — two identical profiles built by different call sites
27
+ * must digest identically.
28
+ */
29
+ exports.ACCEPTANCE_FACTS = [
30
+ /** `process.platform` — the OS FAMILY, never a build number. */
31
+ 'os',
32
+ /** `process.arch`. */
33
+ 'arch',
34
+ /** Runtime identity AND version: `node@22.11.0`. */
35
+ 'runtime',
36
+ /** Dependency identity: `<lockfile>@<sha256:16>`, or the readable answer `none`. */
37
+ 'lock',
38
+ /**
39
+ * `from-lock` or `carried-from-host`.
40
+ *
41
+ * 🔴 NOT A FORMALITY. `integration-runtime.ts:441-454` copies `node_modules`
42
+ * into the candidate's worktree from the LANE's tree, so the gate runs the
43
+ * candidate's lockfile against the host's installed tree. Recording `lock`
44
+ * alone would assert a dependency identity the check did not have.
45
+ */
46
+ 'deps',
47
+ /** `acceptanceMapDigest(cfg.gates)` — which acceptance map this pass ran under. */
48
+ 'gates',
49
+ /** `<backend>:available` or `<backend>:unavailable`, from `DoctorReport.containment`. */
50
+ 'containment',
51
+ ];
52
+ /**
53
+ * A fact only this project knows how to read — a database engine and major
54
+ * version, a migration head, a build target, an explicitly selected external
55
+ * double. Declared as a PREDICATE AND A PROBE TOGETHER (config.ts refuses one
56
+ * without the other), so there is no fact nothing reads and no demand nothing
57
+ * can observe.
58
+ */
59
+ const PROBE_FACT = /^probe\.[a-z][a-z0-9-]{0,31}$/;
60
+ function isAcceptanceFact(key) {
61
+ return exports.ACCEPTANCE_FACTS.includes(key) || PROBE_FACT.test(key);
62
+ }
63
+ function describePredicate(p) {
64
+ switch (p.kind) {
65
+ case 'equals':
66
+ return p.value;
67
+ case 'one-of':
68
+ return `one of ${[...p.values].join(', ')}`;
69
+ case 'at-least':
70
+ return `${p.version} or later`;
71
+ case 'known':
72
+ return 'any known value';
73
+ }
74
+ }
75
+ /** Dotted-numeric compare. A segment that is not a number sorts as 0, never as a throw. */
76
+ function atLeast(seen, want) {
77
+ const a = seen.split(/[^0-9]+/).map((s) => Number(s) || 0);
78
+ const b = want.split(/[^0-9]+/).map((s) => Number(s) || 0);
79
+ for (let i = 0; i < Math.max(a.length, b.length); i += 1) {
80
+ const x = a[i] ?? 0;
81
+ const y = b[i] ?? 0;
82
+ if (x !== y)
83
+ return x > y;
84
+ }
85
+ return true;
86
+ }
87
+ /**
88
+ * THE TRUSTED MATCHER. PURE, AND THE ONLY THING THAT DECIDES.
89
+ *
90
+ * 🔴 THE LOOP IS OVER `required`, AND THAT ONE LINE IS THE WHOLE
91
+ * "IRRELEVANT FACTS MUST NOT INVALIDATE" CLAUSE. An observation may carry ten
92
+ * facts while a specification names one: the nine are recorded, printed and
93
+ * debuggable, and structurally incapable of refusing anything. There is no
94
+ * statement below that reads a key absent from `required`.
95
+ *
96
+ * Returns every refusal rather than the first, because a person fixing a
97
+ * machine wants the whole list in one pass. Empty means accepted.
98
+ */
99
+ function matchProfile(required, observed) {
100
+ const refusals = [];
101
+ for (const fact of Object.keys(required).sort()) {
102
+ const p = required[fact];
103
+ const want = describePredicate(p);
104
+ const seen = observed[fact];
105
+ // ⚠️ ABSENT AND null ARE DIFFERENT ANSWERS AND NEITHER IS EVIDENCE. There is
106
+ // no branch below that can accept without a value.
107
+ if (seen === undefined) {
108
+ refusals.push({ kind: 'fact-unobserved', fact, required: want });
109
+ continue;
110
+ }
111
+ if (seen === null) {
112
+ refusals.push({ kind: 'fact-unreadable', fact, required: want });
113
+ continue;
114
+ }
115
+ const held = p.kind === 'known'
116
+ ? true
117
+ : p.kind === 'equals'
118
+ ? seen === p.value
119
+ : p.kind === 'one-of'
120
+ ? p.values.includes(seen)
121
+ : atLeast(seen, p.version);
122
+ if (!held)
123
+ refusals.push({ kind: 'fact-mismatch', fact, required: want, observed: seen });
124
+ }
125
+ return refusals;
126
+ }
127
+ /**
128
+ * ⚠️ A SENTINEL NO READABLE VALUE CAN PRODUCE. Without it a fact whose value is
129
+ * literally the word `unreadable` digests identically to one that could not be
130
+ * read, and the digest stops discriminating exactly where it matters most.
131
+ */
132
+ exports.UNREADABLE = '\u0020unreadable';
133
+ function canonicalProfile(facts) {
134
+ const core = exports.ACCEPTANCE_FACTS.filter((f) => facts[f] !== undefined);
135
+ const probes = Object.keys(facts)
136
+ .filter((k) => !exports.ACCEPTANCE_FACTS.includes(k))
137
+ .sort();
138
+ return [...core, ...probes].map((f) => `${f}=${facts[f] === null ? exports.UNREADABLE : facts[f]}`).join('\n');
139
+ }
140
+ /**
141
+ * A deterministic digest of the facts, STORED BESIDE THEM AND NEVER INSTEAD.
142
+ *
143
+ * ⚠️ IDENTITY FOR QUOTING AND DEDUP, NEVER THE ACCEPTANCE TEST. Comparing two
144
+ * digests would make a node patch bump invalidate every receipt — the precise
145
+ * thing Rule 1 forbids — so nothing in this package or its callers compares
146
+ * one. `matchProfile` decides; this labels. A person reading a refusal needs
147
+ * `runtime was node@20.11.0 and the specification wanted node@22`, not that
148
+ * `a91c…` is not `4f2e…`.
149
+ */
150
+ function environmentDigest(facts) {
151
+ return (0, node_crypto_1.createHash)('sha256')
152
+ .update(`${exports.ACCEPTANCE_PROFILE_DOMAIN}\n${canonicalProfile(facts)}`, 'utf8')
153
+ .digest('hex')
154
+ .slice(0, 16);
155
+ }
156
+ /**
157
+ * THE DIGEST OF THE ACCEPTANCE MAP ITSELF.
158
+ *
159
+ * 🔴 `provenBy` IS A STEP NAME, SO THE NAME ALONE IS NOT THE SPECIFICATION. A
160
+ * receipt that says "proved by jest" is about whatever `jest` RAN. Change the
161
+ * command, the filter or whether it is required, and the old receipt describes a
162
+ * check that no longer exists under that name — which is exactly the staleness
163
+ * Rule #2 asks to be caught rather than inherited.
164
+ *
165
+ * ⚠️ ORDER IS PART OF THE MAP and is NOT sorted away. `.looply/config.yaml`
166
+ * documents its gate order as the execution order ("cheapest first… a broken
167
+ * typecheck should not wait on a full suite"), so reordering is a real change to
168
+ * what a pass means.
169
+ *
170
+ * ⚠️ `timeoutS` IS INCLUDED, and that is a judgement rather than an oversight: a
171
+ * step whose budget was cut can newly time out, and a timeout is a failure with
172
+ * a different cause. Absent fields are written as the empty string so that
173
+ * adding `required: false` to a step that never had it does not move the digest.
174
+ */
175
+ function acceptanceMapDigest(steps) {
176
+ const canonical = steps
177
+ .map((s) => [s.name, s.run, s.when ?? '', s.required === true ? 'required' : '', s.timeoutS ?? ''].join('\u0000'))
178
+ .join('\n');
179
+ return (0, node_crypto_1.createHash)('sha256')
180
+ .update(`${exports.ACCEPTANCE_PROFILE_DOMAIN}\nmap\n${canonical}`, 'utf8')
181
+ .digest('hex')
182
+ .slice(0, 16);
183
+ }
184
+ /** Keep only the closed set and declared probes. Anything else a capture invented is DROPPED here. */
185
+ function normaliseObserved(raw) {
186
+ const out = {};
187
+ for (const key of Object.keys(raw)) {
188
+ if (!isAcceptanceFact(key))
189
+ continue;
190
+ const v = raw[key];
191
+ out[key] = typeof v === 'string' && v.trim() !== '' ? v.trim() : null;
192
+ }
193
+ return out;
194
+ }
195
+ function describeEnvironmentRefusal(r) {
196
+ switch (r.kind) {
197
+ case 'fact-unobserved':
198
+ return `the acceptance specification requires ${r.fact} to be ${r.required} and nothing asked what it was`;
199
+ case 'fact-unreadable':
200
+ return `${r.fact} could not be read, and an unknown fact is not evidence under a strict programme`;
201
+ case 'fact-mismatch':
202
+ return `the acceptance specification requires ${r.fact} to be ${r.required}; these checks ran under ${r.observed}`;
203
+ }
204
+ }
205
+ //# sourceMappingURL=acceptance-environment.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"acceptance-environment.js","sourceRoot":"","sources":["../src/acceptance-environment.ts"],"names":[],"mappings":";;;AAsDA,4CAEC;AAkDD,8CAWC;AA0BD,oCA2BC;AASD,4CAMC;AAYD,8CAKC;AAiCD,kDAQC;AAGD,8CAQC;AAED,gEASC;AAzQD,6CAAyC;AAE5B,QAAA,yBAAyB,GAAG,gCAAgC,CAAC;AAE1E;;;;;;;;;;;;;;GAcG;AACU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EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;IACxE,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,SAAgB,0BAA0B,CAAC,CAAqB;IAC9D,QAAQ,CAAC,CAAC,IAAI,EAAE,CAAC;QACf,KAAK,iBAAiB;YACpB,OAAO,yCAAyC,CAAC,CAAC,IAAI,UAAU,CAAC,CAAC,QAAQ,gCAAgC,CAAC;QAC7G,KAAK,iBAAiB;YACpB,OAAO,GAAG,CAAC,CAAC,IAAI,kFAAkF,CAAC;QACrG,KAAK,eAAe;YAClB,OAAO,yCAAyC,CAAC,CAAC,IAAI,UAAU,CAAC,CAAC,QAAQ,4BAA4B,CAAC,CAAC,QAAQ,EAAE,CAAC;IACvH,CAAC;AACH,CAAC"}
@@ -0,0 +1,51 @@
1
+ /**
2
+ * ONE CANONICAL FORM, AND ONE PLACE THAT DEFINES IT.
3
+ *
4
+ * A future approval authorises ONE EXACT ACTION. That only means something if
5
+ * two people — this machine and the server, today and next year — can look at a
6
+ * request and agree, byte for byte, on what it says. So the encoding is written
7
+ * down here and nowhere else.
8
+ *
9
+ * WHY NOT `JSON.stringify`. It serialises keys in insertion order, so the same
10
+ * action built by two code paths produces two different strings and two
11
+ * different fingerprints. It renders `undefined` in arrays as `null` and drops
12
+ * it in objects. It accepts `NaN` and writes `null`. It is a debugging format,
13
+ * not an agreement.
14
+ *
15
+ * WHY NOT `seedOf` FROM `ids.ts`. That takes a flat list of primitives and
16
+ * exists to derive an id; it has no key ordering because it never sees an
17
+ * object. Reaching for it here would put approval authority and id derivation
18
+ * behind one helper, and the day someone changed it for one purpose they would
19
+ * silently change the other.
20
+ *
21
+ * CROSS-LANGUAGE ON PURPOSE. The rules below are the ones any language can
22
+ * follow with its own JSON primitives: sort keys by code unit, keep array
23
+ * order, no insertion-order dependence, no class names, no `undefined`. A
24
+ * server or a phone must be able to recompute this and get the same bytes.
25
+ */
26
+ /** The only shapes that may carry authority. */
27
+ export type CanonicalValue = string | number | boolean | null | readonly CanonicalValue[] | {
28
+ readonly [key: string]: CanonicalValue;
29
+ };
30
+ export declare class CanonicalError extends Error {
31
+ }
32
+ /**
33
+ * The canonical text of a value.
34
+ *
35
+ * Object keys are sorted by UTF-16 code unit, which is the ordering every
36
+ * language can reproduce without agreeing on a locale. Array order is kept,
37
+ * because in an array the order IS the meaning.
38
+ */
39
+ export declare function canonicalize(value: CanonicalValue): string;
40
+ /**
41
+ * The domain this digest belongs to.
42
+ *
43
+ * Prefixed and versioned so a digest of an action can never equal a digest of
44
+ * anything else Looply hashes, and so a later canonical form cannot be mistaken
45
+ * for this one. Changing the version changes every fingerprint, which is the
46
+ * point: old approvals must not be reinterpreted under new rules.
47
+ */
48
+ export declare const ACTION_DIGEST_DOMAIN = "looply-action-request-v1";
49
+ /** Lowercase hex SHA-256 of the domain, a newline, and the canonical text. */
50
+ export declare function actionDigest(canonical: string): string;
51
+ //# sourceMappingURL=action-canonical.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"action-canonical.d.ts","sourceRoot":"","sources":["../src/action-canonical.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,gDAAgD;AAChD,MAAM,MAAM,cAAc,GACtB,MAAM,GACN,MAAM,GACN,OAAO,GACP,IAAI,GACJ,SAAS,cAAc,EAAE,GACzB;IAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,cAAc,CAAA;CAAE,CAAC;AAE/C,qBAAa,cAAe,SAAQ,KAAK;CAAG;AA0B5C;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,cAAc,GAAG,MAAM,CA6B1D;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,oBAAoB,6BAA6B,CAAC;AAE/D,8EAA8E;AAC9E,wBAAgB,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAItD"}
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ACTION_DIGEST_DOMAIN = exports.CanonicalError = void 0;
4
+ exports.canonicalize = canonicalize;
5
+ exports.actionDigest = actionDigest;
6
+ const crypto_1 = require("crypto");
7
+ class CanonicalError extends Error {
8
+ }
9
+ exports.CanonicalError = CanonicalError;
10
+ /**
11
+ * NUMBERS ARE INTEGERS HERE, AND THAT IS DELIBERATE.
12
+ *
13
+ * `0.1 + 0.2` is not `0.3`, and an approval that means one amount on this
14
+ * machine and another on a server is worse than no approval. Anything with a
15
+ * fractional part must be expressed by the action's own schema as minor units
16
+ * or as a decimal string, where the action decides what its digits mean.
17
+ */
18
+ function encodeNumber(n) {
19
+ if (!Number.isFinite(n)) {
20
+ throw new CanonicalError(`a canonical number must be finite, not ${String(n)}`);
21
+ }
22
+ if (!Number.isInteger(n)) {
23
+ throw new CanonicalError(`a canonical number must be a whole number, not ${String(n)} — express fractions as minor units or a decimal string`);
24
+ }
25
+ if (!Number.isSafeInteger(n)) {
26
+ throw new CanonicalError(`${String(n)} is past the range integers survive exactly`);
27
+ }
28
+ // `-0` and `0` are the same value and must not be two different bytes.
29
+ return Object.is(n, -0) ? '0' : String(n);
30
+ }
31
+ /**
32
+ * The canonical text of a value.
33
+ *
34
+ * Object keys are sorted by UTF-16 code unit, which is the ordering every
35
+ * language can reproduce without agreeing on a locale. Array order is kept,
36
+ * because in an array the order IS the meaning.
37
+ */
38
+ function canonicalize(value) {
39
+ if (value === null)
40
+ return 'null';
41
+ if (typeof value === 'boolean')
42
+ return value ? 'true' : 'false';
43
+ if (typeof value === 'number')
44
+ return encodeNumber(value);
45
+ if (typeof value === 'string') {
46
+ // JSON's own string escaping: exact code units, no normalisation. Two
47
+ // strings that look alike but are not the same text must not collide.
48
+ return JSON.stringify(value);
49
+ }
50
+ if (Array.isArray(value)) {
51
+ return `[${value.map((v) => canonicalize(v)).join(',')}]`;
52
+ }
53
+ if (typeof value === 'object') {
54
+ const obj = value;
55
+ const keys = Object.keys(obj).sort();
56
+ const parts = [];
57
+ for (const k of keys) {
58
+ const v = obj[k];
59
+ // ABSENT AND NULL ARE DIFFERENT, and neither is `undefined`. A key that
60
+ // exists with no value is a hole in the meaning of the request; a schema
61
+ // that wants "not set" says so with `null` or leaves the key out.
62
+ if (v === undefined) {
63
+ throw new CanonicalError(`the key ${JSON.stringify(k)} is present with no value`);
64
+ }
65
+ parts.push(`${JSON.stringify(k)}:${canonicalize(v)}`);
66
+ }
67
+ return `{${parts.join(',')}}`;
68
+ }
69
+ throw new CanonicalError(`${typeof value} cannot carry authority`);
70
+ }
71
+ /**
72
+ * The domain this digest belongs to.
73
+ *
74
+ * Prefixed and versioned so a digest of an action can never equal a digest of
75
+ * anything else Looply hashes, and so a later canonical form cannot be mistaken
76
+ * for this one. Changing the version changes every fingerprint, which is the
77
+ * point: old approvals must not be reinterpreted under new rules.
78
+ */
79
+ exports.ACTION_DIGEST_DOMAIN = 'looply-action-request-v1';
80
+ /** Lowercase hex SHA-256 of the domain, a newline, and the canonical text. */
81
+ function actionDigest(canonical) {
82
+ return (0, crypto_1.createHash)('sha256')
83
+ .update(`${exports.ACTION_DIGEST_DOMAIN}\n${canonical}`, 'utf8')
84
+ .digest('hex');
85
+ }
86
+ //# sourceMappingURL=action-canonical.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"action-canonical.js","sourceRoot":"","sources":["../src/action-canonical.ts"],"names":[],"mappings":";;;AAsEA,oCA6BC;AAaD,oCAIC;AApHD,mCAAoC;AAqCpC,MAAa,cAAe,SAAQ,KAAK;CAAG;AAA5C,wCAA4C;AAE5C;;;;;;;GAOG;AACH,SAAS,YAAY,CAAC,CAAS;IAC7B,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC;QACxB,MAAM,IAAI,cAAc,CAAC,0CAA0C,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IAClF,CAAC;IACD,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC;Q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