usegrunt 0.0.1 → 0.6.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/dist/store.js ADDED
@@ -0,0 +1,56 @@
1
+ import { createClient } from "@libsql/client";
2
+ import { randomUUID } from "node:crypto";
3
+ import { mkdirSync } from "node:fs";
4
+ import { dirname } from "node:path";
5
+ export class AgentStore {
6
+ db;
7
+ constructor(db) {
8
+ this.db = db;
9
+ }
10
+ static async open(url) {
11
+ if (url.startsWith("file:") && url !== "file::memory:")
12
+ mkdirSync(dirname(url.slice(5)), { recursive: true });
13
+ const db = createClient({ url: url === ":memory:" ? "file::memory:" : url });
14
+ await db.executeMultiple(`
15
+ PRAGMA journal_mode=WAL;
16
+ CREATE TABLE IF NOT EXISTS messages (id TEXT PRIMARY KEY, person TEXT NOT NULL, role TEXT NOT NULL, text TEXT NOT NULL, ts INTEGER NOT NULL);
17
+ CREATE INDEX IF NOT EXISTS messages_person ON messages(person, ts);
18
+ CREATE TABLE IF NOT EXISTS tasks (id TEXT PRIMARY KEY, person TEXT NOT NULL, title TEXT NOT NULL, brief TEXT NOT NULL, kind TEXT NOT NULL, status TEXT NOT NULL, model TEXT, route_reason TEXT, result TEXT, error TEXT, created_at INTEGER NOT NULL, updated_at INTEGER NOT NULL);
19
+ CREATE INDEX IF NOT EXISTS tasks_person ON tasks(person, created_at);
20
+ CREATE TABLE IF NOT EXISTS notes (person TEXT NOT NULL, text TEXT NOT NULL, ts INTEGER NOT NULL, UNIQUE(person, text));
21
+ CREATE TABLE IF NOT EXISTS calls (model TEXT NOT NULL, kind TEXT NOT NULL, tokens_in INTEGER NOT NULL, tokens_out INTEGER NOT NULL, latency_ms INTEGER NOT NULL, outcome TEXT NOT NULL, cost REAL NOT NULL, ts INTEGER NOT NULL);
22
+ UPDATE tasks SET status='failed', error='Gateway restarted before the task finished.', updated_at=${Date.now()} WHERE status IN ('queued','running');
23
+ `);
24
+ return new AgentStore(db);
25
+ }
26
+ async rows(sql, args = []) {
27
+ return (await this.db.execute({ sql, args })).rows;
28
+ }
29
+ async messages(person) { return (await this.rows("SELECT * FROM messages WHERE person=? ORDER BY rowid DESC LIMIT 20", [person])).reverse(); }
30
+ async tasks(person) { return this.rows("SELECT * FROM tasks WHERE person=? AND status IN ('queued','running') UNION ALL SELECT * FROM (SELECT * FROM tasks WHERE person=? AND status NOT IN ('queued','running') ORDER BY created_at DESC LIMIT 30)", [person, person]); }
31
+ async task(person, id) { return (await this.rows("SELECT * FROM tasks WHERE person=? AND id=?", [person, id]))[0]; }
32
+ async notes(person) { return this.rows("SELECT text,ts FROM notes WHERE person=? ORDER BY rowid DESC LIMIT 64", [person]); }
33
+ async calls() { return this.rows("SELECT * FROM calls ORDER BY rowid DESC LIMIT 500"); }
34
+ async message(person, role, text) {
35
+ const m = { id: randomUUID(), person, role, text, ts: Date.now() };
36
+ await this.db.execute({ sql: "INSERT INTO messages VALUES (?,?,?,?,?)", args: [m.id, person, role, text, m.ts] });
37
+ return m;
38
+ }
39
+ async remember(person, text) { await this.db.execute({ sql: "INSERT OR IGNORE INTO notes VALUES (?,?,?)", args: [person, text, Date.now()] }); }
40
+ async dispatch(person, title, brief, kind) {
41
+ const id = randomUUID(), now = Date.now();
42
+ await this.db.execute({ sql: "INSERT INTO tasks (id,person,title,brief,kind,status,created_at,updated_at) VALUES (?,?,?,?,?,'queued',?,?)", args: [id, person, title, brief, kind, now, now] });
43
+ return (await this.task(person, id));
44
+ }
45
+ async update(person, id, patch, from = ["queued", "running"]) {
46
+ const entries = Object.entries({ ...patch, updated_at: Date.now() });
47
+ await this.db.execute({ sql: `UPDATE tasks SET ${entries.map(([k]) => `${k}=?`).join(",")} WHERE person=? AND id=? AND status IN (${from.map(() => "?").join(",")})`, args: [...entries.map(([, v]) => v), person, id, ...from] });
48
+ return this.task(person, id);
49
+ }
50
+ async record(c) { await this.db.execute({ sql: "INSERT INTO calls VALUES (?,?,?,?,?,?,?,?)", args: [c.model, c.kind, c.tokens_in, c.tokens_out, c.latency_ms, c.outcome, c.cost, c.ts] }); }
51
+ async state(person) {
52
+ const [messages, tasks, notes] = await Promise.all([this.messages(person), this.tasks(person), this.notes(person)]);
53
+ return { messages, tasks, notes };
54
+ }
55
+ close() { this.db.close(); }
56
+ }
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,12 +1,53 @@
1
1
  {
2
2
  "name": "usegrunt",
3
- "version": "0.0.1",
4
- "description": "",
5
- "main": "index.js",
3
+ "version": "0.6.0",
4
+ "type": "module",
5
+ "engines": {
6
+ "node": ">=22"
7
+ },
8
+ "packageManager": "pnpm@10.34.5",
9
+ "pnpm": {
10
+ "onlyBuiltDependencies": [
11
+ "better-sqlite3@12.11.1"
12
+ ]
13
+ },
6
14
  "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1"
15
+ "dev": "tsx src/server.ts",
16
+ "build": "tsc && cp src/chat.html dist/chat.html && mkdir -p dist/registry && cp registry/adapters.json dist/registry/adapters.json",
17
+ "start": "node dist/server.js",
18
+ "test": "vitest run",
19
+ "lint": "eslint src && tsc --noEmit",
20
+ "local": "tsx src/local/main.ts"
21
+ },
22
+ "dependencies": {
23
+ "@clack/prompts": "^1.9.0",
24
+ "@hono/node-server": "^1.19.17",
25
+ "@libsql/client": "^0.18.0",
26
+ "@modelcontextprotocol/sdk": "^1.32.2",
27
+ "@trusty-squire/mcp": "1.1.39",
28
+ "@trusty-squire/sdk": "0.1.0",
29
+ "ajv": "^8.20.0",
30
+ "chalk": "^6.0.1",
31
+ "hono": "^4.13.8",
32
+ "ipaddr.js": "^2.5.0",
33
+ "standardwebhooks": "^1.1.1"
34
+ },
35
+ "devDependencies": {
36
+ "@types/node": "^22.20.3",
37
+ "eslint": "^9.39.5",
38
+ "tsx": "^4.19.2",
39
+ "typescript": "^5.9.3",
40
+ "typescript-eslint": "^8.70.0",
41
+ "vitest": "^3.2.7"
42
+ },
43
+ "bin": {
44
+ "usegrunt": "dist/local/main.js",
45
+ "milo": "dist/local/main.js",
46
+ "milo-local": "dist/local/main.js"
8
47
  },
9
- "keywords": [],
10
- "author": "",
11
- "license": "ISC"
48
+ "description": "One-command setup for grunt",
49
+ "files": [
50
+ "dist",
51
+ "README.md"
52
+ ]
12
53
  }