feed-the-machine 1.1.0 → 1.3.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.
- package/bin/generate-manifest.mjs +253 -0
- package/bin/install.mjs +372 -26
- package/docs/INBOX.md +233 -0
- package/ftm/SKILL.md +34 -0
- package/ftm-audit/SKILL.md +69 -0
- package/ftm-brainstorm/SKILL.md +51 -0
- package/ftm-browse/SKILL.md +39 -0
- package/ftm-capture/SKILL.md +370 -0
- package/ftm-capture.yml +4 -0
- package/ftm-codex-gate/SKILL.md +59 -0
- package/ftm-config/SKILL.md +35 -0
- package/ftm-council/SKILL.md +56 -0
- package/ftm-dashboard/SKILL.md +34 -0
- package/ftm-debug/SKILL.md +84 -0
- package/ftm-diagram/SKILL.md +44 -0
- package/ftm-executor/SKILL.md +97 -0
- package/ftm-git/SKILL.md +60 -0
- package/ftm-inbox/backend/__init__.py +0 -0
- package/ftm-inbox/backend/adapters/__init__.py +0 -0
- package/ftm-inbox/backend/adapters/_retry.py +64 -0
- package/ftm-inbox/backend/adapters/base.py +230 -0
- package/ftm-inbox/backend/adapters/freshservice.py +104 -0
- package/ftm-inbox/backend/adapters/gmail.py +125 -0
- package/ftm-inbox/backend/adapters/jira.py +136 -0
- package/ftm-inbox/backend/adapters/registry.py +192 -0
- package/ftm-inbox/backend/adapters/slack.py +110 -0
- package/ftm-inbox/backend/db/__init__.py +0 -0
- package/ftm-inbox/backend/db/connection.py +54 -0
- package/ftm-inbox/backend/db/schema.py +78 -0
- package/ftm-inbox/backend/executor/__init__.py +7 -0
- package/ftm-inbox/backend/executor/engine.py +149 -0
- package/ftm-inbox/backend/executor/step_runner.py +98 -0
- package/ftm-inbox/backend/main.py +103 -0
- package/ftm-inbox/backend/models/__init__.py +1 -0
- package/ftm-inbox/backend/models/unified_task.py +36 -0
- package/ftm-inbox/backend/planner/__init__.py +6 -0
- package/ftm-inbox/backend/planner/generator.py +127 -0
- package/ftm-inbox/backend/planner/schema.py +34 -0
- package/ftm-inbox/backend/requirements.txt +5 -0
- package/ftm-inbox/backend/routes/__init__.py +0 -0
- package/ftm-inbox/backend/routes/execute.py +186 -0
- package/ftm-inbox/backend/routes/health.py +52 -0
- package/ftm-inbox/backend/routes/inbox.py +68 -0
- package/ftm-inbox/backend/routes/plan.py +271 -0
- package/ftm-inbox/bin/launchagent.mjs +91 -0
- package/ftm-inbox/bin/setup.mjs +188 -0
- package/ftm-inbox/bin/start.sh +10 -0
- package/ftm-inbox/bin/status.sh +17 -0
- package/ftm-inbox/bin/stop.sh +8 -0
- package/ftm-inbox/config.example.yml +55 -0
- package/ftm-inbox/package-lock.json +2898 -0
- package/ftm-inbox/package.json +26 -0
- package/ftm-inbox/postcss.config.js +6 -0
- package/ftm-inbox/src/app.css +199 -0
- package/ftm-inbox/src/app.html +18 -0
- package/ftm-inbox/src/lib/api.ts +166 -0
- package/ftm-inbox/src/lib/components/ExecutionLog.svelte +81 -0
- package/ftm-inbox/src/lib/components/InboxFeed.svelte +143 -0
- package/ftm-inbox/src/lib/components/PlanStep.svelte +271 -0
- package/ftm-inbox/src/lib/components/PlanView.svelte +206 -0
- package/ftm-inbox/src/lib/components/StreamPanel.svelte +99 -0
- package/ftm-inbox/src/lib/components/TaskCard.svelte +190 -0
- package/ftm-inbox/src/lib/components/ui/EmptyState.svelte +63 -0
- package/ftm-inbox/src/lib/components/ui/KawaiiCard.svelte +86 -0
- package/ftm-inbox/src/lib/components/ui/PillButton.svelte +106 -0
- package/ftm-inbox/src/lib/components/ui/StatusBadge.svelte +67 -0
- package/ftm-inbox/src/lib/components/ui/StreamDrawer.svelte +149 -0
- package/ftm-inbox/src/lib/components/ui/ThemeToggle.svelte +80 -0
- package/ftm-inbox/src/lib/theme.ts +47 -0
- package/ftm-inbox/src/routes/+layout.svelte +76 -0
- package/ftm-inbox/src/routes/+page.svelte +401 -0
- package/ftm-inbox/static/favicon.png +0 -0
- package/ftm-inbox/svelte.config.js +12 -0
- package/ftm-inbox/tailwind.config.ts +63 -0
- package/ftm-inbox/tsconfig.json +13 -0
- package/ftm-inbox/vite.config.ts +6 -0
- package/ftm-intent/SKILL.md +44 -0
- package/ftm-manifest.json +3794 -0
- package/ftm-map/SKILL.md +50 -0
- package/ftm-mind/SKILL.md +173 -66
- package/ftm-pause/SKILL.md +43 -0
- package/ftm-researcher/SKILL.md +55 -0
- package/ftm-resume/SKILL.md +47 -0
- package/ftm-retro/SKILL.md +54 -0
- package/ftm-routine/SKILL.md +36 -0
- package/ftm-state/blackboard/capabilities.json +5 -0
- package/ftm-state/blackboard/capabilities.schema.json +27 -0
- package/ftm-upgrade/SKILL.md +41 -0
- package/hooks/ftm-blackboard-enforcer.sh +28 -27
- package/hooks/ftm-plan-gate.sh +21 -25
- package/install.sh +238 -111
- package/package.json +6 -2
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Plan API routes.
|
|
3
|
+
|
|
4
|
+
Endpoints:
|
|
5
|
+
POST /api/tasks/{task_id}/generate-plan — generate a plan via Claude CLI
|
|
6
|
+
GET /api/tasks/{task_id}/plan — fetch the current plan
|
|
7
|
+
POST /api/tasks/{task_id}/plan/steps/{step_id}/approve — approve one step
|
|
8
|
+
POST /api/tasks/{task_id}/plan/approve-all — approve all low-risk steps
|
|
9
|
+
GET /api/tasks/{task_id}/plan-stream — SSE stream for live generation output
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import asyncio
|
|
15
|
+
import json
|
|
16
|
+
import sqlite3
|
|
17
|
+
from datetime import datetime, timezone
|
|
18
|
+
from pathlib import Path
|
|
19
|
+
|
|
20
|
+
from fastapi import APIRouter, HTTPException
|
|
21
|
+
from fastapi.responses import StreamingResponse
|
|
22
|
+
|
|
23
|
+
from backend.db.connection import get_connection
|
|
24
|
+
from backend.planner.generator import generate_plan
|
|
25
|
+
from backend.planner.schema import Plan, PlanStep
|
|
26
|
+
|
|
27
|
+
router = APIRouter(prefix="/api", tags=["plans"])
|
|
28
|
+
|
|
29
|
+
# ---------------------------------------------------------------------------
|
|
30
|
+
# Helpers
|
|
31
|
+
# ---------------------------------------------------------------------------
|
|
32
|
+
|
|
33
|
+
_CAPABILITIES_PATH = Path(__file__).resolve().parent.parent.parent / "config.yml"
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _now() -> str:
|
|
37
|
+
return datetime.now(timezone.utc).isoformat()
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _load_capabilities() -> dict:
|
|
41
|
+
"""Try to load the capabilities section from config.yml. Non-fatal."""
|
|
42
|
+
try:
|
|
43
|
+
import yaml
|
|
44
|
+
with open(_CAPABILITIES_PATH) as f:
|
|
45
|
+
cfg = yaml.safe_load(f) or {}
|
|
46
|
+
return cfg.get("capabilities", {})
|
|
47
|
+
except Exception:
|
|
48
|
+
return {}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def _fetch_task(conn: sqlite3.Connection, task_id: int) -> dict:
|
|
52
|
+
row = conn.execute("SELECT * FROM inbox WHERE id = ?", (task_id,)).fetchone()
|
|
53
|
+
if row is None:
|
|
54
|
+
raise HTTPException(status_code=404, detail=f"Task {task_id} not found")
|
|
55
|
+
return dict(row)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def _fetch_plan_row(conn: sqlite3.Connection, task_id: int) -> dict | None:
|
|
59
|
+
row = conn.execute(
|
|
60
|
+
"SELECT * FROM plans WHERE task_id = ? ORDER BY id DESC LIMIT 1", (task_id,)
|
|
61
|
+
).fetchone()
|
|
62
|
+
return dict(row) if row else None
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def _row_to_plan(row: dict) -> Plan:
|
|
66
|
+
"""Deserialise a plans table row into a Plan model."""
|
|
67
|
+
steps_raw = []
|
|
68
|
+
try:
|
|
69
|
+
yaml_content = row.get("yaml_content", "")
|
|
70
|
+
if yaml_content:
|
|
71
|
+
import yaml as _yaml
|
|
72
|
+
parsed = _yaml.safe_load(yaml_content) or {}
|
|
73
|
+
steps_raw = parsed.get("steps", [])
|
|
74
|
+
except Exception:
|
|
75
|
+
pass
|
|
76
|
+
|
|
77
|
+
steps = [PlanStep(**s) if isinstance(s, dict) else s for s in steps_raw]
|
|
78
|
+
return Plan(
|
|
79
|
+
id=row["id"],
|
|
80
|
+
task_id=row["task_id"],
|
|
81
|
+
steps=steps,
|
|
82
|
+
status=row.get("status", "draft"),
|
|
83
|
+
yaml_content=row.get("yaml_content", ""),
|
|
84
|
+
created_at=row.get("created_at"),
|
|
85
|
+
updated_at=row.get("updated_at"),
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def _upsert_plan(conn: sqlite3.Connection, task_id: int, yaml_content: str, steps: list[dict]) -> int:
|
|
90
|
+
"""Insert a new plan row (one plan per task, replaced on re-generation)."""
|
|
91
|
+
# Delete previous plan for this task so we always have a single current plan
|
|
92
|
+
conn.execute("DELETE FROM plans WHERE task_id = ?", (task_id,))
|
|
93
|
+
now = _now()
|
|
94
|
+
cursor = conn.execute(
|
|
95
|
+
"""
|
|
96
|
+
INSERT INTO plans (task_id, yaml_content, status, created_at, updated_at)
|
|
97
|
+
VALUES (?, ?, 'draft', ?, ?)
|
|
98
|
+
""",
|
|
99
|
+
(task_id, yaml_content, now, now),
|
|
100
|
+
)
|
|
101
|
+
conn.commit()
|
|
102
|
+
return cursor.lastrowid
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
# ---------------------------------------------------------------------------
|
|
106
|
+
# Routes
|
|
107
|
+
# ---------------------------------------------------------------------------
|
|
108
|
+
|
|
109
|
+
@router.post("/tasks/{task_id}/generate-plan")
|
|
110
|
+
async def generate_plan_for_task(task_id: int):
|
|
111
|
+
"""Generate a plan for a task using Claude CLI and persist it."""
|
|
112
|
+
conn = get_connection()
|
|
113
|
+
task = _fetch_task(conn, task_id)
|
|
114
|
+
capabilities = _load_capabilities()
|
|
115
|
+
|
|
116
|
+
# Run in a thread pool so we don't block the event loop during the
|
|
117
|
+
# potentially long Claude CLI subprocess call.
|
|
118
|
+
loop = asyncio.get_event_loop()
|
|
119
|
+
result = await loop.run_in_executor(
|
|
120
|
+
None, lambda: generate_plan(dict(task), capabilities)
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
if result.get("error") and not result.get("steps"):
|
|
124
|
+
raise HTTPException(status_code=502, detail=result["error"])
|
|
125
|
+
|
|
126
|
+
plan_id = _upsert_plan(conn, task_id, result.get("yaml_content", ""), result.get("steps", []))
|
|
127
|
+
plan_row = _fetch_plan_row(conn, task_id)
|
|
128
|
+
plan = _row_to_plan(plan_row)
|
|
129
|
+
|
|
130
|
+
return plan.model_dump()
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
@router.get("/tasks/{task_id}/plan")
|
|
134
|
+
async def get_plan(task_id: int):
|
|
135
|
+
"""Fetch the current plan for a task."""
|
|
136
|
+
conn = get_connection()
|
|
137
|
+
_fetch_task(conn, task_id) # 404 if task missing
|
|
138
|
+
plan_row = _fetch_plan_row(conn, task_id)
|
|
139
|
+
if plan_row is None:
|
|
140
|
+
return {"plan": None}
|
|
141
|
+
return _row_to_plan(plan_row).model_dump()
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
@router.post("/tasks/{task_id}/plan/steps/{step_id}/approve")
|
|
145
|
+
async def approve_step(task_id: int, step_id: int):
|
|
146
|
+
"""Approve a specific plan step."""
|
|
147
|
+
conn = get_connection()
|
|
148
|
+
_fetch_task(conn, task_id)
|
|
149
|
+
plan_row = _fetch_plan_row(conn, task_id)
|
|
150
|
+
if plan_row is None:
|
|
151
|
+
raise HTTPException(status_code=404, detail="No plan found for this task")
|
|
152
|
+
|
|
153
|
+
import yaml as _yaml
|
|
154
|
+
yaml_content = plan_row.get("yaml_content", "")
|
|
155
|
+
plan_data = _yaml.safe_load(yaml_content) or {}
|
|
156
|
+
steps: list[dict] = plan_data.get("steps", [])
|
|
157
|
+
|
|
158
|
+
updated = False
|
|
159
|
+
for step in steps:
|
|
160
|
+
if step.get("id") == step_id:
|
|
161
|
+
step["status"] = "approved"
|
|
162
|
+
updated = True
|
|
163
|
+
break
|
|
164
|
+
|
|
165
|
+
if not updated:
|
|
166
|
+
raise HTTPException(status_code=404, detail=f"Step {step_id} not found in plan")
|
|
167
|
+
|
|
168
|
+
plan_data["steps"] = steps
|
|
169
|
+
new_yaml = _yaml.dump(plan_data, default_flow_style=False)
|
|
170
|
+
|
|
171
|
+
# Check if all steps are now approved → mark plan approved
|
|
172
|
+
all_approved = all(s.get("status") == "approved" for s in steps)
|
|
173
|
+
new_status = "approved" if all_approved else plan_row.get("status", "draft")
|
|
174
|
+
|
|
175
|
+
conn.execute(
|
|
176
|
+
"UPDATE plans SET yaml_content = ?, status = ?, updated_at = ? WHERE id = ?",
|
|
177
|
+
(new_yaml, new_status, _now(), plan_row["id"]),
|
|
178
|
+
)
|
|
179
|
+
conn.commit()
|
|
180
|
+
|
|
181
|
+
updated_row = _fetch_plan_row(conn, task_id)
|
|
182
|
+
return _row_to_plan(updated_row).model_dump()
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
@router.post("/tasks/{task_id}/plan/approve-all")
|
|
186
|
+
async def approve_all_steps(task_id: int):
|
|
187
|
+
"""Approve all low-risk steps at once."""
|
|
188
|
+
conn = get_connection()
|
|
189
|
+
_fetch_task(conn, task_id)
|
|
190
|
+
plan_row = _fetch_plan_row(conn, task_id)
|
|
191
|
+
if plan_row is None:
|
|
192
|
+
raise HTTPException(status_code=404, detail="No plan found for this task")
|
|
193
|
+
|
|
194
|
+
import yaml as _yaml
|
|
195
|
+
yaml_content = plan_row.get("yaml_content", "")
|
|
196
|
+
plan_data = _yaml.safe_load(yaml_content) or {}
|
|
197
|
+
steps: list[dict] = plan_data.get("steps", [])
|
|
198
|
+
|
|
199
|
+
for step in steps:
|
|
200
|
+
if step.get("risk_level", "low") == "low":
|
|
201
|
+
step["status"] = "approved"
|
|
202
|
+
|
|
203
|
+
plan_data["steps"] = steps
|
|
204
|
+
new_yaml = _yaml.dump(plan_data, default_flow_style=False)
|
|
205
|
+
|
|
206
|
+
all_approved = all(s.get("status") == "approved" for s in steps)
|
|
207
|
+
new_status = "approved" if all_approved else plan_row.get("status", "draft")
|
|
208
|
+
|
|
209
|
+
conn.execute(
|
|
210
|
+
"UPDATE plans SET yaml_content = ?, status = ?, updated_at = ? WHERE id = ?",
|
|
211
|
+
(new_yaml, new_status, _now(), plan_row["id"]),
|
|
212
|
+
)
|
|
213
|
+
conn.commit()
|
|
214
|
+
|
|
215
|
+
updated_row = _fetch_plan_row(conn, task_id)
|
|
216
|
+
return _row_to_plan(updated_row).model_dump()
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
@router.get("/tasks/{task_id}/plan-stream")
|
|
220
|
+
async def plan_stream(task_id: int):
|
|
221
|
+
"""
|
|
222
|
+
SSE endpoint that streams plan generation output in real time.
|
|
223
|
+
|
|
224
|
+
Emits:
|
|
225
|
+
- data: {"type": "chunk", "text": "..."} — incremental output
|
|
226
|
+
- data: {"type": "done", "plan": {...}} — final plan after storage
|
|
227
|
+
- data: {"type": "error", "message": "..."}
|
|
228
|
+
"""
|
|
229
|
+
conn = get_connection()
|
|
230
|
+
task = _fetch_task(conn, task_id)
|
|
231
|
+
capabilities = _load_capabilities()
|
|
232
|
+
|
|
233
|
+
async def event_generator():
|
|
234
|
+
try:
|
|
235
|
+
yield _sse({"type": "chunk", "text": "Starting plan generation...\n"})
|
|
236
|
+
yield _sse({"type": "chunk", "text": f"Task: {task['title']}\n"})
|
|
237
|
+
yield _sse({"type": "chunk", "text": "Invoking Claude CLI...\n"})
|
|
238
|
+
|
|
239
|
+
loop = asyncio.get_event_loop()
|
|
240
|
+
result = await loop.run_in_executor(
|
|
241
|
+
None, lambda: generate_plan(dict(task), capabilities)
|
|
242
|
+
)
|
|
243
|
+
|
|
244
|
+
if result.get("error") and not result.get("steps"):
|
|
245
|
+
yield _sse({"type": "error", "message": result["error"]})
|
|
246
|
+
return
|
|
247
|
+
|
|
248
|
+
yield _sse({"type": "chunk", "text": f"Plan generated with {len(result.get('steps', []))} steps.\n"})
|
|
249
|
+
|
|
250
|
+
plan_id = _upsert_plan(conn, task_id, result.get("yaml_content", ""), result.get("steps", []))
|
|
251
|
+
plan_row = _fetch_plan_row(conn, task_id)
|
|
252
|
+
plan = _row_to_plan(plan_row)
|
|
253
|
+
|
|
254
|
+
yield _sse({"type": "done", "plan": plan.model_dump()})
|
|
255
|
+
|
|
256
|
+
except Exception as exc:
|
|
257
|
+
yield _sse({"type": "error", "message": str(exc)})
|
|
258
|
+
|
|
259
|
+
return StreamingResponse(
|
|
260
|
+
event_generator(),
|
|
261
|
+
media_type="text/event-stream",
|
|
262
|
+
headers={
|
|
263
|
+
"Cache-Control": "no-cache",
|
|
264
|
+
"X-Accel-Buffering": "no",
|
|
265
|
+
},
|
|
266
|
+
)
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
def _sse(data: dict) -> str:
|
|
270
|
+
"""Format a dict as a Server-Sent Event frame."""
|
|
271
|
+
return f"data: {json.dumps(data)}\n\n"
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Generates ~/Library/LaunchAgents/com.ftm.inbox.plist
|
|
5
|
+
* Runs ftm-inbox on login (macOS only).
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { existsSync, mkdirSync, writeFileSync } from "fs";
|
|
9
|
+
import { join } from "path";
|
|
10
|
+
import { homedir, platform } from "os";
|
|
11
|
+
import { execSync } from "child_process";
|
|
12
|
+
import { fileURLToPath } from "url";
|
|
13
|
+
import { dirname } from "path";
|
|
14
|
+
|
|
15
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
16
|
+
const __dirname = dirname(__filename);
|
|
17
|
+
|
|
18
|
+
const HOME = homedir();
|
|
19
|
+
const LAUNCH_AGENTS_DIR = join(HOME, "Library", "LaunchAgents");
|
|
20
|
+
const PLIST_PATH = join(LAUNCH_AGENTS_DIR, "com.ftm.inbox.plist");
|
|
21
|
+
const INBOX_CONFIG_DIR = join(HOME, ".claude", "ftm-inbox");
|
|
22
|
+
const START_SCRIPT = join(__dirname, "start.sh");
|
|
23
|
+
|
|
24
|
+
function ensureDir(dir) {
|
|
25
|
+
if (!existsSync(dir)) {
|
|
26
|
+
mkdirSync(dir, { recursive: true });
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function buildPlist(startScript, logDir) {
|
|
31
|
+
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
32
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
33
|
+
<plist version="1.0">
|
|
34
|
+
<dict>
|
|
35
|
+
<key>Label</key>
|
|
36
|
+
<string>com.ftm.inbox</string>
|
|
37
|
+
|
|
38
|
+
<key>ProgramArguments</key>
|
|
39
|
+
<array>
|
|
40
|
+
<string>/bin/bash</string>
|
|
41
|
+
<string>${startScript}</string>
|
|
42
|
+
</array>
|
|
43
|
+
|
|
44
|
+
<key>RunAtLoad</key>
|
|
45
|
+
<true/>
|
|
46
|
+
|
|
47
|
+
<key>KeepAlive</key>
|
|
48
|
+
<false/>
|
|
49
|
+
|
|
50
|
+
<key>StandardOutPath</key>
|
|
51
|
+
<string>${join(logDir, "launchd-stdout.log")}</string>
|
|
52
|
+
|
|
53
|
+
<key>StandardErrorPath</key>
|
|
54
|
+
<string>${join(logDir, "launchd-stderr.log")}</string>
|
|
55
|
+
|
|
56
|
+
<key>WorkingDirectory</key>
|
|
57
|
+
<string>${dirname(dirname(startScript))}</string>
|
|
58
|
+
</dict>
|
|
59
|
+
</plist>
|
|
60
|
+
`;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function main() {
|
|
64
|
+
if (platform() !== "darwin") {
|
|
65
|
+
console.error("LaunchAgent setup is macOS-only.");
|
|
66
|
+
process.exit(1);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const logDir = join(INBOX_CONFIG_DIR, "logs");
|
|
70
|
+
|
|
71
|
+
ensureDir(LAUNCH_AGENTS_DIR);
|
|
72
|
+
ensureDir(logDir);
|
|
73
|
+
|
|
74
|
+
const plistContent = buildPlist(START_SCRIPT, logDir);
|
|
75
|
+
writeFileSync(PLIST_PATH, plistContent, "utf8");
|
|
76
|
+
|
|
77
|
+
console.log("LaunchAgent written to:", PLIST_PATH);
|
|
78
|
+
console.log("Logs will be written to:", logDir);
|
|
79
|
+
|
|
80
|
+
// Load it immediately
|
|
81
|
+
try {
|
|
82
|
+
execSync(`launchctl load "${PLIST_PATH}"`, { stdio: "inherit" });
|
|
83
|
+
console.log("LaunchAgent loaded. ftm-inbox will start on next login.");
|
|
84
|
+
console.log("To start it now: launchctl start com.ftm.inbox");
|
|
85
|
+
} catch (err) {
|
|
86
|
+
console.warn("Could not load LaunchAgent automatically:", err.message);
|
|
87
|
+
console.warn("Run manually: launchctl load", PLIST_PATH);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
main();
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* ftm-inbox setup wizard
|
|
5
|
+
* Prompts for credentials and writes ~/.claude/ftm-inbox/config.yml
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { createInterface } from "readline";
|
|
9
|
+
import { existsSync, mkdirSync, writeFileSync } from "fs";
|
|
10
|
+
import { join } from "path";
|
|
11
|
+
import { homedir } from "os";
|
|
12
|
+
|
|
13
|
+
const HOME = homedir();
|
|
14
|
+
const INBOX_CONFIG_DIR = join(HOME, ".claude", "ftm-inbox");
|
|
15
|
+
const CONFIG_FILE = join(INBOX_CONFIG_DIR, "config.yml");
|
|
16
|
+
|
|
17
|
+
const rl = createInterface({
|
|
18
|
+
input: process.stdin,
|
|
19
|
+
output: process.stdout,
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
function ask(question, defaultValue = "") {
|
|
23
|
+
return new Promise((resolve) => {
|
|
24
|
+
const prompt = defaultValue ? `${question} [${defaultValue}]: ` : `${question}: `;
|
|
25
|
+
rl.question(prompt, (answer) => {
|
|
26
|
+
resolve(answer.trim() || defaultValue);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function askSecret(question) {
|
|
32
|
+
return new Promise((resolve) => {
|
|
33
|
+
process.stdout.write(`${question}: `);
|
|
34
|
+
// Note: readline doesn't natively hide input; use as-is for terminal environments
|
|
35
|
+
rl.question("", (answer) => {
|
|
36
|
+
resolve(answer.trim());
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function ensureDir(dir) {
|
|
42
|
+
if (!existsSync(dir)) {
|
|
43
|
+
mkdirSync(dir, { recursive: true });
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function buildConfig(answers) {
|
|
48
|
+
const lines = ["# ftm-inbox configuration", "# Generated by ftm-inbox setup wizard", ""];
|
|
49
|
+
|
|
50
|
+
lines.push("server:");
|
|
51
|
+
lines.push(` port: ${answers.port}`);
|
|
52
|
+
lines.push("");
|
|
53
|
+
|
|
54
|
+
if (answers.jiraBaseUrl || answers.jiraEmail || answers.jiraApiToken) {
|
|
55
|
+
lines.push("adapters:");
|
|
56
|
+
lines.push(" jira:");
|
|
57
|
+
lines.push(` enabled: ${!!(answers.jiraBaseUrl && answers.jiraEmail && answers.jiraApiToken)}`);
|
|
58
|
+
lines.push(` base_url: "${answers.jiraBaseUrl}"`);
|
|
59
|
+
lines.push(` email: "${answers.jiraEmail}"`);
|
|
60
|
+
lines.push(` api_token: "${answers.jiraApiToken}"`);
|
|
61
|
+
lines.push(` poll_interval_seconds: 60`);
|
|
62
|
+
lines.push("");
|
|
63
|
+
} else {
|
|
64
|
+
lines.push("adapters:");
|
|
65
|
+
lines.push(" jira:");
|
|
66
|
+
lines.push(" enabled: false");
|
|
67
|
+
lines.push(` base_url: ""`);
|
|
68
|
+
lines.push(` email: ""`);
|
|
69
|
+
lines.push(` api_token: ""`);
|
|
70
|
+
lines.push(` poll_interval_seconds: 60`);
|
|
71
|
+
lines.push("");
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
lines.push(" freshservice:");
|
|
75
|
+
lines.push(` enabled: ${!!(answers.freshserviceDomain && answers.freshserviceApiKey)}`);
|
|
76
|
+
lines.push(` domain: "${answers.freshserviceDomain}"`);
|
|
77
|
+
lines.push(` api_key: "${answers.freshserviceApiKey}"`);
|
|
78
|
+
lines.push(` poll_interval_seconds: 120`);
|
|
79
|
+
lines.push("");
|
|
80
|
+
|
|
81
|
+
lines.push(" slack:");
|
|
82
|
+
lines.push(` enabled: ${!!answers.slackBotToken}`);
|
|
83
|
+
lines.push(` bot_token: "${answers.slackBotToken}"`);
|
|
84
|
+
lines.push(` poll_interval_seconds: 30`);
|
|
85
|
+
lines.push("");
|
|
86
|
+
|
|
87
|
+
lines.push(" gmail:");
|
|
88
|
+
lines.push(` enabled: ${!!answers.gmailCredentialsPath}`);
|
|
89
|
+
lines.push(` credentials_path: "${answers.gmailCredentialsPath}"`);
|
|
90
|
+
lines.push(` poll_interval_seconds: 120`);
|
|
91
|
+
lines.push("");
|
|
92
|
+
|
|
93
|
+
lines.push("database:");
|
|
94
|
+
lines.push(` path: "${join(INBOX_CONFIG_DIR, "inbox.db")}"`);
|
|
95
|
+
lines.push("");
|
|
96
|
+
|
|
97
|
+
lines.push("logging:");
|
|
98
|
+
lines.push(` level: "INFO"`);
|
|
99
|
+
lines.push(` path: "${join(INBOX_CONFIG_DIR, "logs")}"`);
|
|
100
|
+
|
|
101
|
+
return lines.join("\n");
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
async function main() {
|
|
105
|
+
console.log("");
|
|
106
|
+
console.log("ftm-inbox Setup Wizard");
|
|
107
|
+
console.log("======================");
|
|
108
|
+
console.log("This will configure your inbox service credentials.");
|
|
109
|
+
console.log("Credentials are stored in ~/.claude/ftm-inbox/config.yml (gitignored).");
|
|
110
|
+
console.log("");
|
|
111
|
+
|
|
112
|
+
const answers = {};
|
|
113
|
+
|
|
114
|
+
// Port
|
|
115
|
+
answers.port = await ask("Port number", "8042");
|
|
116
|
+
|
|
117
|
+
// Jira
|
|
118
|
+
console.log("");
|
|
119
|
+
console.log("--- Jira (leave blank to skip) ---");
|
|
120
|
+
answers.jiraBaseUrl = await ask("Jira base URL (e.g. https://yourorg.atlassian.net)");
|
|
121
|
+
if (answers.jiraBaseUrl) {
|
|
122
|
+
answers.jiraEmail = await ask("Jira email");
|
|
123
|
+
answers.jiraApiToken = await askSecret("Jira API token");
|
|
124
|
+
} else {
|
|
125
|
+
answers.jiraEmail = "";
|
|
126
|
+
answers.jiraApiToken = "";
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// Freshservice
|
|
130
|
+
console.log("");
|
|
131
|
+
console.log("--- Freshservice (leave blank to skip) ---");
|
|
132
|
+
answers.freshserviceDomain = await ask("Freshservice domain (e.g. yourorg.freshservice.com)");
|
|
133
|
+
if (answers.freshserviceDomain) {
|
|
134
|
+
answers.freshserviceApiKey = await askSecret("Freshservice API key");
|
|
135
|
+
} else {
|
|
136
|
+
answers.freshserviceApiKey = "";
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// Slack
|
|
140
|
+
console.log("");
|
|
141
|
+
console.log("--- Slack (leave blank to skip) ---");
|
|
142
|
+
answers.slackBotToken = await askSecret("Slack bot token (xoxb-...)");
|
|
143
|
+
|
|
144
|
+
// Gmail
|
|
145
|
+
console.log("");
|
|
146
|
+
console.log("--- Gmail (leave blank to skip) ---");
|
|
147
|
+
answers.gmailCredentialsPath = await ask(
|
|
148
|
+
"Gmail credentials JSON path (e.g. ~/credentials.json)"
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
rl.close();
|
|
152
|
+
|
|
153
|
+
// Validate at least one adapter
|
|
154
|
+
const hasJira = !!(answers.jiraBaseUrl && answers.jiraEmail && answers.jiraApiToken);
|
|
155
|
+
const hasFreshservice = !!(answers.freshserviceDomain && answers.freshserviceApiKey);
|
|
156
|
+
const hasSlack = !!answers.slackBotToken;
|
|
157
|
+
const hasGmail = !!answers.gmailCredentialsPath;
|
|
158
|
+
|
|
159
|
+
if (!hasJira && !hasFreshservice && !hasSlack && !hasGmail) {
|
|
160
|
+
console.log("");
|
|
161
|
+
console.error("ERROR: At least one adapter must have credentials configured.");
|
|
162
|
+
console.error("Re-run setup and provide credentials for at least one service.");
|
|
163
|
+
process.exit(1);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Write config
|
|
167
|
+
ensureDir(INBOX_CONFIG_DIR);
|
|
168
|
+
ensureDir(join(INBOX_CONFIG_DIR, "logs"));
|
|
169
|
+
|
|
170
|
+
const configContent = buildConfig(answers);
|
|
171
|
+
writeFileSync(CONFIG_FILE, configContent, "utf8");
|
|
172
|
+
|
|
173
|
+
console.log("");
|
|
174
|
+
console.log("Configuration written to:", CONFIG_FILE);
|
|
175
|
+
console.log("");
|
|
176
|
+
console.log("Enabled adapters:");
|
|
177
|
+
if (hasJira) console.log(" - Jira");
|
|
178
|
+
if (hasFreshservice) console.log(" - Freshservice");
|
|
179
|
+
if (hasSlack) console.log(" - Slack");
|
|
180
|
+
if (hasGmail) console.log(" - Gmail");
|
|
181
|
+
console.log("");
|
|
182
|
+
console.log("Start the service with: ftm-inbox/bin/start.sh");
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
main().catch((err) => {
|
|
186
|
+
console.error("Setup failed:", err.message);
|
|
187
|
+
process.exit(1);
|
|
188
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# Start ftm-inbox backend + pollers
|
|
3
|
+
cd "$(dirname "$0")/.."
|
|
4
|
+
PORT=${FTM_INBOX_PORT:-8042}
|
|
5
|
+
echo "Starting ftm-inbox on port $PORT..."
|
|
6
|
+
python3 -m uvicorn backend.main:app --host 0.0.0.0 --port $PORT &
|
|
7
|
+
BACKEND_PID=$!
|
|
8
|
+
echo "Backend PID: $BACKEND_PID"
|
|
9
|
+
echo $BACKEND_PID > /tmp/ftm-inbox.pid
|
|
10
|
+
echo "ftm-inbox running. Stop with: ftm-inbox/bin/stop.sh"
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
if [ -f /tmp/ftm-inbox.pid ] && kill -0 $(cat /tmp/ftm-inbox.pid) 2>/dev/null; then
|
|
3
|
+
echo "ftm-inbox is running (PID: $(cat /tmp/ftm-inbox.pid))"
|
|
4
|
+
# Show last poll times from DB if available
|
|
5
|
+
CONFIG_DIR="$HOME/.claude/ftm-inbox"
|
|
6
|
+
DB_PATH="$CONFIG_DIR/inbox.db"
|
|
7
|
+
if [ -f "$DB_PATH" ] && command -v sqlite3 &>/dev/null; then
|
|
8
|
+
echo ""
|
|
9
|
+
echo "Last poll times:"
|
|
10
|
+
sqlite3 "$DB_PATH" "SELECT adapter, MAX(fetched_at) FROM inbox_items GROUP BY adapter;" 2>/dev/null | \
|
|
11
|
+
while IFS='|' read -r adapter ts; do
|
|
12
|
+
echo " $adapter: $ts"
|
|
13
|
+
done
|
|
14
|
+
fi
|
|
15
|
+
else
|
|
16
|
+
echo "ftm-inbox is not running."
|
|
17
|
+
fi
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# ftm-inbox configuration
|
|
2
|
+
#
|
|
3
|
+
# Copy this file to config.yml and fill in your credentials.
|
|
4
|
+
# The adapter registry loads this on startup. Missing config.yml is
|
|
5
|
+
# non-fatal — the backend starts with no adapters registered.
|
|
6
|
+
#
|
|
7
|
+
# Each adapter entry:
|
|
8
|
+
# name : unique identifier, used as inbox.source value
|
|
9
|
+
# class : dotted Python path to the adapter class
|
|
10
|
+
# interval_seconds : how often the poller runs (scheduler not yet wired — reserved)
|
|
11
|
+
# credentials : secrets (API tokens, passwords) — keep out of version control
|
|
12
|
+
# config : non-secret settings (URLs, project keys, etc.)
|
|
13
|
+
|
|
14
|
+
adapters:
|
|
15
|
+
- name: jira
|
|
16
|
+
class: ftm_inbox.adapters.jira.JiraAdapter
|
|
17
|
+
interval_seconds: 60
|
|
18
|
+
credentials:
|
|
19
|
+
api_token: "your-jira-api-token-here"
|
|
20
|
+
email: "you@yourorg.com"
|
|
21
|
+
config:
|
|
22
|
+
base_url: "https://yourorg.atlassian.net"
|
|
23
|
+
project_key: "OPS"
|
|
24
|
+
max_results: 100
|
|
25
|
+
jql: "project = OPS AND statusCategory != Done ORDER BY updated DESC"
|
|
26
|
+
|
|
27
|
+
- name: freshservice
|
|
28
|
+
class: ftm_inbox.adapters.freshservice.FreshserviceAdapter
|
|
29
|
+
interval_seconds: 90
|
|
30
|
+
credentials:
|
|
31
|
+
api_key: "your-freshservice-api-key-here"
|
|
32
|
+
config:
|
|
33
|
+
domain: "yourorg.freshservice.com"
|
|
34
|
+
per_page: 100
|
|
35
|
+
|
|
36
|
+
- name: slack
|
|
37
|
+
class: ftm_inbox.adapters.slack.SlackAdapter
|
|
38
|
+
interval_seconds: 30
|
|
39
|
+
credentials:
|
|
40
|
+
bot_token: "xoxb-your-slack-bot-token"
|
|
41
|
+
config:
|
|
42
|
+
channels:
|
|
43
|
+
- "C0123456789" # ops-alerts
|
|
44
|
+
- "C0987654321" # triage
|
|
45
|
+
lookback_hours: 24
|
|
46
|
+
|
|
47
|
+
- name: gmail
|
|
48
|
+
class: ftm_inbox.adapters.gmail.GmailAdapter
|
|
49
|
+
interval_seconds: 120
|
|
50
|
+
credentials:
|
|
51
|
+
credentials_json_path: "~/.config/ftm-inbox/gmail-credentials.json"
|
|
52
|
+
token_path: "~/.config/ftm-inbox/gmail-token.json"
|
|
53
|
+
config:
|
|
54
|
+
label_filter: "ftm-inbox"
|
|
55
|
+
max_results: 50
|