fwdloop 0.26.2 → 0.28.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 (73) hide show
  1. package/bin/fwdloop +46 -7
  2. package/package.json +2 -2
  3. package/src/authoring.js +21 -1
  4. package/src/canrun.js +23 -0
  5. package/src/config.js +18 -0
  6. package/src/declaration.js +129 -3
  7. package/src/drafter.js +38 -10
  8. package/src/flow.js +2 -1
  9. package/src/launcher.js +4 -2
  10. package/src/learnstore.js +3 -2
  11. package/src/mcp-checks.js +50 -0
  12. package/src/mcp-pick.js +33 -0
  13. package/src/mcp-sources.js +84 -0
  14. package/src/mcp-use.js +54 -0
  15. package/src/natural.js +23 -0
  16. package/src/panel/author.js +17 -1
  17. package/src/panel/authorcard.js +35 -0
  18. package/src/panel/authorflows.js +15 -6
  19. package/src/panel/authorstart.js +10 -6
  20. package/src/panel/authortrigger.js +263 -82
  21. package/src/panel/data.js +127 -9
  22. package/src/panel/index.html +945 -94
  23. package/src/panel/jobgrid.js +127 -0
  24. package/src/panel/scheduler.js +48 -6
  25. package/src/panel/server.js +33 -8
  26. package/src/panel/settings.js +119 -4
  27. package/src/panel/tickets.js +118 -0
  28. package/src/primitives.js +34 -5
  29. package/src/runner.js +129 -15
  30. package/src/schedule.js +5 -0
  31. package/src/summary-words.js +27 -7
  32. package/src/ticket-draft.js +85 -0
  33. package/src/ticket-labels.js +75 -0
  34. package/src/ticket-mcp.js +89 -0
  35. package/src/ticket-next.js +33 -0
  36. package/src/ticket-shape.js +33 -0
  37. package/src/trigger-clock.js +4 -4
  38. package/src/trigger-files.js +4 -4
  39. package/src/trigger-line.js +2 -1
  40. package/src/trigger-tickets.js +238 -0
  41. package/types/authoring.d.ts +5 -1
  42. package/types/canrun.d.ts +7 -0
  43. package/types/config.d.ts +6 -0
  44. package/types/declaration.d.ts +8 -0
  45. package/types/drafter.d.ts +552 -21
  46. package/types/mcp-checks.d.ts +8 -0
  47. package/types/mcp-pick.d.ts +23 -0
  48. package/types/mcp-sources.d.ts +51 -0
  49. package/types/mcp-use.d.ts +12 -0
  50. package/types/natural.d.ts +2 -0
  51. package/types/panel/author.d.ts +44 -0
  52. package/types/panel/authorcard.d.ts +11 -0
  53. package/types/panel/authorflows.d.ts +11 -1
  54. package/types/panel/authorstart.d.ts +3 -1
  55. package/types/panel/authortrigger.d.ts +83 -7
  56. package/types/panel/data.d.ts +78 -5
  57. package/types/panel/jobgrid.d.ts +109 -0
  58. package/types/panel/scheduler.d.ts +7 -2
  59. package/types/panel/server.d.ts +13 -2
  60. package/types/panel/settings.d.ts +3 -2
  61. package/types/panel/tickets.d.ts +103 -0
  62. package/types/primitives.d.ts +15 -2
  63. package/types/runner.d.ts +133 -75
  64. package/types/summary-words.d.ts +24 -4
  65. package/types/ticket-draft.d.ts +104 -0
  66. package/types/ticket-labels.d.ts +42 -0
  67. package/types/ticket-mcp.d.ts +57 -0
  68. package/types/ticket-next.d.ts +23 -0
  69. package/types/ticket-shape.d.ts +30 -0
  70. package/types/trigger-clock.d.ts +4 -3
  71. package/types/trigger-files.d.ts +3 -1
  72. package/types/trigger-line.d.ts +7 -0
  73. package/types/trigger-tickets.d.ts +105 -0
