@schilderlabs/pitown-core 0.2.1 → 0.2.6

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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tasks-BfQm-7-O.mjs","names":["writeJson"],"sources":["../src/events.ts","../src/agents.ts","../src/tasks.ts"],"sourcesContent":["import { mkdirSync, readFileSync, writeFileSync } from \"node:fs\"\nimport { dirname } from \"node:path\"\n\nexport function appendJsonl(filePath: string, value: unknown) {\n\tmkdirSync(dirname(filePath), { recursive: true })\n\twriteFileSync(filePath, `${JSON.stringify(value)}\\n`, { encoding: \"utf-8\", flag: \"a\" })\n}\n\nexport function readJsonl<T>(filePath: string): T[] {\n\ttry {\n\t\tconst raw = readFileSync(filePath, \"utf-8\")\n\t\treturn raw\n\t\t\t.split(/\\r?\\n/)\n\t\t\t.map((line) => line.trim())\n\t\t\t.filter(Boolean)\n\t\t\t.map((line) => JSON.parse(line) as T)\n\t} catch {\n\t\treturn []\n\t}\n}\n","import { existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from \"node:fs\"\nimport { dirname, join } from \"node:path\"\nimport { appendJsonl, readJsonl } from \"./events.js\"\nimport type {\n\tAgentMailbox,\n\tAgentMessageRecord,\n\tAgentSessionRecord,\n\tAgentStateSnapshot,\n\tAgentStatus,\n} from \"./types.js\"\n\nfunction writeJson(path: string, value: unknown) {\n\tmkdirSync(dirname(path), { recursive: true })\n\twriteFileSync(path, `${JSON.stringify(value, null, 2)}\\n`, \"utf-8\")\n}\n\nfunction ensureMailbox(path: string) {\n\tmkdirSync(dirname(path), { recursive: true })\n\tif (!existsSync(path)) writeFileSync(path, \"\", \"utf-8\")\n}\n\nexport function getAgentsDir(artifactsDir: string): string {\n\treturn join(artifactsDir, \"agents\")\n}\n\nexport function getAgentDir(artifactsDir: string, agentId: string): string {\n\treturn join(getAgentsDir(artifactsDir), agentId)\n}\n\nexport function getAgentStatePath(artifactsDir: string, agentId: string): string {\n\treturn join(getAgentDir(artifactsDir, agentId), \"state.json\")\n}\n\nexport function getAgentSessionPath(artifactsDir: string, agentId: string): string {\n\treturn join(getAgentDir(artifactsDir, agentId), \"session.json\")\n}\n\nexport function getAgentMailboxPath(artifactsDir: string, agentId: string, box: AgentMailbox): string {\n\treturn join(getAgentDir(artifactsDir, agentId), `${box}.jsonl`)\n}\n\nexport function getAgentSessionsDir(artifactsDir: string, agentId: string): string {\n\treturn join(getAgentDir(artifactsDir, agentId), \"sessions\")\n}\n\nexport function getSessionIdFromPath(sessionPath: string | null | undefined): string | null {\n\tif (!sessionPath) return null\n\tconst match = /_([0-9a-f-]+)\\.jsonl$/i.exec(sessionPath)\n\treturn match?.[1] ?? null\n}\n\nexport function createAgentSessionRecord(\n\tinput?: Partial<Pick<AgentSessionRecord, \"sessionDir\" | \"sessionId\" | \"sessionPath\" | \"processId\" | \"lastAttachedAt\">>,\n): AgentSessionRecord {\n\treturn {\n\t\truntime: \"pi\",\n\t\tpersisted: true,\n\t\tsessionDir: input?.sessionDir ?? null,\n\t\tsessionId: input?.sessionId ?? null,\n\t\tsessionPath: input?.sessionPath ?? null,\n\t\tprocessId: input?.processId ?? null,\n\t\tlastAttachedAt: input?.lastAttachedAt ?? null,\n\t}\n}\n\nexport function createAgentState(input: {\n\tagentId: string\n\trole: string\n\tstatus: AgentStatus\n\ttaskId?: string | null\n\ttask?: string | null\n\tbranch?: string | null\n\tlastMessage?: string | null\n\twaitingOn?: string | null\n\tblocked?: boolean\n\trunId?: string | null\n\tsession?: AgentSessionRecord\n}): AgentStateSnapshot {\n\treturn {\n\t\tagentId: input.agentId,\n\t\trole: input.role,\n\t\tstatus: input.status,\n\t\ttaskId: input.taskId ?? null,\n\t\ttask: input.task ?? null,\n\t\tbranch: input.branch ?? null,\n\t\tupdatedAt: new Date().toISOString(),\n\t\tlastMessage: input.lastMessage ?? null,\n\t\twaitingOn: input.waitingOn ?? null,\n\t\tblocked: input.blocked ?? false,\n\t\trunId: input.runId ?? null,\n\t\tsession: input.session ?? createAgentSessionRecord(),\n\t}\n}\n\nexport function writeAgentState(artifactsDir: string, state: AgentStateSnapshot) {\n\tmkdirSync(getAgentDir(artifactsDir, state.agentId), { recursive: true })\n\tensureMailbox(getAgentMailboxPath(artifactsDir, state.agentId, \"inbox\"))\n\tensureMailbox(getAgentMailboxPath(artifactsDir, state.agentId, \"outbox\"))\n\twriteJson(getAgentStatePath(artifactsDir, state.agentId), state)\n\twriteJson(getAgentSessionPath(artifactsDir, state.agentId), state.session)\n}\n\nexport function readAgentState(artifactsDir: string, agentId: string): AgentStateSnapshot | null {\n\tconst statePath = getAgentStatePath(artifactsDir, agentId)\n\ttry {\n\t\treturn JSON.parse(readFileSync(statePath, \"utf-8\")) as AgentStateSnapshot\n\t} catch {\n\t\treturn null\n\t}\n}\n\nexport function listAgentStates(artifactsDir: string): AgentStateSnapshot[] {\n\tconst agentsDir = getAgentsDir(artifactsDir)\n\tlet entries: string[]\n\ttry {\n\t\tentries = readdirSync(agentsDir)\n\t} catch {\n\t\treturn []\n\t}\n\n\treturn entries\n\t\t.map((entry) => readAgentState(artifactsDir, entry))\n\t\t.filter((state): state is AgentStateSnapshot => state !== null)\n\t\t.sort((left, right) => left.agentId.localeCompare(right.agentId))\n}\n\nexport function appendAgentMessage(input: {\n\tartifactsDir: string\n\tagentId: string\n\tbox: AgentMailbox\n\tfrom: string\n\tbody: string\n}): AgentMessageRecord {\n\tconst record: AgentMessageRecord = {\n\t\tbox: input.box,\n\t\tfrom: input.from,\n\t\tbody: input.body,\n\t\tcreatedAt: new Date().toISOString(),\n\t}\n\tappendJsonl(getAgentMailboxPath(input.artifactsDir, input.agentId, input.box), record)\n\treturn record\n}\n\nexport function readAgentMessages(artifactsDir: string, agentId: string, box: AgentMailbox): AgentMessageRecord[] {\n\treturn readJsonl<AgentMessageRecord>(getAgentMailboxPath(artifactsDir, agentId, box))\n}\n\nexport function getLatestAgentSession(artifactsDir: string, agentId: string): AgentSessionRecord {\n\tconst sessionDir = getAgentSessionsDir(artifactsDir, agentId)\n\tlet entries: string[]\n\ttry {\n\t\tentries = readdirSync(sessionDir)\n\t} catch {\n\t\treturn createAgentSessionRecord({ sessionDir })\n\t}\n\n\tconst latestSessionPath =\n\t\tentries\n\t\t\t.filter((entry) => entry.endsWith(\".jsonl\"))\n\t\t\t.sort()\n\t\t\t.at(-1) ?? null\n\n\tif (latestSessionPath === null) return createAgentSessionRecord({ sessionDir })\n\n\tconst sessionPath = join(sessionDir, latestSessionPath)\n\treturn createAgentSessionRecord({\n\t\tsessionDir,\n\t\tsessionPath,\n\t\tsessionId: getSessionIdFromPath(sessionPath),\n\t})\n}\n","import { mkdirSync, readFileSync, readdirSync, writeFileSync } from \"node:fs\"\nimport { dirname, join } from \"node:path\"\nimport type { TaskRecord, TaskStatus } from \"./types.js\"\n\nfunction writeJson(path: string, value: unknown) {\n\tmkdirSync(dirname(path), { recursive: true })\n\twriteFileSync(path, `${JSON.stringify(value, null, 2)}\\n`, \"utf-8\")\n}\n\nexport function getTasksDir(artifactsDir: string): string {\n\treturn join(artifactsDir, \"tasks\")\n}\n\nexport function getTaskPath(artifactsDir: string, taskId: string): string {\n\treturn join(getTasksDir(artifactsDir), `${taskId}.json`)\n}\n\nexport function createTaskRecord(input: {\n\ttaskId: string\n\ttitle: string\n\tstatus: TaskStatus\n\trole: string\n\tassignedAgentId: string\n\tcreatedBy: string\n}): TaskRecord {\n\tconst now = new Date().toISOString()\n\treturn {\n\t\ttaskId: input.taskId,\n\t\ttitle: input.title,\n\t\tstatus: input.status,\n\t\trole: input.role,\n\t\tassignedAgentId: input.assignedAgentId,\n\t\tcreatedBy: input.createdBy,\n\t\tcreatedAt: now,\n\t\tupdatedAt: now,\n\t}\n}\n\nexport function writeTaskRecord(artifactsDir: string, task: TaskRecord) {\n\twriteJson(getTaskPath(artifactsDir, task.taskId), task)\n}\n\nexport function updateTaskRecordStatus(artifactsDir: string, taskId: string, status: TaskStatus): TaskRecord | null {\n\tconst task = readTaskRecord(artifactsDir, taskId)\n\tif (task === null) return null\n\n\tconst updatedTask: TaskRecord = {\n\t\t...task,\n\t\tstatus,\n\t\tupdatedAt: new Date().toISOString(),\n\t}\n\twriteTaskRecord(artifactsDir, updatedTask)\n\treturn updatedTask\n}\n\nexport function readTaskRecord(artifactsDir: string, taskId: string): TaskRecord | null {\n\tconst path = getTaskPath(artifactsDir, taskId)\n\ttry {\n\t\treturn JSON.parse(readFileSync(path, \"utf-8\")) as TaskRecord\n\t} catch {\n\t\treturn null\n\t}\n}\n\nexport function listTaskRecords(artifactsDir: string): TaskRecord[] {\n\tconst tasksDir = getTasksDir(artifactsDir)\n\tlet entries: string[]\n\ttry {\n\t\tentries = readdirSync(tasksDir)\n\t} catch {\n\t\treturn []\n\t}\n\n\treturn entries\n\t\t.filter((entry) => entry.endsWith(\".json\"))\n\t\t.map((entry) => readTaskRecord(artifactsDir, entry.replace(/\\.json$/, \"\")))\n\t\t.filter((task): task is TaskRecord => task !== null)\n\t\t.sort((left, right) => left.taskId.localeCompare(right.taskId))\n}\n"],"mappings":";;;;AAGA,SAAgB,YAAY,UAAkB,OAAgB;AAC7D,WAAU,QAAQ,SAAS,EAAE,EAAE,WAAW,MAAM,CAAC;AACjD,eAAc,UAAU,GAAG,KAAK,UAAU,MAAM,CAAC,KAAK;EAAE,UAAU;EAAS,MAAM;EAAK,CAAC;;AAGxF,SAAgB,UAAa,UAAuB;AACnD,KAAI;AAEH,SADY,aAAa,UAAU,QAAQ,CAEzC,MAAM,QAAQ,CACd,KAAK,SAAS,KAAK,MAAM,CAAC,CAC1B,OAAO,QAAQ,CACf,KAAK,SAAS,KAAK,MAAM,KAAK,CAAM;SAC/B;AACP,SAAO,EAAE;;;;;;ACNX,SAASA,YAAU,MAAc,OAAgB;AAChD,WAAU,QAAQ,KAAK,EAAE,EAAE,WAAW,MAAM,CAAC;AAC7C,eAAc,MAAM,GAAG,KAAK,UAAU,OAAO,MAAM,EAAE,CAAC,KAAK,QAAQ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cAAsB,QAAmC;CACvF,MAAM,OAAO,YAAY,cAAc,OAAO;AAC9C,KAAI;AACH,SAAO,KAAK,MAAM,aAAa,MAAM,QAAQ,CAAC;SACvC;AACP,SAAO;;;AAIT,SAAgB,gBAAgB,cAAoC;CACnE,MAAM,WAAW,YAAY,aAAa;CAC1C,IAAI;AACJ,KAAI;AACH,YAAU,YAAY,SAAS;SACxB;AACP,SAAO,EAAE;;AAGV,QAAO,QACL,QAAQ,UAAU,MAAM,SAAS,QAAQ,CAAC,CAC1C,KAAK,UAAU,eAAe,cAAc,MAAM,QAAQ,WAAW,GAAG,CAAC,CAAC,CAC1E,QAAQ,SAA6B,SAAS,KAAK,CACnD,MAAM,MAAM,UAAU,KAAK,OAAO,cAAc,MAAM,OAAO,CAAC"}
package/package.json CHANGED
@@ -1,19 +1,14 @@
1
1
  {
2
2
  "name": "@schilderlabs/pitown-core",
3
- "version": "0.2.1",
4
- "description": "Core runtime primitives for Pi Town",
3
+ "version": "0.2.6",
5
4
  "type": "module",
5
+ "types": "./dist/index.d.mts",
6
6
  "exports": {
7
7
  ".": {
8
8
  "import": "./dist/index.mjs",
9
9
  "types": "./dist/index.d.mts"
10
10
  }
11
11
  },
12
- "types": "./dist/index.d.mts",
13
- "files": [
14
- "dist",
15
- "README.md"
16
- ],
17
12
  "engines": {
18
13
  "node": ">=24"
19
14
  },
@@ -23,24 +18,24 @@
23
18
  "typescript": "5.9.2",
24
19
  "vitest": "4.0.18"
25
20
  },
21
+ "bugs": "https://github.com/RobSchilderr/pitown/issues",
22
+ "description": "Core runtime primitives for Pi Town",
23
+ "files": [
24
+ "dist",
25
+ "README.md"
26
+ ],
27
+ "homepage": "https://github.com/RobSchilderr/pitown#readme",
26
28
  "keywords": [
27
- "pitown",
29
+ "night-shift",
28
30
  "orchestration",
29
- "runtime",
30
- "night-shift"
31
+ "pitown",
32
+ "runtime"
31
33
  ],
32
- "repository": {
33
- "type": "git",
34
- "url": "git+https://github.com/RobSchilderr/pitown.git"
35
- },
36
- "homepage": "https://github.com/RobSchilderr/pitown#readme",
37
- "bugs": {
38
- "url": "https://github.com/RobSchilderr/pitown/issues"
39
- },
34
+ "license": "MIT",
40
35
  "publishConfig": {
41
36
  "access": "public"
42
37
  },
43
- "license": "MIT",
38
+ "repository": "RobSchilderr/pitown.git",
44
39
  "scripts": {
45
40
  "build": "tsdown",
46
41
  "lint": "eslint .",