@yaks/tracker 0.0.0-stage → 0.2.36

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 (198) hide show
  1. package/Histogram.js +71 -0
  2. package/Histogram.js.map +1 -0
  3. package/Histogram.ts +100 -0
  4. package/LICENSE +202 -0
  5. package/README.md +639 -2
  6. package/_dist/brief.d.ts +25 -0
  7. package/_dist/brief.d.ts.map +1 -0
  8. package/_dist/changes.d.ts +9 -0
  9. package/_dist/changes.d.ts.map +1 -0
  10. package/_dist/chart.d.ts +24 -0
  11. package/_dist/chart.d.ts.map +1 -0
  12. package/_dist/digest.d.ts +64 -0
  13. package/_dist/digest.d.ts.map +1 -0
  14. package/_dist/effects.d.ts +73 -0
  15. package/_dist/effects.d.ts.map +1 -0
  16. package/_dist/errors.d.ts +14 -0
  17. package/_dist/errors.d.ts.map +1 -0
  18. package/_dist/everywhere.d.ts +13 -0
  19. package/_dist/everywhere.d.ts.map +1 -0
  20. package/_dist/fault.d.ts +29 -0
  21. package/_dist/fault.d.ts.map +1 -0
  22. package/_dist/file.d.ts +6 -0
  23. package/_dist/file.d.ts.map +1 -0
  24. package/_dist/fixtime.d.ts +20 -0
  25. package/_dist/fixtime.d.ts.map +1 -0
  26. package/_dist/frames.d.ts +6 -0
  27. package/_dist/frames.d.ts.map +1 -0
  28. package/_dist/graph.d.ts +3 -0
  29. package/_dist/graph.d.ts.map +1 -0
  30. package/_dist/group.d.ts +21 -0
  31. package/_dist/group.d.ts.map +1 -0
  32. package/_dist/instrument.d.ts +37 -0
  33. package/_dist/instrument.d.ts.map +1 -0
  34. package/_dist/intake.d.ts +21 -0
  35. package/_dist/intake.d.ts.map +1 -0
  36. package/_dist/merge.d.ts +11 -0
  37. package/_dist/merge.d.ts.map +1 -0
  38. package/_dist/mod.d.ts +7 -0
  39. package/_dist/mod.d.ts.map +1 -0
  40. package/_dist/model.d.ts +20 -0
  41. package/_dist/model.d.ts.map +1 -0
  42. package/_dist/outage.d.ts +7 -0
  43. package/_dist/outage.d.ts.map +1 -0
  44. package/_dist/people.d.ts +3 -0
  45. package/_dist/people.d.ts.map +1 -0
  46. package/_dist/poll.d.ts +101 -0
  47. package/_dist/poll.d.ts.map +1 -0
  48. package/_dist/poll_thread.d.ts +8 -0
  49. package/_dist/poll_thread.d.ts.map +1 -0
  50. package/_dist/reading.d.ts +34 -0
  51. package/_dist/reading.d.ts.map +1 -0
  52. package/_dist/remote.d.ts +61 -0
  53. package/_dist/remote.d.ts.map +1 -0
  54. package/_dist/report.d.ts +324 -0
  55. package/_dist/report.d.ts.map +1 -0
  56. package/_dist/resolution.d.ts +22 -0
  57. package/_dist/resolution.d.ts.map +1 -0
  58. package/_dist/routes.d.ts +33 -0
  59. package/_dist/routes.d.ts.map +1 -0
  60. package/_dist/script.d.ts +8 -0
  61. package/_dist/script.d.ts.map +1 -0
  62. package/_dist/service.d.ts +30 -0
  63. package/_dist/service.d.ts.map +1 -0
  64. package/_dist/sync_health.d.ts +4 -0
  65. package/_dist/sync_health.d.ts.map +1 -0
  66. package/_dist/ticket.d.ts +14 -0
  67. package/_dist/ticket.d.ts.map +1 -0
  68. package/_dist/tools.d.ts +39 -0
  69. package/_dist/tools.d.ts.map +1 -0
  70. package/_dist/trace-intake.d.ts +25 -0
  71. package/_dist/trace-intake.d.ts.map +1 -0
  72. package/_dist/views.d.ts +11 -0
  73. package/_dist/views.d.ts.map +1 -0
  74. package/_dist/vocab.d.ts +9 -0
  75. package/_dist/vocab.d.ts.map +1 -0
  76. package/box.json +51 -0
  77. package/brief.js +86 -0
  78. package/brief.js.map +1 -0
  79. package/brief.ts +120 -0
  80. package/changes.js +57 -0
  81. package/changes.js.map +1 -0
  82. package/changes.ts +70 -0
  83. package/chart.js +186 -0
  84. package/chart.js.map +1 -0
  85. package/chart.ts +193 -0
  86. package/deno.json +1 -0
  87. package/digest.js +329 -0
  88. package/digest.js.map +1 -0
  89. package/digest.ts +406 -0
  90. package/effects.js +136 -0
  91. package/effects.js.map +1 -0
  92. package/effects.ts +178 -0
  93. package/errors.js +130 -0
  94. package/errors.js.map +1 -0
  95. package/errors.ts +185 -0
  96. package/everywhere.js +46 -0
  97. package/everywhere.js.map +1 -0
  98. package/everywhere.ts +66 -0
  99. package/fault.js +65 -0
  100. package/fault.js.map +1 -0
  101. package/fault.ts +107 -0
  102. package/file.js +87 -0
  103. package/file.js.map +1 -0
  104. package/file.ts +93 -0
  105. package/fixtime.js +67 -0
  106. package/fixtime.js.map +1 -0
  107. package/fixtime.ts +86 -0
  108. package/frames.js +77 -0
  109. package/frames.js.map +1 -0
  110. package/frames.ts +69 -0
  111. package/graph.js +7 -0
  112. package/graph.js.map +1 -0
  113. package/graph.ts +8 -0
  114. package/group.js +444 -0
  115. package/group.js.map +1 -0
  116. package/group.ts +533 -0
  117. package/inspect.js +471 -0
  118. package/inspect.js.map +1 -0
  119. package/inspect.ts +693 -0
  120. package/instrument.js +69 -0
  121. package/instrument.js.map +1 -0
  122. package/instrument.ts +93 -0
  123. package/intake.js +43 -0
  124. package/intake.js.map +1 -0
  125. package/intake.ts +84 -0
  126. package/merge.js +126 -0
  127. package/merge.js.map +1 -0
  128. package/merge.ts +115 -0
  129. package/migrate.ts +36 -0
  130. package/mod.js +8 -0
  131. package/mod.js.map +1 -0
  132. package/mod.ts +19 -0
  133. package/model.js +8 -0
  134. package/model.js.map +1 -0
  135. package/model.ts +27 -0
  136. package/outage.js +129 -0
  137. package/outage.js.map +1 -0
  138. package/outage.ts +158 -0
  139. package/package.json +133 -4
  140. package/page.d.ts +2 -0
  141. package/page.js +905 -0
  142. package/people.js +51 -0
  143. package/people.js.map +1 -0
  144. package/people.ts +82 -0
  145. package/poll.js +277 -0
  146. package/poll.js.map +1 -0
  147. package/poll.ts +411 -0
  148. package/poll_thread.js +104 -0
  149. package/poll_thread.js.map +1 -0
  150. package/poll_thread.ts +126 -0
  151. package/poll_worker.ts +45 -0
  152. package/reading.js +122 -0
  153. package/reading.js.map +1 -0
  154. package/reading.ts +162 -0
  155. package/reconcile.js +113 -0
  156. package/reconcile.js.map +1 -0
  157. package/reconcile.ts +130 -0
  158. package/remote.js +312 -0
  159. package/remote.js.map +1 -0
  160. package/remote.ts +397 -0
  161. package/report.js +825 -0
  162. package/report.js.map +1 -0
  163. package/report.ts +944 -0
  164. package/resolution.js +114 -0
  165. package/resolution.js.map +1 -0
  166. package/resolution.ts +123 -0
  167. package/routes.js +130 -0
  168. package/routes.js.map +1 -0
  169. package/routes.ts +163 -0
  170. package/script.js +13 -0
  171. package/script.js.map +1 -0
  172. package/script.ts +16 -0
  173. package/service.js +174 -0
  174. package/service.js.map +1 -0
  175. package/service.ts +215 -0
  176. package/spread.js +94 -0
  177. package/spread.js.map +1 -0
  178. package/spread.ts +101 -0
  179. package/sync_health.js +36 -0
  180. package/sync_health.js.map +1 -0
  181. package/sync_health.ts +65 -0
  182. package/ticket.js +6 -0
  183. package/ticket.js.map +1 -0
  184. package/ticket.ts +24 -0
  185. package/tools.js +305 -0
  186. package/tools.js.map +1 -0
  187. package/tools.ts +411 -0
  188. package/trace-intake.js +164 -0
  189. package/trace-intake.js.map +1 -0
  190. package/trace-intake.ts +148 -0
  191. package/views.js +247 -0
  192. package/views.js.map +1 -0
  193. package/views.ts +254 -0
  194. package/vocab.js +20 -0
  195. package/vocab.js.map +1 -0
  196. package/vocab.json +834 -0
  197. package/vocab.ts +14 -0
  198. package/yak-tracker@.service +22 -0