@@ -0,0 +1,42 @@
1
+ /**
2
+ * One priority value from a ticket's labels: `P0`..`P3`; `unsure` when two different ones are present, or when a label names a priority on another scale
3
+ * (`priority/important-soon`) and no scale value is present; `none` when no label speaks of priority.
4
+ * @param {string[]} labels @returns {string}
5
+ */
6
+ export function priorityOf(labels: string[]): string;
7
+ /**
8
+ * The typed fields of a ticket read through `issue_read`: its JSON. A missing `labels` key means no labels (GitHub omits it, F98). Text that is not a JSON
9
+ * object is `ok:false`: never read as "no labels".
10
+ * @param {string} text @returns {{ok: true, labels: string[], state: string|null, title: string|null}|{ok: false}}
11
+ */
12
+ export function readTicketFields(text: string): {
13
+ ok: true;
14
+ labels: string[];
15
+ state: string | null;
16
+ title: string | null;
17
+ } | {
18
+ ok: false;
19
+ };
20
+ /**
21
+ * M13 piece 7 (9.4): the ONE reader of "the filter was unsure about this ticket", from a run.json input entry: true when its stored verdict ran with an `unsure`
22
+ * reason (also when the ticket was sent with Run it anyway and the filter's own verdict was unsure). Anything else, a torn entry too, is false.
23
+ * @param {any} entry @returns {boolean}
24
+ */
25
+ export function filterUnsure(entry: any): boolean;
26
+ /**
27
+ * @param {{text: string, filter?: {priority?: string[], labels?: string[]}}} a `filter` = the job's signed `ticketFilter` (or absent)
28
+ * @returns {{outcome: 'run', unsure?: string}|{outcome: 'skip', reason: string}}
29
+ */
30
+ export function decideTicket({ text, filter }: {
31
+ text: string;
32
+ filter?: {
33
+ priority?: string[];
34
+ labels?: string[];
35
+ };
36
+ }): {
37
+ outcome: "run";
38
+ unsure?: string;
39
+ } | {
40
+ outcome: "skip";
41
+ reason: string;
42
+ };
@@ -0,0 +1,57 @@
1
+ /**
2
+ * M13 piece 3: the config file a server starts from. An explicit path (a test seam) wins; otherwise the file of the WINNING place for `server` (src/mcp-sources.js,
3
+ * the one decider), or `~/.mcp.json` when no place has it. `remote` true = the winner has no start command (listed, not usable).
4
+ * @param {string} server @param {string} [explicit] @returns {{ file: string, remote: boolean }}
5
+ */
6
+ export function configForServer(server: string, explicit?: string): {
7
+ file: string;
8
+ remote: boolean;
9
+ };
10
+ /**
11
+ * Read ticket `number` of the list at `listUrl` with the job's `issue_read`.
12
+ * @param {{listUrl: string, number: number, mcp: {server: string, tools: string[]}, configPath?: string, timeoutMs?: number}} o
13
+ * @returns {Promise<{ok: true, text: string, url: string, record: {server: string, exposed: string[], missing: Array<{server: string, tool: string}>, calls: Array<{tool: string, owner: string, repo: string, issue_number: number}>}} | {ok: false, error: string}>}
14
+ * `record` is what the run keeps (in its `run.json` input entry): what the server exposed and lacked, and each call made.
15
+ */
16
+ export function readTicketMcp({ listUrl, number, mcp, configPath: explicitConfig, timeoutMs }: {
17
+ listUrl: string;
18
+ number: number;
19
+ mcp: {
20
+ server: string;
21
+ tools: string[];
22
+ };
23
+ configPath?: string;
24
+ timeoutMs?: number;
25
+ }): Promise<{
26
+ ok: true;
27
+ text: string;
28
+ url: string;
29
+ record: {
30
+ server: string;
31
+ exposed: string[];
32
+ missing: Array<{
33
+ server: string;
34
+ tool: string;
35
+ }>;
36
+ calls: Array<{
37
+ tool: string;
38
+ owner: string;
39
+ repo: string;
40
+ issue_number: number;
41
+ }>;
42
+ };
43
+ } | {
44
+ ok: false;
45
+ error: string;
46
+ }>;
47
+ /** M13 item 9.5: the only parent env names an MCP gets (plus its own settings); the one list for every place fwdloop starts an MCP, so no provider key reaches it */
48
+ export const MCP_PASS_ENV: string[];
49
+ export function mcpStartOpts(): {
50
+ passEnv: string[];
51
+ cwd: string;
52
+ };
53
+ export function startRefusal(server: string, e: any): string;
54
+ export function USER_MCP_CONFIG(): string;
55
+ export function remoteRefusal(server: string): string;
56
+ export function firstLine(e: any): string;
57
+ export function isDeviceLogin(text: any): any;
@@ -0,0 +1,23 @@
1
+ /** the ticket numbers this job's runs have read @param {string} flowDir @returns {Set<number>} */
2
+ export function ranTicketNumbers(flowDir: string): Set<number>;
3
+ /**
4
+ * @param {{flowDir: string, listUrl: string, mcp: {server: string, tool: string}, configPath?: string, look?: typeof lookTickets}} o `look` is a test seam
5
+ * @returns {Promise<{ok: true, number: number} | {ok: false, say: string}>}
6
+ */
7
+ export function newestUnrunTicket({ flowDir, listUrl, mcp, configPath, look }: {
8
+ flowDir: string;
9
+ listUrl: string;
10
+ mcp: {
11
+ server: string;
12
+ tool: string;
13
+ };
14
+ configPath?: string;
15
+ look?: typeof lookTickets;
16
+ }): Promise<{
17
+ ok: true;
18
+ number: number;
19
+ } | {
20
+ ok: false;
21
+ say: string;
22
+ }>;
23
+ import { lookTickets } from './trigger-tickets.js';
@@ -0,0 +1,30 @@
1
+ /**
2
+ * The one reader of a ticket list address: its owner and repo and the address of one ticket on it, or the one refusal every caller shows.
3
+ * @param {unknown} listUrl @returns {{ok: true, owner: string, repo: string, ticketUrl: (number: number) => string} | {ok: false, error: string}}
4
+ */
5
+ export function parseTicketList(listUrl: unknown): {
6
+ ok: true;
7
+ owner: string;
8
+ repo: string;
9
+ ticketUrl: (number: number) => string;
10
+ } | {
11
+ ok: false;
12
+ error: string;
13
+ };
14
+ /** The ticket lists a signed job names: role -> address, for every page input whose address has the list shape. @param {{sources?: Array<{role: string, kind?: string, path: string}>}} arbiter @returns {Record<string, string>} */
15
+ export function ticketListsOf(arbiter: {
16
+ sources?: Array<{
17
+ role: string;
18
+ kind?: string;
19
+ path: string;
20
+ }>;
21
+ }): Record<string, string>;
22
+ /** The fields a signed schedule may watch (item 7): typed values the list already carries. */
23
+ export const WATCHABLE: readonly string[];
24
+ /** the shape of a ticket list address: owner and repo are the two groups */
25
+ export const LIST_URL: RegExp;
26
+ /** M13 piece 7 (9.7): the one cap on a ticket number, 10 digits. Every door that takes or reads a ticket number uses `isTicketNumber`. Under 2^53, so a safe JS number. */
27
+ export const TICKET_MAX: 9999999999;
28
+ export function isTicketNumber(n: unknown): n is number;
29
+ /** The words every refusal of a ticket number uses. */
30
+ export const TICKET_NUMBER_WORDS: string;
@@ -22,15 +22,15 @@ export function due(schedule: Schedule, rows: ClockRow[], now: number): Due;
22
22
  export function nextSlot(schedule: Schedule, afterMs: number): number;
