feed-the-machine 1.0.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 (120) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +268 -0
  3. package/bin/generate-manifest.mjs +210 -0
  4. package/bin/install.mjs +114 -0
  5. package/ftm/SKILL.md +88 -0
  6. package/ftm-audit/SKILL.md +146 -0
  7. package/ftm-audit/references/protocols/PROJECT-PATTERNS.md +91 -0
  8. package/ftm-audit/references/protocols/RUNTIME-WIRING.md +66 -0
  9. package/ftm-audit/references/protocols/WIRING-CONTRACTS.md +135 -0
  10. package/ftm-audit/references/strategies/AUTO-FIX-STRATEGIES.md +69 -0
  11. package/ftm-audit/references/templates/REPORT-FORMAT.md +96 -0
  12. package/ftm-audit/scripts/run-knip.sh +23 -0
  13. package/ftm-audit.yml +2 -0
  14. package/ftm-brainstorm/SKILL.md +379 -0
  15. package/ftm-brainstorm/evals/evals.json +100 -0
  16. package/ftm-brainstorm/evals/promptfoo.yaml +109 -0
  17. package/ftm-brainstorm/references/agent-prompts.md +224 -0
  18. package/ftm-brainstorm/references/plan-template.md +121 -0
  19. package/ftm-brainstorm.yml +2 -0
  20. package/ftm-browse/SKILL.md +415 -0
  21. package/ftm-browse/daemon/browser-manager.ts +206 -0
  22. package/ftm-browse/daemon/bun.lock +30 -0
  23. package/ftm-browse/daemon/cli.ts +347 -0
  24. package/ftm-browse/daemon/commands.ts +410 -0
  25. package/ftm-browse/daemon/main.ts +357 -0
  26. package/ftm-browse/daemon/package.json +17 -0
  27. package/ftm-browse/daemon/server.ts +189 -0
  28. package/ftm-browse/daemon/snapshot.ts +519 -0
  29. package/ftm-browse/daemon/tsconfig.json +22 -0
  30. package/ftm-browse.yml +4 -0
  31. package/ftm-codex-gate/SKILL.md +302 -0
  32. package/ftm-codex-gate.yml +2 -0
  33. package/ftm-config/SKILL.md +310 -0
  34. package/ftm-config.default.yml +80 -0
  35. package/ftm-config.yml +2 -0
  36. package/ftm-council/SKILL.md +132 -0
  37. package/ftm-council/references/prompts/CLAUDE-INVESTIGATION.md +60 -0
  38. package/ftm-council/references/prompts/CODEX-INVESTIGATION.md +58 -0
  39. package/ftm-council/references/prompts/GEMINI-INVESTIGATION.md +58 -0
  40. package/ftm-council/references/prompts/REBUTTAL-TEMPLATE.md +57 -0
  41. package/ftm-council/references/protocols/PREREQUISITES.md +47 -0
  42. package/ftm-council/references/protocols/STEP-0-FRAMING.md +46 -0
  43. package/ftm-council.yml +2 -0
  44. package/ftm-dashboard.yml +4 -0
  45. package/ftm-debug/SKILL.md +146 -0
  46. package/ftm-debug/references/phases/PHASE-0-INTAKE.md +58 -0
  47. package/ftm-debug/references/phases/PHASE-1-TRIAGE.md +46 -0
  48. package/ftm-debug/references/phases/PHASE-2-WAR-ROOM-AGENTS.md +279 -0
  49. package/ftm-debug/references/phases/PHASE-3-TO-6-EXECUTION.md +436 -0
  50. package/ftm-debug/references/protocols/BLACKBOARD.md +86 -0
  51. package/ftm-debug/references/protocols/EDGE-CASES.md +103 -0
  52. package/ftm-debug.yml +2 -0
  53. package/ftm-diagram/SKILL.md +233 -0
  54. package/ftm-diagram.yml +2 -0
  55. package/ftm-executor/SKILL.md +657 -0
  56. package/ftm-executor/references/STYLE-TEMPLATE.md +73 -0
  57. package/ftm-executor/references/phases/PHASE-0-VERIFICATION.md +62 -0
  58. package/ftm-executor/references/phases/PHASE-2-AGENT-ASSEMBLY.md +34 -0
  59. package/ftm-executor/references/phases/PHASE-3-WORKTREES.md +38 -0
  60. package/ftm-executor/references/phases/PHASE-4-5-AUDIT.md +72 -0
  61. package/ftm-executor/references/phases/PHASE-4-DISPATCH.md +66 -0
  62. package/ftm-executor/references/phases/PHASE-5-5-CODEX-GATE.md +73 -0
  63. package/ftm-executor/references/protocols/DOCUMENTATION-BOOTSTRAP.md +36 -0
  64. package/ftm-executor/references/protocols/MODEL-PROFILE.md +44 -0
  65. package/ftm-executor/references/protocols/PROGRESS-TRACKING.md +66 -0
  66. package/ftm-executor/runtime/ftm-runtime.mjs +252 -0
  67. package/ftm-executor/runtime/package.json +8 -0
  68. package/ftm-executor.yml +2 -0
  69. package/ftm-git/SKILL.md +195 -0
  70. package/ftm-git/evals/evals.json +26 -0
  71. package/ftm-git/evals/promptfoo.yaml +75 -0
  72. package/ftm-git/hooks/post-commit-experience.sh +92 -0
  73. package/ftm-git/references/patterns/SECRET-PATTERNS.md +104 -0
  74. package/ftm-git/references/protocols/REMEDIATION.md +139 -0
  75. package/ftm-git/scripts/pre-commit-secrets.sh +110 -0
  76. package/ftm-git.yml +2 -0
  77. package/ftm-intent/SKILL.md +198 -0
  78. package/ftm-intent.yml +2 -0
  79. package/ftm-map.yml +2 -0
  80. package/ftm-mind/SKILL.md +986 -0
  81. package/ftm-mind/evals/promptfoo.yaml +142 -0
  82. package/ftm-mind/references/blackboard-schema.md +328 -0
  83. package/ftm-mind/references/complexity-guide.md +110 -0
  84. package/ftm-mind/references/event-registry.md +299 -0
  85. package/ftm-mind/references/mcp-inventory.md +296 -0
  86. package/ftm-mind/references/protocols/COMPLEXITY-SIZING.md +72 -0
  87. package/ftm-mind/references/protocols/MCP-HEURISTICS.md +32 -0
  88. package/ftm-mind/references/protocols/PLAN-APPROVAL.md +80 -0
  89. package/ftm-mind/references/reflexion-protocol.md +249 -0
  90. package/ftm-mind/references/routing/SCENARIOS.md +22 -0
  91. package/ftm-mind/references/routing-scenarios.md +35 -0
  92. package/ftm-mind.yml +2 -0
  93. package/ftm-pause/SKILL.md +133 -0
  94. package/ftm-pause/references/protocols/SKILL-RESTORE-PROTOCOLS.md +186 -0
  95. package/ftm-pause/references/protocols/VALIDATION.md +80 -0
  96. package/ftm-pause.yml +2 -0
  97. package/ftm-researcher.yml +2 -0
  98. package/ftm-resume/SKILL.md +166 -0
  99. package/ftm-resume/references/protocols/VALIDATION.md +172 -0
  100. package/ftm-resume.yml +2 -0
  101. package/ftm-retro/SKILL.md +189 -0
  102. package/ftm-retro/references/protocols/SCORING-RUBRICS.md +89 -0
  103. package/ftm-retro/references/templates/REPORT-FORMAT.md +109 -0
  104. package/ftm-retro.yml +2 -0
  105. package/ftm-routine.yml +4 -0
  106. package/ftm-state/blackboard/context.json +23 -0
  107. package/ftm-state/blackboard/experiences/index.json +9 -0
  108. package/ftm-state/blackboard/patterns.json +6 -0
  109. package/ftm-state/schemas/context.schema.json +130 -0
  110. package/ftm-state/schemas/experience-index.schema.json +77 -0
  111. package/ftm-state/schemas/experience.schema.json +78 -0
  112. package/ftm-state/schemas/patterns.schema.json +44 -0
  113. package/ftm-upgrade/SKILL.md +153 -0
  114. package/ftm-upgrade/scripts/check-version.sh +76 -0
  115. package/ftm-upgrade/scripts/upgrade.sh +143 -0
  116. package/ftm-upgrade.yml +2 -0
  117. package/ftm.yml +2 -0
  118. package/install.sh +102 -0
  119. package/package.json +74 -0
  120. package/uninstall.sh +25 -0
