fwdloop 0.26.1 → 0.27.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 (50) hide show
  1. package/bin/fwdloop +23 -3
  2. package/package.json +3 -3
  3. package/src/authoring.js +10 -0
  4. package/src/canrun.js +20 -0
  5. package/src/declaration.js +98 -2
  6. package/src/drafter.js +23 -10
  7. package/src/launcher.js +3 -2
  8. package/src/learnstore.js +1 -1
  9. package/src/pageask.js +18 -2
  10. package/src/pagefetch.js +10 -5
  11. package/src/panel/author.js +18 -2
  12. package/src/panel/authorflows.js +9 -4
  13. package/src/panel/authorstart.js +10 -6
  14. package/src/panel/authortrigger.js +34 -10
  15. package/src/panel/data.js +39 -4
  16. package/src/panel/index.html +516 -60
  17. package/src/panel/scheduler.js +42 -6
  18. package/src/panel/server.js +21 -5
  19. package/src/panel/tickets.js +113 -0
  20. package/src/runner.js +51 -10
  21. package/src/schedule.js +5 -0
  22. package/src/summary-words.js +12 -4
  23. package/src/ticket-draft.js +87 -0
  24. package/src/ticket-labels.js +65 -0
  25. package/src/ticket-mcp.js +66 -0
  26. package/src/ticket-shape.js +24 -0
  27. package/src/trigger-files.js +1 -1
  28. package/src/trigger-line.js +2 -1
  29. package/src/trigger-tickets.js +209 -0
  30. package/types/canrun.d.ts +14 -0
  31. package/types/drafter.d.ts +186 -64
  32. package/types/pageask.d.ts +1 -0
  33. package/types/pagefetch.d.ts +6 -3
  34. package/types/panel/author.d.ts +8 -0
  35. package/types/panel/authorflows.d.ts +2 -0
  36. package/types/panel/authorstart.d.ts +3 -1
  37. package/types/panel/authortrigger.d.ts +11 -1
  38. package/types/panel/data.d.ts +22 -3
  39. package/types/panel/scheduler.d.ts +7 -2
  40. package/types/panel/server.d.ts +9 -2
  41. package/types/panel/tickets.d.ts +81 -0
  42. package/types/runner.d.ts +21 -3
  43. package/types/summary-words.d.ts +2 -1
  44. package/types/ticket-draft.d.ts +96 -0
  45. package/types/ticket-labels.d.ts +36 -0
  46. package/types/ticket-mcp.d.ts +40 -0
  47. package/types/ticket-shape.d.ts +25 -0
  48. package/types/trigger-files.d.ts +2 -0
  49. package/types/trigger-line.d.ts +7 -0
  50. package/types/trigger-tickets.d.ts +91 -0