23
23
  /** @param {string} file @param {string} [sig] M9 am20: only the rows of that schedule signing (the one schedule ledger carries every signing's rows); absent = every row @returns {ClockRow[]} every row on disk that parses, oldest first; a missing file is no rows; a line a crash tore mid-append is skipped (`appendOnce` starts each append on a fresh line, so it never glues onto the next row). */
24
24
  export function readRows(file: string, sig?: string): ClockRow[];
25
- /** The trigger was set at `now`: no slot before this ever fires. @param {string} file @param {number} now @param {string} [sig] */
26
- export function armTrigger(file: string, now: number, sig?: string): void;
25
+ /** The trigger was set at `now`: no slot before this ever fires. M13 piece 5: `ticketN` = the highest ticket number the first green run read; a ticket schedule's first look baselines only tickets up to it. @param {string} file @param {number} now @param {string} [sig] @param {number} [ticketN] */
26
+ export function armTrigger(file: string, now: number, sig?: string, ticketN?: number): void;
27
27
  /**
28
28
  * Record that the run for this due slot is starting. Call BEFORE starting the run: a crash loses a run, never doubles one.
29
29
  * @param {string} file @param {Due} d the result of `due` with fire true @param {number} now @param {string} [sig]
30
30
  */
31
31
  export function recordFire(file: string, d: Due, now: number, sig?: string): void;
32
32
  /** @typedef {{kind:'daily'|'weekdays', hour:number, minute:number} | {kind:'weekly', day:string, hour:number, minute:number}} Schedule */