@@ -0,0 +1,410 @@
1
+ import { browserManager } from "./browser-manager.ts";
2
+ import { buildSnapshot, checkRefStale, resolveRef } from "./snapshot.ts";
3
+ import * as path from "path";
4
+ import * as fs from "fs";
5
+
6
+ export interface CommandResult {
7
+ success: boolean;
8
+ data?: unknown;
9
+ error?: string;
10
+ }
11
+
12
+ // ─── WRITE Commands (state-mutating) ───────────────────────────────────────
13
+
14
+ export async function gotoCommand(args: { url: string }): Promise<CommandResult> {
15
+ if (!args.url) {
16
+ return { success: false, error: "url is required" };
17
+ }
18
+
19
+ try {
20
+ const page = await browserManager.getPage();
21
+ const response = await page.goto(args.url, {
22
+ waitUntil: "domcontentloaded",
23
+ timeout: 30000,
24
+ });
25
+
26
+ return {
27
+ success: true,
28
+ data: {
29
+ url: page.url(),
30
+ title: await page.title(),
31
+ status: response?.status() ?? null,
32
+ },
33
+ };
34
+ } catch (err) {
35
+ return {
36
+ success: false,
37
+ error: err instanceof Error ? err.message : String(err),
38
+ };
39
+ }
40
+ }
41
+
42
+ export async function clickCommand(args: { ref: string }): Promise<CommandResult> {
43
+ if (!args.ref) {
44
+ return { success: false, error: "ref is required" };
45
+ }
46
+
47
+ try {
48
+ const page = await browserManager.getPage();
49
+
50
+ // Staleness check (~5ms fast-fail)
51
+ const staleCheck = await checkRefStale(page, args.ref);
52
+ if (staleCheck.stale) {
53
+ return { success: false, error: staleCheck.error };
54
+ }
55
+
56
+ const locator = resolveRef(page, args.ref);
57
+ await locator.click({ timeout: 10000 });
58
+
59
+ // Wait for any navigation or network idle after click
60
+ try {
61
+ await page.waitForLoadState("domcontentloaded", { timeout: 3000 });
62
+ } catch {
63
+ // Navigation may not have occurred, that's ok
64
+ }
65
+
66
+ return {
67
+ success: true,
68
+ data: {
69
+ url: page.url(),
70
+ title: await page.title(),
71
+ },
72
+ };
73
+ } catch (err) {
74
+ return {
75
+ success: false,
76
+ error: err instanceof Error ? err.message : String(err),
77
+ };
78
+ }
79
+ }
80
+
81
+ export async function fillCommand(args: {
82
+ ref: string;
83
+ value: string;
84
+ }): Promise<CommandResult> {
85
+ if (!args.ref) {
86
+ return { success: false, error: "ref is required" };
87
+ }
88
+ if (args.value === undefined || args.value === null) {
89
+ return { success: false, error: "value is required" };
90
+ }
91
+
92
+ try {
93
+ const page = await browserManager.getPage();
94
+
95
+ // Staleness check (~5ms fast-fail)
96
+ const staleCheck = await checkRefStale(page, args.ref);
97
+ if (staleCheck.stale) {
98
+ return { success: false, error: staleCheck.error };
99
+ }
100
+
101
+ const locator = resolveRef(page, args.ref);
102
+ await locator.fill(String(args.value), { timeout: 10000 });
103
+
104
+ return {
105
+ success: true,
106
+ data: { ref: args.ref, value: args.value },
107
+ };
108
+ } catch (err) {
109
+ return {
110
+ success: false,
111
+ error: err instanceof Error ? err.message : String(err),
112
+ };
113
+ }
114
+ }
115
+
116
+ export async function pressCommand(args: { key: string }): Promise<CommandResult> {
117
+ if (!args.key) {
118
+ return { success: false, error: "key is required" };
119
+ }
120
+
121
+ try {
122
+ const page = await browserManager.getPage();
123
+ await page.keyboard.press(args.key);
124
+
125
+ // Wait briefly for any resulting navigation
126
+ try {
127
+ await page.waitForLoadState("domcontentloaded", { timeout: 2000 });
128
+ } catch {
129
+ // No navigation, that's fine
130
+ }
131
+
132
+ return {
133
+ success: true,
134
+ data: {
135
+ key: args.key,
136
+ url: page.url(),
137
+ },
138
+ };
139
+ } catch (err) {
140
+ return {
141
+ success: false,
142
+ error: err instanceof Error ? err.message : String(err),
143
+ };
144
+ }
145
+ }
146
+
147
+ // ─── READ Commands (safe to retry) ─────────────────────────────────────────
148
+
149
+ export async function textCommand(): Promise<CommandResult> {
150
+ try {
151
+ const page = await browserManager.getPage();
152
+ const text = await page.evaluate(() => document.body.innerText);
153
+
154
+ return {
155
+ success: true,
156
+ data: { text },
157
+ };
158
+ } catch (err) {
159
+ return {
160
+ success: false,
161
+ error: err instanceof Error ? err.message : String(err),
162
+ };
163
+ }
164
+ }
165
+
166
+ export async function htmlCommand(): Promise<CommandResult> {
167
+ try {
168
+ const page = await browserManager.getPage();
169
+ const html = await page.content();
170
+
171
+ return {
172
+ success: true,
173
+ data: { html },
174
+ };
175
+ } catch (err) {
176
+ return {
177
+ success: false,
178
+ error: err instanceof Error ? err.message : String(err),
179
+ };
180
+ }
181
+ }
182
+
183
+ // ─── EVAL Command ───────────────────────────────────────────────────────────
184
+
185
+ export async function evalCommand(args: {
186
+ expression: string;
187
+ }): Promise<CommandResult> {
188
+ if (!args.expression) {
189
+ return { success: false, error: "expression is required" };
190
+ }
191
+
192
+ try {
193
+ const page = await browserManager.getPage();
194
+ const result = await page.evaluate((expr) => {
195
+ try {
196
+ // eslint-disable-next-line no-eval
197
+ const value = eval(expr);
198
+ // Handle non-serializable values
199
+ if (value instanceof HTMLElement) {
200
+ return {
201
+ type: "element",
202
+ tagName: value.tagName,
203
+ id: value.id,
204
+ text: value.textContent?.slice(0, 200),
205
+ };
206
+ }
207
+ if (typeof value === "function") {
208
+ return { type: "function", name: value.name || "anonymous" };
209
+ }
210
+ return value;
211
+ } catch (e) {
212
+ return { error: String(e) };
213
+ }
214
+ }, args.expression);
215
+
216
+ return {
217
+ success: true,
218
+ data: { result },
219
+ };
220
+ } catch (err) {
221
+ return {
222
+ success: false,
223
+ error: `Evaluation failed: ${err instanceof Error ? err.message : String(err)}`,
224
+ };
225
+ }
226
+ }
227
+
228
+ // ─── META Commands ──────────────────────────────────────────────────────────
229
+
230
+ export async function snapshotCommand(args: {
231
+ interactive_only?: boolean;
232
+ }): Promise<CommandResult> {
233
+ try {
234
+ const page = await browserManager.getPage();
235
+ const interactiveOnly = args.interactive_only === true;
236
+ const { tree, refs, aria_text } = await buildSnapshot(page, interactiveOnly);
237
+
238
+ return {
239
+ success: true,
240
+ data: {
241
+ url: page.url(),
242
+ title: await page.title(),
243
+ interactive_only: interactiveOnly,
244
+ tree,
245
+ refs,
246
+ ...(aria_text ? { aria_text } : {}),
247
+ },
248
+ };
249
+ } catch (err) {
250
+ return {
251
+ success: false,
252
+ error: err instanceof Error ? err.message : String(err),
253
+ };
254
+ }
255
+ }
256
+
257
+ export async function screenshotCommand(args: {
258
+ path?: string;
259
+ }): Promise<CommandResult> {
260
+ try {
261
+ const page = await browserManager.getPage();
262
+
263
+ // Default screenshot directory
264
+ const screenshotDir = path.join(
265
+ process.env.HOME || "~",
266
+ ".ftm-browse",
267
+ "screenshots"
268
+ );
269
+
270
+ // Ensure directory exists
271
+ if (!fs.existsSync(screenshotDir)) {
272
+ fs.mkdirSync(screenshotDir, { recursive: true });
273
+ }
274
+
275
+ const screenshotPath =
276
+ args.path ||
277
+ path.join(screenshotDir, `screenshot-${Date.now()}.png`);
278
+
279
+ await page.screenshot({
280
+ path: screenshotPath,
281
+ fullPage: false,
282
+ });
283
+
284
+ return {
285
+ success: true,
286
+ data: {
287
+ path: screenshotPath,
288
+ url: page.url(),
289
+ title: await page.title(),
290
+ },
291
+ };
292
+ } catch (err) {
293
+ return {
294
+ success: false,
295
+ error: err instanceof Error ? err.message : String(err),
296
+ };
297
+ }
298
+ }
299
+
300
+ export async function tabsCommand(): Promise<CommandResult> {
301
+ try {
302
+ const pages = await browserManager.getAllPages();
303
+
304
+ const tabInfo = await Promise.all(
305
+ pages.map(async (p, index) => {
306
+ try {
307
+ return {
308
+ index,
309
+ url: p.url(),
310
+ title: await p.title(),
311
+ active: false, // We'll mark the active one below
312
+ };
313
+ } catch {
314
+ return {
315
+ index,
316
+ url: "about:blank",
317
+ title: "Unknown",
318
+ active: false,
319
+ };
320
+ }
321
+ })
322
+ );
323
+
324
+ // Mark the active tab (last page that had interaction)
325
+ if (tabInfo.length > 0) {
326
+ tabInfo[tabInfo.length - 1].active = true;
327
+ }
328
+
329
+ return {
330
+ success: true,
331
+ data: { tabs: tabInfo },
332
+ };
333
+ } catch (err) {
334
+ return {
335
+ success: false,
336
+ error: err instanceof Error ? err.message : String(err),
337
+ };
338
+ }
339
+ }
340
+
341
+ // ─── CHAIN Command ──────────────────────────────────────────────────────────
342
+
343
+ export interface ChainStep {
344
+ command: string;
345
+ args?: Record<string, unknown>;
346
+ }
347
+
348
+ export async function chainCommand(args: {
349
+ commands: ChainStep[];
350
+ }): Promise<CommandResult> {
351
+ if (!Array.isArray(args.commands)) {
352
+ return { success: false, error: "commands must be an array" };
353
+ }
354
+
355
+ const results: Array<{ command: string; result: CommandResult }> = [];
356
+
357
+ for (const step of args.commands) {
358
+ const result = await executeCommand(step.command, step.args || {});
359
+ results.push({ command: step.command, result });
360
+
361
+ // Stop chain on error
362
+ if (!result.success) {
363
+ return {
364
+ success: false,
365
+ error: `Chain failed at command '${step.command}': ${result.error}`,
366
+ data: { results, failed_at: step.command },
367
+ };
368
+ }
369
+ }
370
+
371
+ return {
372
+ success: true,
373
+ data: { results },
374
+ };
375
+ }
376
+
377
+ // ─── Command Dispatcher ─────────────────────────────────────────────────────
378
+
379
+ export async function executeCommand(
380
+ command: string,
381
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
382
+ args: Record<string, any>
383
+ ): Promise<CommandResult> {
384
+ switch (command) {
385
+ case "goto":
386
+ return gotoCommand(args as { url: string });
387
+ case "click":
388
+ return clickCommand(args as { ref: string });
389
+ case "fill":
390
+ return fillCommand(args as { ref: string; value: string });
391
+ case "press":
392
+ return pressCommand(args as { key: string });
393
+ case "text":
394
+ return textCommand();
395
+ case "html":
396
+ return htmlCommand();
397
+ case "snapshot":
398
+ return snapshotCommand(args as { interactive_only?: boolean });
399
+ case "screenshot":
400
+ return screenshotCommand(args as { path?: string });
401
+ case "tabs":
402
+ return tabsCommand();
403
+ case "chain":
404
+ return chainCommand(args as { commands: ChainStep[] });
405
+ case "eval":
406
+ return evalCommand(args as { expression: string });
407
+ default:
408
+ return { success: false, error: `Unknown command: ${command}` };
409
+ }
410
+ }