package/types/runner.d.ts CHANGED
@@ -99,15 +99,21 @@ export function freezePage(dir: string, id: string, url: string, { fetchPage }?:
99
99
  * (never the original again after this) and return the manifest, which `runFlow` records as the `inputs` of `run.json` (M8b). An
100
100
  * unreadable source refuses by name. A source that is a web address
101
101
  * (M10 item 1) is fetched and frozen by `freezePage`, in the same manifest.
102
- * @param {string} runDir @param {Array<{id: string, path: string}>} sources
102
+ * @param {string} runDir @param {Array<{id: string, path: string, ticket?: {number: number, anyway?: true}}>} sources
103
103
  * M10b amendment 1: a CSV input named in `tableRoles` (the sheets a step's `close.sheet` reads) also gets its `tableSha` (bareguard's fingerprint of the table made
104
104
  * from the FROZEN copy) in its manifest entry - the ONE place it is written, once, with the run's inputs; every sheet check of the run uses this recorded value.
105
105
  * A sheet bareguard cannot read as a table refuses the run here, naming the input.
106
- * @param {{fetchPage?: (url: string) => Promise<{ok: true, text: string, url: string}|{ok: false, error: string}>, tableRoles?: string[]}} [o] */
106
+ * M12 piece 1b: a source with `ticket: {number}` is one ticket of the list at its `path`, read through the job's MCP tools (`mcp`, the declaration's `{server, tools}`) by
107
+ * `ticketRead` and frozen like a page; its manifest entry also carries `mcp`, the record of what the server exposed and each call made (kept in `run.json`, no new file).
108
+ * @param {{fetchPage?: (url: string) => Promise<{ok: true, text: string, url: string}|{ok: false, error: string}>, tableRoles?: string[], mcp?: {server: string, tools: string[]}, ticketRead?: typeof readTicketMcp, ticketFilter?: {priority?: string[], labels?: string[]}}} [o] */
107
109
  export function freezeInputs(runDir: string, sources: Array<{
108
110
  id: string;
109
111
  path: string;
110
- }>, { fetchPage, tableRoles }?: {
112
+ ticket?: {
113
+ number: number;
114
+ anyway?: true;
115
+ };
116
+ }>, { fetchPage, tableRoles, mcp, ticketRead, ticketFilter }?: {
111
117
  fetchPage?: (url: string) => Promise<{
112
118
  ok: true;
113
119
  text: string;
@@ -117,10 +123,20 @@ export function freezeInputs(runDir: string, sources: Array<{
117
123
  error: string;
118
124
  }>;
119
125
  tableRoles?: string[];
126
+ mcp?: {
127
+ server: string;
128
+ tools: string[];
129
+ };
130
+ ticketRead?: typeof readTicketMcp;
131
+ ticketFilter?: {
132
+ priority?: string[];
133
+ labels?: string[];
134
+ };
120
135
  }): Promise<{
121
136
  ok: boolean;
122
137
  red: string;
123
138
  manifest?: undefined;
139
+ skip?: undefined;
124
140
  } | {
125
141
  ok: boolean;
126
142
  manifest: (Record<string, any> | {
@@ -130,6 +146,7 @@ export function freezeInputs(runDir: string, sources: Array<{
130
146
  sha256: string;
131
147
  bytes: number;
132
148
  })[];
149
+ skip: string | null;
133
150
  red?: undefined;
134
151
  }>;
135
152
  /** The send target's folder (M4e amendment 1, "Destination is any folder").
@@ -553,3 +570,4 @@ export const STOP_FILE: "stop.request";
553
570
  export const HALT_FILE: "halt.json";
554
571
  /** where a failure of learnings work that must not stop the run is recorded (one appended row, in the run's own folder): the run-end tally (`recordRunNotes`) and the take of the draft's learnings record (`takeLearningsRecord`, in runFlow). The run itself is unaffected */
555
572
  export const LEARN_ERROR_FILE: "learn-error.jsonl";
573
+ import { readTicketMcp } from './ticket-mcp.js';
@@ -39,7 +39,7 @@ export function catchUpWords(rec: any): "This run was a catch-up: it started mor
39
39
  /**
40
40
  * ENDED / NEXT of a finished run. Every outcome the history row can hold has a fixed sentence; an unknown one gets an honest fixed fallback
41
41
  * that names the code and guesses nothing. `null` when there is no ending (still running, waiting, or no history row and not died).
42
- * @param {{outcome: string|null, died?: boolean, line: number|null, destination: string|null, canResume: boolean, home?: string}} f
42
+ * @param {{outcome: string|null, died?: boolean, line: number|null, destination: string|null, canResume: boolean, home?: string, skipReason?: string}} f
43
43
  * @returns {{reason: string, next: string, rows?: Array<[string, string]>}|null}
44
44
  */
45
45
  export function endedWords(f: {
@@ -49,6 +49,7 @@ export function endedWords(f: {
49
49
  destination: string | null;
50
50
  canResume: boolean;
51
51
  home?: string;
52
+ skipReason?: string;
52
53
  }): {
53
54
  reason: string;
54
55
  next: string;
@@ -0,0 +1,96 @@
1
+ /** the refusals of a by-hand start's ticket box: a ticket job needs a number; any other job takes none. @param {string|null} ticketRole @param {any} body @returns {{field: string, say: string}[]} */
2
+ export function ticketRefusals(ticketRole: string | null, body: any): {
3
+ field: string;
4
+ say: string;
5
+ }[];
6
+ /** the server names in the user's own `~/.mcp.json` (what the drafter may name); none when the file is missing or unreadable @param {string} [configPath] @returns {string[]} */
7
+ export function userMcpServers(configPath?: string): string[];
8
+ /**
9
+ * The lines under "Inputs" for one ticket role. The first is F90c's, word for word; the rest tell the drafter the two optional fields it may suggest.
10
+ * @param {string} role @param {string[]} servers @returns {string[]}
11
+ */
12
+ export function ticketFactsLines(role: string, servers: string[]): string[];
13
+ /** the schema parts a job with a ticket role adds: top-level `mcp` and `ticketFilter`, per-step `mcpTools` @param {string[]} servers */
14
+ export function ticketSchemaParts(servers: string[]): {
15
+ top: {
16
+ mcp: {
17
+ type: string;
18
+ properties: {
19
+ server: {
20
+ type: string;
21
+ enum: string[];
22
+ };
23
+ tools: {
24
+ type: string;
25
+ items: {
26
+ type: string;
27
+ enum: string[];
28
+ };
29
+ };
30
+ };
31
+ required: string[];
32
+ additionalProperties: boolean;
33
+ description: string;
34
+ };
35
+ ticketFilter: {
36
+ type: string;
37
+ properties: {
38
+ priority: {
39
+ type: string;
40
+ items: {
41
+ type: string;
42
+ enum: string[];
43
+ };
44
+ description: string;
45
+ };
46
+ labels: {
47
+ type: string;
48
+ items: {
49
+ type: string;
50
+ };
51
+ description: string;
52
+ };
53
+ };
54
+ additionalProperties: boolean;
55
+ description: string;
56
+ };
57
+ ticketWatch: {
58
+ type: string;
59
+ items: {
60
+ type: string;
61
+ enum: string[];
62
+ };
63
+ description: string;
64
+ };
65
+ };
66
+ step: {
67
+ mcpTools: {
68
+ type: string;
69
+ items: {
70
+ type: string;
71
+ enum: string[];
72
+ };
73
+ description: string;
74
+ };
75
+ };
76
+ };
77
+ /**
78
+ * Reds a draft with a ticket role must not pass with: no `mcp`, a server the person's config does not have, or no step that reads the ticket and holds the tool.
79
+ * @param {Record<string, any>} declaration @param {Array<{role: string}>} ticketSources @param {string[]} servers @returns {string[]}
80
+ */
81
+ export function ticketReds(declaration: Record<string, any>, ticketSources: Array<{
82
+ role: string;
83
+ }>, servers: string[]): string[];
84
+ /** the one tool the first slice reads a ticket with */
85
+ export const TICKET_TOOL: "issue_read";
86
+ export function isTicketListUrl(url: unknown): boolean;
87
+ export function ticketSourcesOf(sources: Array<{
88
+ kind?: string;
89
+ role: string;
90
+ path: string;
91
+ }>): {
92
+ kind?: string;
93
+ role: string;
94
+ path: string;
95
+ }[];
96
+ export function ticketNumberOf(v: unknown): number | null;
@@ -0,0 +1,36 @@
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
+ * @param {{text: string, filter?: {priority?: string[], labels?: string[]}}} a `filter` = the job's signed `ticketFilter` (or absent)
22
+ * @returns {{outcome: 'run', unsure?: string}|{outcome: 'skip', reason: string}}
23
+ */
24
+ export function decideTicket({ text, filter }: {
25
+ text: string;
26
+ filter?: {
27
+ priority?: string[];
28
+ labels?: string[];
29
+ };
30
+ }): {
31
+ outcome: "run";
32
+ unsure?: string;
33
+ } | {
34
+ outcome: "skip";
35
+ reason: string;
36
+ };
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Read ticket `number` of the list at `listUrl` with the job's `issue_read`.
3
+ * @param {{listUrl: string, number: number, mcp: {server: string, tools: string[]}, configPath?: string, timeoutMs?: number}} o
4
+ * @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}>}
5
+ * `record` is what the run keeps (in its `run.json` input entry): what the server exposed and lacked, and each call made.
6
+ */
7
+ export function readTicketMcp({ listUrl, number, mcp, configPath, timeoutMs }: {
8
+ listUrl: string;
9
+ number: number;
10
+ mcp: {
11
+ server: string;
12
+ tools: string[];
13
+ };
14
+ configPath?: string;
15
+ timeoutMs?: number;
16
+ }): Promise<{
17
+ ok: true;
18
+ text: string;
19
+ url: string;
20
+ record: {
21
+ server: string;
22
+ exposed: string[];
23
+ missing: Array<{
24
+ server: string;
25
+ tool: string;
26
+ }>;
27
+ calls: Array<{
28
+ tool: string;
29
+ owner: string;
30
+ repo: string;
31
+ issue_number: number;
32
+ }>;
33
+ };
34
+ } | {
35
+ ok: false;
36
+ error: string;
37
+ }>;
38
+ export function USER_MCP_CONFIG(): string;
39
+ export function firstLine(e: any): string;
40
+ export function isDeviceLogin(text: any): any;
@@ -0,0 +1,25 @@
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;
@@ -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;
@@ -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,91 @@
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
+ * @param {{listUrl: string, mcp: {server: string, tool: string}, configPath?: string, seen: Set<number>|null, last: Map<number, {state: string, labels: string[]}>, watch: string[], perPage?: number, timeoutMs?: number}} o
16
+ * @returns {Promise<{ok: true, first: boolean, 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}>}
17
+ */
18
+ export function lookTickets({ listUrl, mcp, configPath, seen, last, watch, perPage, timeoutMs, }: {
19
+ listUrl: string;
20
+ mcp: {
21
+ server: string;
22
+ tool: string;
23
+ };
24
+ configPath?: string;
25
+ seen: Set<number> | null;
26
+ last: Map<number, {
27
+ state: string;
28
+ labels: string[];
29
+ }>;
30
+ watch: string[];
31
+ perPage?: number;
32
+ timeoutMs?: number;
33
+ }): Promise<{
34
+ ok: true;
35
+ first: boolean;
36
+ found: Array<{
37
+ number: number;
38
+ state: string;
39
+ labels: string[];
40
+ createdAt: string | null;
41
+ }>;
42
+ changed: Array<{
43
+ number: number;
44
+ reason: string;
45
+ state: string;
46
+ labels: string[];
47
+ }>;
48
+ pages: number;
49
+ } | {
50
+ ok: false;
51
+ error: string;
52
+ }>;
53
+ /** The numbers a signing has a baseline or an arrived row for. @param {string} ledger @param {string} sig */
54
+ export function seenNumbers(ledger: string, sig: string): Set<any>;
55
+ /** 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[]}>} */
56
+ export function lastSeen(ledger: string, sig: string): Map<number, {
57
+ state: string;
58
+ labels: string[];
59
+ }>;
60
+ /**
61
+ * 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
62
+ * 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.
63
+ * @param {string} ledger @param {string} sig @param {Awaited<ReturnType<typeof lookTickets>>} look @param {number} at
64
+ * @returns {{arrived: number[], unreadable: string|null}}
65
+ */
66
+ export function recordLook(ledger: string, sig: string, look: Awaited<ReturnType<typeof lookTickets>>, at: number): {
67
+ arrived: number[];
68
+ unreadable: string | null;
69
+ };
70
+ /**
71
+ * 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.
72
+ * 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
73
+ * is refused, never a second run). @param {string} ledger @param {string} sig @param {{number: number, reason: string}} a @param {number} at
74
+ * @returns {{ok: true} | {ok: false, say: string}}
75
+ */
76
+ export function recordAnyway(ledger: string, sig: string, a: {
77
+ number: number;
78
+ reason: string;
79
+ }, at: number): {
80
+ ok: true;
81
+ } | {
82
+ ok: false;
83
+ say: string;
84
+ };
85
+ /** A look every 15 minutes, fixed (item 8). */
86
+ export const TICKET_LOOK_MS: number;
87
+ export function watchedOf(i: any): {
88
+ state: string;
89
+ labels: any;
90
+ };
91
+ export function hasBaseline(ledger: string, sig: string): boolean;