33
- /** @typedef {{id:string, kind:'armed'|'fire', at:number, slot?:number, catchUp?:boolean, missed?:number, sig?:string}} ClockRow */
33
+ /** @typedef {{id:string, kind:'armed'|'fire', at:number, slot?:number, catchUp?:boolean, missed?:number, sig?:string, ticketN?:number}} ClockRow */
34
34
  /** @typedef {{fire:boolean, catchUp:boolean, missed:number, slot?:number}} Due */
35
35
  /** A slot seen MORE than this after its set time is a catch-up (M9 am2 item 1). Exactly this late is on time. */
36
36
  export const GRACE_MS: 120000;
@@ -52,6 +52,7 @@ export type ClockRow = {
52
52
  catchUp?: boolean;
53
53
  missed?: number;
54
54
  sig?: string;
55
+ ticketN?: number;
55
56
  };
56
57
  export type Due = {
57
58
  fire: boolean;
@@ -1,5 +1,7 @@
1
1
  /** Every row that parses; a line a crash tore mid-append is skipped (it counts as not written). `appendSeen` starts each append on a fresh line, so a torn line can never glue onto the next row. @param {string} file @param {string} [sig] M9 am20: only the rows of that schedule signing (the one schedule ledger carries every signing's rows); absent = every row @returns {SeenRow[]} */
2
2
  export function readSeen(file: string, sig?: string): SeenRow[];
3
+ /** The ONE appender: write-once by id within a signing (a second row with the same id is not written). Starts on a fresh line when the file does not end in a newline (a torn last line). @param {string} file @param {SeenRow} row @param {string} [sig] stamped on the row @returns {boolean} written */
4
+ export function appendSeen(file: string, row: SeenRow, sig?: string): boolean;
3
5
  /** Arrived rows are never overwritten: the 2nd arrival of a sha (after a drop) gets its own id. @param {string} ledger @param {ToRun & {name?:string}} item @param {number} at the scheduler's clock, never the file's mtime @param {string} [sig] */
4
6
  export function recordArrived(ledger: string, item: ToRun & {
5
7
  name?: string;
@@ -12,7 +14,7 @@ export function recordDropped(ledger: string, item: {
12
14
  id?: string;
13
15
  }, why: "deleted" | "changed" | "schedule-changed" | "carried", at: number, sig?: string): boolean;
14
16
  /**
15
- * The queue: arrived and neither ran nor dropped, oldest arrival first. Identical arrival times: by name, then by sha (deterministic).
17
+ * The queue: arrived and neither ran nor dropped, oldest arrival first. Identical arrival times: by name, then by sha (deterministic); numbers inside a name compare as numbers (`#8` before `#10`).
16
18
  * @param {SeenRow[]} rows @returns {(SeenRow & {path:string})[]}
17
19
  */
18
20
  export function queueOf(rows: SeenRow[]): (SeenRow & {
@@ -49,4 +49,11 @@ export type Trigger = Schedule | {
49
49
  kind: "new-file";
50
50
  role: string;
51
51
  folder: string;
52
+ } | {
53
+ kind: "new-ticket";
54
+ role: string;
55
+ list: string;
56
+ server: string;
57
+ tool: string;
58
+ watch?: string[];
52
59
  };
@@ -0,0 +1,105 @@
1
+ /**
2
+ * Why a ticket changed, in words, only for the watched fields; '' = nothing changed. @param {{state: string, labels: string[]}} prev @param {{state: string, labels: string[]}} cur @param {string[]} watch
3
+ */
4
+ export function reasonFor(prev: {
5
+ state: string;
6
+ labels: string[];
7
+ }, cur: {
8
+ state: string;
9
+ labels: string[];
10
+ }, watch: string[]): string;
11
+ /**
12
+ * One look. `seen` null = the first look after signing (the first page is the starting point, nothing runs). Otherwise newest first with the cursor, stopping at a seen
13
+ * number; with watched fields the walk goes on past it only as far as the oldest tracked ticket, comparing each tracked ticket's watched values with `last`.
14
+ * Every failure is `{ok:false, error}` naming its cause, at $0; none reads as "0 new".
15
+ * M13 piece 5 (F114f): `cut` (first look only) = the highest ticket number the job's first green run read. The first look goes on past a page whose tickets are all above it, so
16
+ * every ticket that came in after that run started is seen; `recordLook` then baselines the ones up to `cut` and lets the rest arrive.
17
+ * @param {{listUrl: string, mcp: {server: string, tool: string}, configPath?: string, seen: Set<number>|null, last: Map<number, {state: string, labels: string[]}>, watch: string[], cut?: number, perPage?: number, timeoutMs?: number}} o
18
+ * @returns {Promise<{ok: true, first: boolean, cut?: number, ignored?: number[], found: Array<{number: number, state: string, labels: string[], createdAt: string|null}>, changed: Array<{number: number, reason: string, state: string, labels: string[]}>, pages: number} | {ok: false, error: string}>}
19
+ */
20
+ export function lookTickets({ listUrl, mcp, configPath: explicitConfig, seen, last, watch, cut, perPage, timeoutMs, }: {
21
+ listUrl: string;
22
+ mcp: {
23
+ server: string;
24
+ tool: string;
25
+ };
26
+ configPath?: string;
27
+ seen: Set<number> | null;
28
+ last: Map<number, {
29
+ state: string;
30
+ labels: string[];
31
+ }>;
32
+ watch: string[];
33
+ cut?: number;
34
+ perPage?: number;
35
+ timeoutMs?: number;
36
+ }): Promise<{
37
+ ok: true;
38
+ first: boolean;
39
+ cut?: number;
40
+ ignored?: number[];
41
+ found: Array<{
42
+ number: number;
43
+ state: string;
44
+ labels: string[];
45
+ createdAt: string | null;
46
+ }>;
47
+ changed: Array<{
48
+ number: number;
49
+ reason: string;
50
+ state: string;
51
+ labels: string[];
52
+ }>;
53
+ pages: number;
54
+ } | {
55
+ ok: false;
56
+ error: string;
57
+ }>;
58
+ /** The numbers a signing has a baseline or an arrived row for. @param {string} ledger @param {string} sig */
59
+ export function seenNumbers(ledger: string, sig: string): Set<any>;
60
+ /** Last-seen watched values per number: the newest baseline/arrived row's. @param {string} ledger @param {string} sig @returns {Map<number, {state: string, labels: string[]}>} */
61
+ export function lastSeen(ledger: string, sig: string): Map<number, {
62
+ state: string;
63
+ labels: string[];
64
+ }>;
65
+ /** Has this signing had its first look (its baseline written)? @param {string} ledger @param {string} sig */
66
+ /**
67
+ * M13 item 9b.3: the cause of the newest look when it could not read, else null. The newest look row decides: an `unreadable` row is the problem until a later look reads
68
+ * (its `looked`, `baseline` or `arrived` row). @param {import('./trigger-files.js').SeenRow[]} rows @returns {{at: number, why: string}|null}
69
+ */
70
+ export function lookProblemOf(rows: import("./trigger-files.js").SeenRow[]): {
71
+ at: number;
72
+ why: string;
73
+ } | null;
74
+ /**
75
+ * Write what a look found, once. First look: a `baseline` row per ticket on the page (never runs). Later: an `arrived` row per new ticket, oldest first (its arrival
76
+ * time is this clock), and one `arrived` row per watched change with its `reason`. A look that could not read writes one `unreadable` row with its cause.
77
+ * @param {string} ledger @param {string} sig @param {Awaited<ReturnType<typeof lookTickets>>} look @param {number} at
78
+ * @returns {{arrived: number[], unreadable: string|null}}
79
+ */
80
+ export function recordLook(ledger: string, sig: string, look: Awaited<ReturnType<typeof lookTickets>>, at: number): {
81
+ arrived: number[];
82
+ unreadable: string | null;
83
+ };
84
+ /**
85
+ * M12 piece 3 (item 9): "Run it anyway" — ONE `arrived` row for a skipped ticket, carrying the person's reason, so the queue starts it as a new arrival on a later tick.
86
+ * Same row shape and id series as a watched change (the count of this number's arrived rows). Nothing is written while this number is still queued (a second click
87
+ * is refused, never a second run). @param {string} ledger @param {string} sig @param {{number: number, reason: string}} a @param {number} at
88
+ * @returns {{ok: true} | {ok: false, say: string}}
89
+ */
90
+ export function recordAnyway(ledger: string, sig: string, a: {
91
+ number: number;
92
+ reason: string;
93
+ }, at: number): {
94
+ ok: true;
95
+ } | {
96
+ ok: false;
97
+ say: string;
98
+ };
99
+ /** A look every 15 minutes, fixed (item 8). */
100
+ export const TICKET_LOOK_MS: number;
101
+ export function watchedOf(i: any): {
102
+ state: string;
103
+ labels: any;
104
+ };
105
+ export function hasBaseline(ledger: any, sig: any): boolean;