@@ -0,0 +1,30 @@
1
+ import type { Graph } from "@yaks/graph";
2
+ import { type Source } from "./intake.js";
3
+ export { intake, type Record, type Source } from "./intake.js";
4
+ import { type Context } from "./report.js";
5
+ import { type Remote } from "./remote.js";
6
+ import type { Clock } from "@yaks/fp";
7
+ import { type Notice } from "./sync_health.js";
8
+ export type Options = {
9
+ source?: Source;
10
+ spool?: string;
11
+ every?: number;
12
+ report?: (error: unknown, context?: Partial<Context>) => void;
13
+ remote?: Remote;
14
+ fetch?: typeof fetch;
15
+ /** what time it is and how a wait is set for the syncs' passes
16
+ * (./outage.ts), so a test can hold the clock */ clock?: Clock;
17
+ /** Independent local notice path; never forwarded into the failing outbox. */ notice?: Notice;
18
+ /** a sync the platform tracker could not answer, and its answering again
19
+ * (default: `console.warn`) */ log?: (line: string) => void;
20
+ reconcileEvery?: number;
21
+ };
22
+ export declare let service: (host: {
23
+ graph: Graph;
24
+ config?: {
25
+ tracker?: {
26
+ spool: string;
27
+ };
28
+ };
29
+ }, options?: Options, signal?: AbortSignal) => Promise<void>;
30
+ //# sourceMappingURL=service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service.d.ts","sources":["../service.ts"],"names":[],"mappings":"AAKA,cAAc,KAAK,2BAAgC;AACnD,SAAoC,KAAK,MAAM,sBAAqB;AACpE,SAAS,MAAM,EAAE,KAAK,MAAM,EAAE,KAAK,MAAM,sBAAqB;AAG9D,SAAiB,KAAK,OAAO,sBAA4B;AACzD,SAAmB,KAAK,MAAM,sBAAkC;AAEhE,cAAc,KAAK,wBAA6B;AAChD,SAEE,KAAK,MAAM,2BAGY;AAEzB,YAAY;EACV,SAAS;EACT,QAAQ,MAAM;EACd,QAAQ,MAAM;EACd,UAAU,OAAO,OAAO,EAAE,UAAU,QAAQ,aAAa,IAAI;EAC7D,SAAS;EACT,eAAe;EACf;iDAC+C,GAC/C,QAAQ;EACR,4EAA4E,GAC5E,SAAS;EACT;+BAC6B,GAC7B,OAAO,MAAM,MAAM,KAAK,IAAI;EAC5B,iBAAiB,MAAM;;AAMzB,OAAO,YAAI,UACT;EACE,OAAO;EACP;IAAW;MAAY,OAAO,MAAM;;;GAEtC,UAAS,SACT,SAAQ,gBACP,QAAQ,IAAI,EAqKd"}
@@ -0,0 +1,4 @@
1
+ export type Direction = 'delivery' | 'standing';
2
+ /** Where a failed sync is told: an `Error` naming the sync, its cause the
3
+ * failure. */ export type Notice = (error: Error, direction: Direction) => Promise<void>;
4
+ //# sourceMappingURL=sync_health.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync_health.d.ts","sources":["../sync_health.ts"],"names":[],"mappings":"AAcA,YAAY,YAAY,aAAa;AAErC;YACY,GACZ,YAAY,UAAU,OAAO,OAAO,WAAW,cAAc,QAAQ,IAAI"}
@@ -0,0 +1,14 @@
1
+ /** Short-lived tracker tickets issued by a trusted host: a signed value
2
+ * (@yaks/secrets/signed) under the tracker's own label. No ticket or secret is
3
+ * persisted; callers issue one when they call remotely. */ export type Access = {
4
+ scope: string;
5
+ person: string;
6
+ exp: number;
7
+ admin?: boolean;
8
+ ingest?: boolean;
9
+ mark?: boolean;
10
+ };
11
+ /** Signs the tracker ticket the tracker's authorization opens. */ export declare let sign: (access: Access, secret: string) => Promise<string>;
12
+ /** What a ticket grants, or null for anything but a ticket signed under this
13
+ * secret; its expiry and scope are the caller's to check. */ export declare let opened: (ticket: string, secret: string) => Promise<Access | null>;
14
+ //# sourceMappingURL=ticket.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ticket.d.ts","sources":["../ticket.ts"],"names":[],"mappings":"AAEA;;yDAEyD,GACzD,YAAY;EACV,OAAO,MAAM;EACb,QAAQ,MAAM;EACd,KAAK,MAAM;EACX,QAAQ,OAAO;EACf,SAAS,OAAO;EAChB,OAAO,OAAO;;AAKhB,gEAAgE,GAChE,OAAO,YAAI,OAAQ,QAAQ,QAAQ,QAAQ,MAAM,KAAG,QAAQ,MAAM,EACnC;AAE/B;2DAC2D,GAC3D,OAAO,YAAI,SAAU,QAAQ,MAAM,EAAE,QAAQ,MAAM,KAAG,QAAQ,SAAS,IAAI,EACjC"}
@@ -0,0 +1,39 @@
1
+ import { type Bundle, type Graph } from "@yaks/graph";
2
+ import type { Runs } from "@yaks/graph/tools";
3
+ import { type Query } from "@yaks/query";
4
+ import { type Options } from "./routes.js";
5
+ /** The part of a store the bug tools read and mark: this graph, or the box
6
+ * tracker's graph over its wire. */ type Store = Pick<Graph, 'vocab' | 'get' | 'read' | 'address'> & {
7
+ /** how many entities a query selects, where the store is not a graph that
8
+ * counts its own rows */ count?: (q: Query) => Promise<number>;
9
+ rows?: Graph['rows'];
10
+ /** apply a mark's patch where the store keeps it, or hand it back for the
11
+ * runner to apply here */ mark?: (bundles: Partial<Bundle>[]) => Promise<void>;
12
+ };
13
+ /** The box tracker's graph at `url`, read through its `/query` and marked
14
+ * through its `/apply`, in this graph's vocabulary, as the run `via` names in
15
+ * `x-via`, which that graph's door signs its marks with (@yaks/api `asking`).
16
+ * A reference resolves the way that graph resolves one in a query. */ export declare let wire: (url: string, vocab: Graph['vocab'], go?: typeof fetch, via?: string) => Store;
17
+ /** Bug reads preserve caller ordering, defaulting to worst first. */ export declare let bugs: (g: Pick<Store, 'read'>, query: Query, count?: number) => Bundle[] | Promise<Bundle[]>;
18
+ /** A bug read: the bug, a page of its retained occurrences, newest first,
19
+ * and the requests they ran during; how many occurrences it retains; and,
20
+ * where older ones remain, the last one read, which `after` reads past. */ export type Shown = {
21
+ rows: Bundle[];
22
+ occurrences: number;
23
+ next?: string;
24
+ };
25
+ /** A bug and its `size` newest retained occurrences past the one `cursor`
26
+ * names, at most 100, with no copies written locally. */ export declare let bug: (g: Store, input: string, size?: number, cursor?: string) => Promise<Shown>;
27
+ /** The tools' options: the tracker's remote, the store a call naming no
28
+ * source reads and marks (`box` unless said), the box tracker's graph where
29
+ * this one holds no bugs, and the checkout whose commits a resolution names,
30
+ * where a short sha is resolved through the host's `commits` function. */ export type ToolOptions = Options & {
31
+ source?: 'box' | 'yaks.app';
32
+ /** the base URL of the box tracker's graph, such as
33
+ * `http://127.0.0.1:5175`; without it the box is this graph */ box?: string;
34
+ commits?: (sha: string) => Promise<string[]>;
35
+ };
36
+ export declare let runs: (host?: {
37
+ fetch?: typeof fetch;
38
+ }, options?: ToolOptions, go?: typeof fetch) => Runs;
39
+ //# sourceMappingURL=tools.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tools.d.ts","sources":["../tools.ts"],"names":[],"mappings":"AAEA,SAAS,KAAK,MAAM,EAAE,KAAK,KAAK,2BAAyC;AAIzE,cAAc,IAAI,iCAAsC;AACxD,SAaE,KAAK,KAAK,2BAGmB;AAI/B,SAAS,KAAK,OAAO,sBAA2B;AAOhD;kCACkC,QAC7B,QAAQ,KAAK,OAAO,UAAU,QAAQ,SAAS;EAClD;yBACuB,GACvB,SAAS,GAAG,UAAU,QAAQ,MAAM;EACpC,OAAO,MAAM;EACb;0BACwB,GACxB,QAAQ,SAAS,QAAQ,cAAc,QAAQ,IAAI;;AAGrD;;;oEAGoE,GACpE,OAAO,YAAI,OACT,KAAK,MAAM,EACX,OAAO,MAAM,UACb,YAAW,OACX,MAAM,MAAM,KACX,MAoDF;AAaD,mEAAmE,GACnE,OAAO,YAAI,OACT,GAAG,KAAK,OAAO,SACf,OAAO,OACP,mBACC,WAAW,QAAQ,UAOlB;AAEJ;;yEAEyE,GACzE,YAAY;EAAU,MAAM;EAAU,aAAa,MAAM;EAAE,OAAO,MAAM;;AAExE;uDACuD,GACvD,OAAO,YAAI,MACT,GAAG,OACH,OAAO,MAAM,EACb,eACA,SAAS,MAAM,KACd,QAAQ,OAwBV;AAaD;;;wEAGwE,GACxE,YAAY,cAAc;EACxB,SAAS,QAAQ;EACjB;+DAC6D,GAC7D,MAAM,MAAM;EACZ,WAAW,KAAK,MAAM,KAAK,QAAQ,MAAM;;AAG3C,OAAO,YAAI,OACT;EAAQ,eAAe;GACvB,UAAS,aACT,YAAW,UACV,KAmNF"}
@@ -0,0 +1,25 @@
1
+ /** Bounded trace admission. Only a complete, value-free capture has a bounded
2
+ * write plan; arbitrary reporter bundles keep the error intake contract. */ import type { Bundle } from "@yaks/graph";
3
+ export declare let TRACE_CEILING: number;
4
+ export declare let TRACE_ROW_BOUND: number;
5
+ export declare let TRACE_RESERVATION_WRITES: number;
6
+ export declare let TRACE_MAX_BUNDLES: number;
7
+ export type TraceBatch = {
8
+ scope: string;
9
+ rows: Bundle[];
10
+ cost: number;
11
+ };
12
+ /** Refuse to admit a partial/chunked tree. This bounds reference spines and
13
+ * prevents a ceiling drop halfway through a capture from storing a fake tree. */ export declare let traceBatch: (body: unknown) => TraceBatch | undefined;
14
+ export type TraceReservation = {
15
+ reserved: number;
16
+ until: number | null;
17
+ };
18
+ export type TraceBudget = {
19
+ slots: TraceReservation[];
20
+ };
21
+ /** Parse durable reservations fail-closed; corrupt metadata never reopens a
22
+ * budget or turns rejected tracing into a recursively reported tracker error. */ export declare let traceBudget: (text: string | undefined) => TraceBudget | undefined;
23
+ /** A pending reservation never expires after a crash. A completed one stays
24
+ * charged for a full hour from completion, including across clock rollback. */ export declare let reserveTrace: (held: TraceBudget | undefined, now: number, cost: number) => TraceBudget | undefined;
25
+ //# sourceMappingURL=trace-intake.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trace-intake.d.ts","sources":["../trace-intake.ts"],"names":[],"mappings":"AAAA;0EAC0E,GAC1E,cAAc,MAAM,2BAAgC;AAEpD,OAAO,YAAI,sBAAsB;AAGjC,OAAO,YAAI,wBAAoB;AAE/B,OAAO,YAAI,iCAA4B;AACvC,OAAO,YAAI,0BAAuB;AAElC,YAAY;EAAe,OAAO,MAAM;EAAE,MAAM;EAAU,MAAM,MAAM;;AAmBtE;+EAC+E,GAC/E,OAAO,YAAI,aAAc,MAAM,OAAO,KAAG,aAAa,SAAS,CAiE9D;AAED,YAAY;EAAqB,UAAU,MAAM;EAAE,OAAO,MAAM,GAAG,IAAI;;AACvE,YAAY;EAAgB,OAAO;;AACnC;+EAC+E,GAC/E,OAAO,YAAI,cACT,MAAM,MAAM,GAAG,SAAS,KACvB,cAAc,SAAS,CA2BzB;AACD;6EAC6E,GAC7E,OAAO,YAAI,eACT,MAAM,cAAc,SAAS,EAC7B,KAAK,MAAM,EACX,MAAM,MAAM,KACX,cAAc,SAAS,CAOzB"}
@@ -0,0 +1,11 @@
1
+ import { openBugs } from "./reading.js";
2
+ export { occurrences, openBugs, relatedTraces } from "./reading.js";
3
+ /** The page a browsing app's sidebar offers: the open bugs, worst first. */ export declare let destinations: readonly [{
4
+ readonly key: string;
5
+ readonly name: string;
6
+ readonly icon: string;
7
+ readonly query: any;
8
+ }];
9
+ /** Draws a bug or an error by name. */ export declare let views: import("@yaks/render").Registry;
10
+ export declare let inspectViews: () => Promise<import("@yaks/inspect").View[]>;
11
+ //# sourceMappingURL=views.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"views.d.ts","sources":["../views.ts"],"names":[],"mappings":"AAaA,SAAkB,QAAQ,uBAAkD;AAG5E,SAAS,WAAW,EAAE,QAAQ,EAAE,aAAa,uBAAsB;AAEnE,0EAA0E,GAC1E,OAAO,YAAI;aACP;aAAa;aAAc;aAAa;KAC3C;AA+MD,qCAAqC,GACrC,OAAO,YAAI,mCAAyC,SAqBlD;AAEF,OAAO,YAAI,oBAAmB,qCAA2C,QACrB"}
@@ -0,0 +1,9 @@
1
+ export { computed } from "./people.js";
2
+ import type { Derived } from "@yaks/sql";
3
+ import { type VocabDoc } from "@yaks/vocab/runtime";
4
+ export declare let trackerDoc: VocabDoc;
5
+ export declare let bugDoc: VocabDoc;
6
+ export declare let derived: () => Derived;
7
+ export declare let description: string;
8
+ export declare let docs: VocabDoc[];
9
+ //# sourceMappingURL=vocab.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vocab.d.ts","sources":["../vocab.ts"],"names":[],"mappings":"AAEA,SAAS,QAAQ,sBAAqB;AAEtC,cAAc,OAAO,yBAA8B;AACnD,SAAe,KAAK,QAAQ,mCAAwC;AAIpE,OAAO,YAAI,YAAY,SAA0B;AACjD,OAAO,YAAI,QAAQ,SAAmD;AACtE,OAAO,YAAI,eAAc,QAAiB;AAC1C,OAAO,YAAI,aAAa,MAAM,CAAuB;AACrD,OAAO,YAAI,MAAM,WAAyB"}
package/box.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "db": "tracker.db",
3
+ "tracker": {
4
+ "spool": "tracker-spool"
5
+ },
6
+ "plugins": [
7
+ "@yaks/kernel",
8
+ "@yaks/provenance",
9
+ "@yaks/id",
10
+ "@yaks/archetype",
11
+ "@yaks/doc",
12
+ "@yaks/tools",
13
+ {
14
+ "use": "@yaks/api",
15
+ "with": { "who": "http://127.0.0.1:5173" }
16
+ },
17
+ "@yaks/process",
18
+ "@yaks/effects",
19
+ "@yaks/mail",
20
+ {
21
+ "use": "@yaks/tracker",
22
+ "with": {
23
+ "code": {
24
+ "cwd": "/home/yaks/code/tasks",
25
+ "url": "http://127.0.0.1:5173",
26
+ "origins": [
27
+ "https://tasks.yak.sh",
28
+ "http://127.0.0.1:5173"
29
+ ]
30
+ }
31
+ }
32
+ },
33
+ "@yaks/fts",
34
+ "@yaks/ui",
35
+ {
36
+ "use": "@yaks/web",
37
+ "with": {
38
+ "home": {
39
+ "title": "Open bugs \u00b7 worst first",
40
+ "query": ".bug.status=open * .order=-bug.hits"
41
+ }
42
+ }
43
+ },
44
+ "@yaks/browse",
45
+ "@yaks/inspect"
46
+ ],
47
+ "numbers": true,
48
+ "port": 5175,
49
+ "name": "tracker",
50
+ "hostname": "0.0.0.0"
51
+ }
package/brief.js ADDED
@@ -0,0 +1,86 @@
1
+ // How a long thing reads in a line. An error's message, a stack's file and a
2
+ // commit are stored whole; a person scanning a list or a page reads them
3
+ // briefly, with the whole one click away. Nothing here is stored.
4
+ // deno-lint-ignore no-control-regex -- terminal colour escapes in messages.
5
+ let ANSI = /\x1b\[[0-9;]*[A-Za-z]/g;
6
+ let UUID = /\b([0-9a-f]{8})-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\b/gi;
7
+ let URL_ = /\b([a-z][a-z0-9+.-]*:\/\/[^\s()'"<>]+)/gi;
8
+ let DIGITS = /\b(\d{4})\d{8,}\b/g;
9
+ /// place('file:///home/yaks/code/tasks/packages/code/source.ts') -> 'packages/code/source.ts'
10
+ /// place('ext:deno_fetch/26_fetch.js') -> 'ext:deno_fetch/26_fetch.js'
11
+ /// place('https://jsr.io/@std/assert/1.0.0/mod.ts') -> 'assert/1.0.0/mod.ts'
12
+ /** A file as a person finds it in a project: its last three segments, the
13
+ * scheme and the checkout around them left off. */ export let place = (file)=>{
14
+ let path = file.replace(/^file:\/\//, '').replace(/^[a-z]+:\/\/[^/]+/i, '');
15
+ let parts = path.split('/').filter(Boolean);
16
+ return parts.length > 3 ? parts.slice(-3).join('/') : file;
17
+ };
18
+ /// link('http://127.0.0.1:5173/query?q=.entity.eid%3D99bf28a8') -> 'http://127.0.0.1:5173/query?…'
19
+ /// link('file:///home/yaks/code/tasks/packages/cli/args.ts') -> 'packages/cli/args.ts'
20
+ /** An address in a message: a file by its place, a URL without its query. */ export let link = (url)=>url.startsWith('file://') ? place(url) : url.replace(/[?#].*$/, '?…');
21
+ /// headline('TypeError: error sending request for url (http://127.0.0.1:5173/query?q=a%2Cb): refused') -> 'TypeError: error sending request for url (http://127.0.0.1:5173/query?…): refused'
22
+ /// headline('Error: /mcp said 500 (request 8340c228-dc11-464e-a9fe-1655ef354a15)') -> 'Error: /mcp said 500 (request 8340c228…)'
23
+ /// headline("Error: Unknown export './unknown'.\n Package exports:\n * .") -> "Error: Unknown export './unknown'."
24
+ /// headline('\u001b[31mError\u001b[0m: red') -> 'Error: red'
25
+ /// headline('') -> ''
26
+ /** A message as one line a person reads: its first line, terminal colours
27
+ * left out, an address without its query, an id or a long number cut to its
28
+ * start. The message it stands for is unchanged. */ export let headline = (text)=>(text.replace(ANSI, '').split('\n').find((l)=>l.trim()) ?? '').replace(URL_, (url)=>link(url)).replace(UUID, '$1…').replace(DIGITS, '$1…').replace(/\s+/g, ' ').trim();
29
+ /// thrown('TypeError: no row') -> { type: 'TypeError', message: 'no row' }
30
+ /// thrown('HTTP request failed') -> { message: 'HTTP request failed' }
31
+ /// thrown('Error: /mcp said 500') -> { type: 'Error', message: '/mcp said 500' }
32
+ /** A title split where its thrown value's type ends, as the tracker writes
33
+ * it (`type: value`). A sentence without one is all message. */ export let thrown = (title)=>{
34
+ let m = /^([A-Za-z_$][\w$.]{0,48}): ([^]*)$/.exec(title);
35
+ return m ? {
36
+ type: m[1],
37
+ message: m[2]
38
+ } : {
39
+ message: title
40
+ };
41
+ };
42
+ /// sha('9917d09d30a68730b83661652bdcaecc38670809') -> '9917d09'
43
+ /// sha('v1.2') -> 'v1.2'
44
+ /** A commit as people say it: seven characters of its sha. */ export let sha = (commit)=>/^[0-9a-f]{40}$/i.test(commit) ? commit.slice(0, 7) : commit;
45
+ /// spot('file:///home/yaks/code/tasks/packages/code/source.ts:56 Object.get') -> { place: 'packages/code/source.ts:56', fn: 'Object.get', file: 'file:///home/yaks/code/tasks/packages/code/source.ts:56' }
46
+ /// spot('ext:deno_web/03_abort_signal.js:102') -> { place: 'ext:deno_web/03_abort_signal.js:102', file: 'ext:deno_web/03_abort_signal.js:102' }
47
+ /** A stack's text frame as `bug.spot` keeps it (`file:line function`): where
48
+ * it is, briefly, and what ran there. */ export let spot = (text)=>{
49
+ let [file, ...rest] = text.split(' ');
50
+ let m = /^(.*?)((?::\d+)*)$/.exec(file);
51
+ let fn = rest.join(' ');
52
+ return {
53
+ place: place(m[1]) + m[2],
54
+ ...fn ? {
55
+ fn
56
+ } : {},
57
+ file
58
+ };
59
+ };
60
+ /** A moment to the second, in the reader's own clock and words. */ export let moment = (at)=>new Date(at).toLocaleString('en-US', {
61
+ month: 'short',
62
+ day: 'numeric',
63
+ hour: '2-digit',
64
+ minute: '2-digit',
65
+ second: '2-digit',
66
+ hour12: false
67
+ });
68
+ // Made once, at the first number: a number's `toLocaleString('en-US')` builds
69
+ // a formatter on every call, which a letter that counts a few things paid for
70
+ // each time, and making one loads the locale's data (about 19 ms), which every
71
+ // command importing this module paid at its start.
72
+ let digits;
73
+ /// figure(1200) -> '1,200'
74
+ /** A number with its thousands marked, as people read it. */ export let figure = (n)=>(digits ??= new Intl.NumberFormat('en-US')).format(n);
75
+ /// count(1, 'hit') -> '1 hit'
76
+ /// count(1200, 'hit') -> '1,200 hits'
77
+ /** A count and its noun, plural past one. */ export let count = (n, noun)=>`${figure(n)} ${noun}${n == 1 ? '' : 's'}`;
78
+ /// whom(2, 'person') -> '2 people'
79
+ /// whom(1, 'person') -> '1 person'
80
+ /// whom(0, 'person') -> "a person's space, no signed-in person recorded"
81
+ /// whom(3, 'test') -> 'test accounts only'
82
+ /// whom(0, null) -> 'no person recorded'
83
+ /** Whom a bug reached, from the people its occurrences name and the kind of
84
+ * account they reached (`bug.people`, `bug.account`): a person's failure
85
+ * reads apart from a probe's at a glance. */ export let whom = (people, account)=>account == 'test' ? 'test accounts only' : people ? people == 1 ? '1 person' : `${figure(people)} people` : account == 'person' ? "a person's space, no signed-in person recorded" : 'no person recorded';
86
+ //# sourceMappingURL=brief.js.map
package/brief.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"brief.js","sources":["./brief.ts"],"names":[],"mappings":"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"}
package/brief.ts ADDED
@@ -0,0 +1,120 @@
1
+ // How a long thing reads in a line. An error's message, a stack's file and a
2
+ // commit are stored whole; a person scanning a list or a page reads them
3
+ // briefly, with the whole one click away. Nothing here is stored.
4
+
5
+ // deno-lint-ignore no-control-regex -- terminal colour escapes in messages.
6
+ let ANSI = /\x1b\[[0-9;]*[A-Za-z]/g
7
+ let UUID =
8
+ /\b([0-9a-f]{8})-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\b/gi
9
+ let URL_ = /\b([a-z][a-z0-9+.-]*:\/\/[^\s()'"<>]+)/gi
10
+ let DIGITS = /\b(\d{4})\d{8,}\b/g
11
+
12
+ /// place('file:///home/yaks/code/tasks/packages/code/source.ts') -> 'packages/code/source.ts'
13
+ /// place('ext:deno_fetch/26_fetch.js') -> 'ext:deno_fetch/26_fetch.js'
14
+ /// place('https://jsr.io/@std/assert/1.0.0/mod.ts') -> 'assert/1.0.0/mod.ts'
15
+ /** A file as a person finds it in a project: its last three segments, the
16
+ * scheme and the checkout around them left off. */
17
+ export let place = (file: string): string => {
18
+ let path = file.replace(/^file:\/\//, '').replace(/^[a-z]+:\/\/[^/]+/i, '')
19
+ let parts = path.split('/').filter(Boolean)
20
+ return parts.length > 3 ? parts.slice(-3).join('/') : file
21
+ }
22
+
23
+ /// link('http://127.0.0.1:5173/query?q=.entity.eid%3D99bf28a8') -> 'http://127.0.0.1:5173/query?…'
24
+ /// link('file:///home/yaks/code/tasks/packages/cli/args.ts') -> 'packages/cli/args.ts'
25
+ /** An address in a message: a file by its place, a URL without its query. */
26
+ export let link = (url: string): string =>
27
+ url.startsWith('file://') ? place(url) : url.replace(/[?#].*$/, '?…')
28
+
29
+ /// headline('TypeError: error sending request for url (http://127.0.0.1:5173/query?q=a%2Cb): refused') -> 'TypeError: error sending request for url (http://127.0.0.1:5173/query?…): refused'
30
+ /// headline('Error: /mcp said 500 (request 8340c228-dc11-464e-a9fe-1655ef354a15)') -> 'Error: /mcp said 500 (request 8340c228…)'
31
+ /// headline("Error: Unknown export './unknown'.\n Package exports:\n * .") -> "Error: Unknown export './unknown'."
32
+ /// headline('\u001b[31mError\u001b[0m: red') -> 'Error: red'
33
+ /// headline('') -> ''
34
+ /** A message as one line a person reads: its first line, terminal colours
35
+ * left out, an address without its query, an id or a long number cut to its
36
+ * start. The message it stands for is unchanged. */
37
+ export let headline = (text: string): string =>
38
+ (text.replace(ANSI, '').split('\n').find((l) => l.trim()) ?? '')
39
+ .replace(URL_, (url) => link(url))
40
+ .replace(UUID, '$1…')
41
+ .replace(DIGITS, '$1…')
42
+ .replace(/\s+/g, ' ')
43
+ .trim()
44
+
45
+ /// thrown('TypeError: no row') -> { type: 'TypeError', message: 'no row' }
46
+ /// thrown('HTTP request failed') -> { message: 'HTTP request failed' }
47
+ /// thrown('Error: /mcp said 500') -> { type: 'Error', message: '/mcp said 500' }
48
+ /** A title split where its thrown value's type ends, as the tracker writes
49
+ * it (`type: value`). A sentence without one is all message. */
50
+ export let thrown = (title: string): { type?: string; message: string } => {
51
+ let m = /^([A-Za-z_$][\w$.]{0,48}): ([^]*)$/.exec(title)
52
+ return m ? { type: m[1], message: m[2] } : { message: title }
53
+ }
54
+
55
+ /// sha('9917d09d30a68730b83661652bdcaecc38670809') -> '9917d09'
56
+ /// sha('v1.2') -> 'v1.2'
57
+ /** A commit as people say it: seven characters of its sha. */
58
+ export let sha = (commit: string): string =>
59
+ /^[0-9a-f]{40}$/i.test(commit) ? commit.slice(0, 7) : commit
60
+
61
+ /// spot('file:///home/yaks/code/tasks/packages/code/source.ts:56 Object.get') -> { place: 'packages/code/source.ts:56', fn: 'Object.get', file: 'file:///home/yaks/code/tasks/packages/code/source.ts:56' }
62
+ /// spot('ext:deno_web/03_abort_signal.js:102') -> { place: 'ext:deno_web/03_abort_signal.js:102', file: 'ext:deno_web/03_abort_signal.js:102' }
63
+ /** A stack's text frame as `bug.spot` keeps it (`file:line function`): where
64
+ * it is, briefly, and what ran there. */
65
+ export let spot = (
66
+ text: string,
67
+ ): { place: string; fn?: string; file: string } => {
68
+ let [file, ...rest] = text.split(' ')
69
+ let m = /^(.*?)((?::\d+)*)$/.exec(file)!
70
+ let fn = rest.join(' ')
71
+ return { place: place(m[1]) + m[2], ...fn ? { fn } : {}, file }
72
+ }
73
+
74
+ /** A moment to the second, in the reader's own clock and words. */
75
+ export let moment = (at: string): string =>
76
+ new Date(at).toLocaleString('en-US', {
77
+ month: 'short',
78
+ day: 'numeric',
79
+ hour: '2-digit',
80
+ minute: '2-digit',
81
+ second: '2-digit',
82
+ hour12: false,
83
+ })
84
+
85
+ // Made once, at the first number: a number's `toLocaleString('en-US')` builds
86
+ // a formatter on every call, which a letter that counts a few things paid for
87
+ // each time, and making one loads the locale's data (about 19 ms), which every
88
+ // command importing this module paid at its start.
89
+ let digits: Intl.NumberFormat | undefined
90
+
91
+ /// figure(1200) -> '1,200'
92
+ /** A number with its thousands marked, as people read it. */
93
+ export let figure = (n: number): string =>
94
+ (digits ??= new Intl.NumberFormat('en-US')).format(n)
95
+
96
+ /// count(1, 'hit') -> '1 hit'
97
+ /// count(1200, 'hit') -> '1,200 hits'
98
+ /** A count and its noun, plural past one. */
99
+ export let count = (n: number, noun: string): string =>
100
+ `${figure(n)} ${noun}${n == 1 ? '' : 's'}`
101
+
102
+ /// whom(2, 'person') -> '2 people'
103
+ /// whom(1, 'person') -> '1 person'
104
+ /// whom(0, 'person') -> "a person's space, no signed-in person recorded"
105
+ /// whom(3, 'test') -> 'test accounts only'
106
+ /// whom(0, null) -> 'no person recorded'
107
+ /** Whom a bug reached, from the people its occurrences name and the kind of
108
+ * account they reached (`bug.people`, `bug.account`): a person's failure
109
+ * reads apart from a probe's at a glance. */
110
+ export let whom = (
111
+ people: number,
112
+ account: string | null | undefined,
113
+ ): string =>
114
+ account == 'test'
115
+ ? 'test accounts only'
116
+ : people
117
+ ? people == 1 ? '1 person' : `${figure(people)} people`
118
+ : account == 'person'
119
+ ? "a person's space, no signed-in person recorded"
120
+ : 'no person recorded'
package/changes.js ADDED
@@ -0,0 +1,57 @@
1
+ // All scope polls share one conditional read. A version is acknowledged by a
2
+ // poll only after its bug read succeeds, so a failed read remains due.
3
+ import { system } from "@yaks/fp";
4
+ import { platform, Unavailable } from "./remote.js";
5
+ export let changes = (doors, { every = 30_000, clock = system } = {})=>{
6
+ let tag, next = -Infinity;
7
+ let scopes = new Map();
8
+ let pending;
9
+ let running = false;
10
+ let stop = new AbortController();
11
+ let read = async ()=>{
12
+ if (!doors.changes) throw Error('Tracker has no change feed');
13
+ let got = await doors.changes(tag, stop.signal);
14
+ if (!got.ok) {
15
+ throw got.status >= 500 ? new Unavailable(got.error) : Error(got.error);
16
+ }
17
+ if (got.unchanged) return;
18
+ let legacy = got.value;
19
+ if (!got.tag && Array.isArray(legacy?.scopes) && legacy.scopes.every((scope)=>typeof scope == 'string')) {
20
+ scopes = new Map([
21
+ platform,
22
+ ...legacy.scopes
23
+ ].map((scope)=>[
24
+ scope,
25
+ undefined
26
+ ]));
27
+ tag = undefined;
28
+ return;
29
+ }
30
+ let value = got.value;
31
+ if (!got.tag || !Array.isArray(value?.scopes) || value.scopes.some((s)=>typeof s.scope != 'string' || typeof s.tag != 'string')) throw Error('Tracker returned an invalid change feed');
32
+ for (let scope of value.scopes)scopes.set(scope.scope, scope.tag);
33
+ tag = got.tag;
34
+ };
35
+ let fresh = ()=>{
36
+ if (!running && clock.now() >= next) {
37
+ next = clock.now() + every;
38
+ running = true;
39
+ pending = read().finally(()=>running = false);
40
+ }
41
+ return pending;
42
+ };
43
+ return {
44
+ version: async (scope = platform)=>{
45
+ await fresh();
46
+ return scopes.get(scope);
47
+ },
48
+ scopes: async ()=>{
49
+ await fresh();
50
+ return [
51
+ ...scopes.keys()
52
+ ].filter((scope)=>scope != platform);
53
+ },
54
+ close: ()=>stop.abort()
55
+ };
56
+ };
57
+ //# sourceMappingURL=changes.js.map
package/changes.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"changes.js","sources":["./changes.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,uEAAuE;AAEvE,SAAS,MAAM,wBAA6B;AAE5C,SAAS,QAAQ,EAAE,WAAW,sBAAqB;AAQnD,OAAO,IAAI,UAAU,CACnB,OACA,EAAE,QAAQ,MAAM,EAAE,QAAQ,MAAM,EAAqC,GAAG,CAAC,CAAC;EAE1E,IAAI,KAAyB,OAAO,CAAC;EACrC,IAAI,SAAS,IAAI;EACjB,IAAI;EACJ,IAAI,UAAU;EACd,IAAI,OAAO,IAAI;EACf,IAAI,OAAO;IACT,IAAI,CAAC,MAAM,OAAO,EAAE,MAAM,MAAM;IAChC,IAAI,MAAM,MAAM,MAAM,OAAO,CAAC,KAAK,KAAK,MAAM;IAC9C,IAAI,CAAC,IAAI,EAAE,EAAE;MACX,MAAM,IAAI,MAAM,IAAI,MAAM,IAAI,YAAY,IAAI,KAAK,IAAI,MAAM,IAAI,KAAK;IACxE;IACA,IAAI,IAAI,SAAS,EAAE;IACnB,IAAI,SAAS,IAAI,KAAK;IACtB,IACE,CAAC,IAAI,GAAG,IAAI,MAAM,OAAO,CAAC,QAAQ,WAClC,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,QAAU,OAAO,SAAS,WAC/C;MACA,SAAS,IAAI,IACX;QAAC;WAAa,OAAO,MAAM;OAAC,CAAC,GAAG,CAAC,CAAC,QAAU;UAAC;UAAO;SAAU;MAEhE,MAAM;MACN;IACF;IACA,IAAI,QAAQ,IAAI,KAAK;IACrB,IACE,CAAC,IAAI,GAAG,IAAI,CAAC,MAAM,OAAO,CAAC,OAAO,WAClC,MAAM,MAAM,CAAC,IAAI,CAAC,CAAC,IACjB,OAAO,EAAE,KAAK,IAAI,YAAY,OAAO,EAAE,GAAG,IAAI,WAEhD,MAAM,MAAM;IACd,KAAK,IAAI,SAAS,MAAM,MAAM,CAAE,OAAO,GAAG,CAAC,MAAM,KAAK,EAAE,MAAM,GAAG;IACjE,MAAM,IAAI,GAAG;EACf;EACA,IAAI,QAAQ;IACV,IAAI,CAAC,WAAW,MAAM,GAAG,MAAM,MAAM;MACnC,OAAO,MAAM,GAAG,KAAK;MACrB,UAAU;MACV,UAAU,OAAO,OAAO,CAAC,IAAM,UAAU;IAC3C;IACA,OAAO;EACT;EACA,OAAO;IACL,SAAS,OAAO,QAAQ,QAAQ;MAC9B,MAAM;MACN,OAAO,OAAO,GAAG,CAAC;IACpB;IACA,QAAQ;MACN,MAAM;MACN,OAAO;WAAI,OAAO,IAAI;OAAG,CAAC,MAAM,CAAC,CAAC,QAAU,SAAS;IACvD;IACA,OAAO,IAAM,KAAK,KAAK;EACzB;AACF,EAAC"}
package/changes.ts ADDED
@@ -0,0 +1,70 @@
1
+ // All scope polls share one conditional read. A version is acknowledged by a
2
+ // poll only after its bug read succeeds, so a failed read remains due.
3
+ import type { Clock } from '@yaks/fp'
4
+ import { system } from '@yaks/fp'
5
+ import type { Doors } from './poll.ts'
6
+ import { platform, Unavailable } from './remote.js'
7
+
8
+ export type Changes = {
9
+ version: (scope?: string) => Promise<string | undefined>
10
+ scopes: () => Promise<string[]>
11
+ close: () => void
12
+ }
13
+
14
+ export let changes = (
15
+ doors: Doors,
16
+ { every = 30_000, clock = system }: { every?: number; clock?: Clock } = {},
17
+ ): Changes => {
18
+ let tag: string | undefined, next = -Infinity
19
+ let scopes = new Map<string, string | undefined>()
20
+ let pending: Promise<void>
21
+ let running = false
22
+ let stop = new AbortController()
23
+ let read = async () => {
24
+ if (!doors.changes) throw Error('Tracker has no change feed')
25
+ let got = await doors.changes(tag, stop.signal)
26
+ if (!got.ok) {
27
+ throw got.status >= 500 ? new Unavailable(got.error) : Error(got.error)
28
+ }
29
+ if (got.unchanged) return
30
+ let legacy = got.value as { scopes?: unknown }
31
+ if (
32
+ !got.tag && Array.isArray(legacy?.scopes) &&
33
+ legacy.scopes.every((scope) => typeof scope == 'string')
34
+ ) {
35
+ scopes = new Map(
36
+ [platform, ...legacy.scopes].map((scope) => [scope, undefined]),
37
+ )
38
+ tag = undefined
39
+ return
40
+ }
41
+ let value = got.value as { scopes?: { scope: string; tag: string }[] }
42
+ if (
43
+ !got.tag || !Array.isArray(value?.scopes) ||
44
+ value.scopes.some((s) =>
45
+ typeof s.scope != 'string' || typeof s.tag != 'string'
46
+ )
47
+ ) throw Error('Tracker returned an invalid change feed')
48
+ for (let scope of value.scopes) scopes.set(scope.scope, scope.tag)
49
+ tag = got.tag
50
+ }
51
+ let fresh = () => {
52
+ if (!running && clock.now() >= next) {
53
+ next = clock.now() + every
54
+ running = true
55
+ pending = read().finally(() => running = false)
56
+ }
57
+ return pending
58
+ }
59
+ return {
60
+ version: async (scope = platform) => {
61
+ await fresh()
62
+ return scopes.get(scope)
63
+ },
64
+ scopes: async () => {
65
+ await fresh()
66
+ return [...scopes.keys()].filter((scope) => scope != platform)
67
+ },
68
+ close: () => stop.abort(),
69
+ }
70
+ }