portable-agent-layer 0.70.0 → 0.72.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 (81) hide show
  1. package/README.md +5 -1
  2. package/assets/schema/pal-settings.schema.json +4 -0
  3. package/assets/skills/onboarding/SKILL.md +109 -0
  4. package/assets/skills/projects/SKILL.md +11 -2
  5. package/assets/templates/pal-settings.json +1 -0
  6. package/package.json +5 -1
  7. package/src/cli/index.ts +39 -12
  8. package/src/cli/migrate.ts +1 -1
  9. package/src/cli/personal-context.ts +67 -0
  10. package/src/cli/server.ts +13 -7
  11. package/src/cli/setup-identity.ts +13 -1
  12. package/src/cli/skill.ts +1 -1
  13. package/src/hooks/CompactRecover.ts +28 -86
  14. package/src/hooks/LedgerUnapplied.ts +3 -28
  15. package/src/hooks/LoadContext.ts +33 -60
  16. package/src/hooks/SecurityValidator.ts +16 -109
  17. package/src/hooks/handlers/agenda.ts +223 -0
  18. package/src/hooks/handlers/failure-principle.ts +19 -44
  19. package/src/hooks/handlers/inject-retrieval.ts +6 -2
  20. package/src/hooks/handlers/session-intelligence.ts +13 -70
  21. package/src/hooks/lib/agenda-store.ts +41 -0
  22. package/src/hooks/lib/capture-store.ts +103 -0
  23. package/src/hooks/lib/compact-recall.ts +89 -0
  24. package/src/hooks/lib/failure-principle.ts +98 -0
  25. package/src/hooks/lib/ledger-hook.ts +35 -0
  26. package/src/hooks/lib/ledger.ts +48 -1
  27. package/src/hooks/lib/paths.ts +0 -1
  28. package/src/hooks/lib/projects.ts +16 -1
  29. package/src/hooks/lib/security-gate.ts +159 -0
  30. package/src/hooks/lib/serves.ts +60 -0
  31. package/src/hooks/lib/session-context.ts +74 -0
  32. package/src/hooks/lib/stop.ts +14 -0
  33. package/src/hooks/lib/telos-goals.ts +144 -0
  34. package/src/hooks/lib/telos-topics.ts +68 -0
  35. package/src/hooks/lib/token-usage.ts +3 -1
  36. package/src/hooks/lib/wall-clock.ts +58 -0
  37. package/src/tools/agent/algorithm-reflect.ts +28 -97
  38. package/src/tools/agent/analyze.ts +19 -120
  39. package/src/tools/agent/handoff-note.ts +40 -70
  40. package/src/tools/agent/project.ts +47 -136
  41. package/src/tools/agent/relationship-note.ts +27 -46
  42. package/src/tools/agent/synthesize.ts +1 -1
  43. package/src/tools/agent/thread.ts +43 -123
  44. package/src/tools/control-room/data.ts +332 -0
  45. package/src/tools/control-room/matrix.ts +182 -0
  46. package/src/tools/control-room/server.ts +150 -0
  47. package/src/tools/control-room/ui/agenda.tsx +43 -0
  48. package/src/tools/control-room/ui/agents.tsx +67 -0
  49. package/src/tools/control-room/ui/app.css +857 -0
  50. package/src/tools/control-room/ui/app.tsx +74 -0
  51. package/src/tools/control-room/ui/board.tsx +82 -0
  52. package/src/tools/control-room/ui/format.ts +31 -0
  53. package/src/tools/control-room/ui/handoffs.tsx +37 -0
  54. package/src/tools/control-room/ui/index.html +19 -0
  55. package/src/tools/control-room/ui/ledger.tsx +137 -0
  56. package/src/tools/control-room/ui/matrix.tsx +117 -0
  57. package/src/tools/control-room/ui/panel.tsx +60 -0
  58. package/src/tools/control-room/ui/signal.tsx +161 -0
  59. package/src/tools/ledger/view.ts +3 -0
  60. package/src/tools/lib/algorithm-reflect.ts +84 -0
  61. package/src/tools/lib/analyze-report.ts +120 -0
  62. package/src/tools/lib/handoff-note.ts +88 -0
  63. package/src/tools/lib/note-flags.ts +59 -0
  64. package/src/tools/lib/project-isc.ts +151 -0
  65. package/src/tools/lib/relationship-reflect.ts +402 -0
  66. package/src/tools/lib/self-model.ts +499 -0
  67. package/src/tools/lib/session-usage.ts +216 -0
  68. package/src/tools/lib/skill-doctor.ts +457 -0
  69. package/src/tools/lib/thread.ts +119 -0
  70. package/src/tools/lib/token-report.ts +173 -0
  71. package/src/tools/lib/transcript-usage.ts +42 -0
  72. package/src/tools/lib/usage-buckets.ts +329 -0
  73. package/src/tools/relationship-reflect.ts +48 -412
  74. package/src/tools/self-model.ts +76 -558
  75. package/src/tools/session-summary.ts +8 -215
  76. package/src/tools/skill-doctor.ts +9 -444
  77. package/src/tools/token-cost.ts +18 -428
  78. package/assets/templates/ledger-page.html +0 -213
  79. package/src/cli/setup-telos.ts +0 -52
  80. package/src/hooks/lib/setup.ts +0 -60
  81. package/src/tools/ledger/server.ts +0 -111
@@ -1,52 +0,0 @@
1
- /**
2
- * Interactive TELOS setup — prompts for personal context during `pal install`.
3
- * Skips any step whose TELOS file already has real content.
4
- */
5
-
6
- import { writeFileSync } from "node:fs";
7
- import { resolve } from "node:path";
8
- import * as clack from "@clack/prompts";
9
- import { palHome } from "../hooks/lib/paths";
10
- import { hasRealContent, SETUP_STEPS, STEP_ORDER } from "../hooks/lib/setup";
11
-
12
- /** Prompt for missing TELOS context. Skips any step whose file already has real content. */
13
- export async function promptTelos(): Promise<void> {
14
- // Skip interactive prompts in non-TTY environments (tests, CI)
15
- if (!process.stdin.isTTY) return;
16
-
17
- const home = palHome();
18
- const pending = STEP_ORDER.filter(
19
- (key) => !hasRealContent(resolve(home, SETUP_STEPS[key].file))
20
- );
21
-
22
- if (pending.length === 0) {
23
- clack.log.info("TELOS already configured");
24
- return;
25
- }
26
-
27
- clack.intro("Personal Context Setup");
28
- clack.note(
29
- "Answer in a sentence or two — you can edit the files in ~/.pal/telos/ for more detail later.",
30
- "Quick setup"
31
- );
32
-
33
- for (const key of pending) {
34
- const step = SETUP_STEPS[key];
35
- const title = key.charAt(0).toUpperCase() + key.slice(1);
36
-
37
- const answer = await clack.text({
38
- message: step.question,
39
- placeholder: step.hint,
40
- });
41
-
42
- if (clack.isCancel(answer)) {
43
- clack.cancel("Setup cancelled");
44
- return;
45
- }
46
-
47
- const filePath = resolve(home, step.file);
48
- writeFileSync(filePath, `# ${title}\n\n${answer}\n`, "utf-8");
49
- }
50
-
51
- clack.outro("Personal context saved ✓");
52
- }
@@ -1,60 +0,0 @@
1
- /**
2
- * Setup state management for PAL first-run wizard.
3
- *
4
- * State lives in memory/state/setup.json. Each step maps to a TELOS file.
5
- * The AI is instructed to mark steps done after writing each file.
6
- */
7
-
8
- import { existsSync, readFileSync } from "node:fs";
9
-
10
- interface SetupStep {
11
- done: boolean;
12
- file: string;
13
- question: string;
14
- hint: string;
15
- }
16
-
17
- /** Ordered setup steps — defines the wizard flow */
18
- export const SETUP_STEPS: Record<string, Omit<SetupStep, "done">> = {
19
- mission: {
20
- file: "telos/MISSION.md",
21
- question:
22
- "What do you do? What's your role and core purpose? (~/.pal/telos/MISSION.md)",
23
- hint: "e.g. Senior software engineer building developer tooling at Acme Corp",
24
- },
25
- goals: {
26
- file: "telos/GOALS.md",
27
- question:
28
- "What are your current goals? (short-term, medium-term, long-term) (~/.pal/telos/GOALS.md)",
29
- hint: "e.g. Ship v2 by Q3, learn Rust, get promoted to staff engineer",
30
- },
31
- beliefs: {
32
- file: "telos/BELIEFS.md",
33
- question: "What principles or values guide your work? (~/.pal/telos/BELIEFS.md)",
34
- hint: "e.g. Simple code > clever code, ship early and iterate, always write tests",
35
- },
36
- challenges: {
37
- file: "telos/CHALLENGES.md",
38
- question: "What are your biggest current challenges? (~/.pal/telos/CHALLENGES.md)",
39
- hint: "e.g. Context switching between projects, unclear requirements, work-life balance",
40
- },
41
- };
42
-
43
- export const STEP_ORDER = Object.keys(SETUP_STEPS);
44
-
45
- /** Check if a TELOS file has real content (not just template scaffolding) */
46
- export function hasRealContent(filePath: string): boolean {
47
- if (!existsSync(filePath)) return false;
48
- try {
49
- const content = readFileSync(filePath, "utf-8").trim();
50
- return content.split("\n").some((l) => {
51
- if (!l.trim()) return false;
52
- if (l.startsWith("#")) return false;
53
- if (l.startsWith("<!--") || l.startsWith("-->")) return false;
54
- if (/^\s*-\s*$/.test(l)) return false;
55
- return true; // includes table rows (| ... |) — counts as real content
56
- });
57
- } catch {
58
- return false;
59
- }
60
- }
@@ -1,111 +0,0 @@
1
- /**
2
- * A local page over the ledger, for showing the action log to someone who
3
- * will not read a terminal.
4
- *
5
- * Loopback only, stateless, no store of its own: every request reads the
6
- * ledger afresh through the same query the CLI uses, so the page and
7
- * `pal cli ledger` can never disagree. The browser holds nothing but the
8
- * current filter selection.
9
- */
10
-
11
- import { readFileSync } from "node:fs";
12
- import { loadMachine } from "../../hooks/lib/machine";
13
- import { assets } from "../../hooks/lib/paths";
14
- import { readAllProjects } from "../../hooks/lib/projects";
15
- import { type LedgerFilter, ledgerFiles, parseSince } from "./query";
16
- import { ledgerView } from "./view";
17
-
18
- export const DEFAULT_PORT = 7250;
19
- export const LOOPBACK = "127.0.0.1";
20
-
21
- export interface ServerStatus {
22
- pid: number;
23
- port: number;
24
- startedAt: string;
25
- ledgerFiles: number;
26
- machine: string;
27
- }
28
-
29
- function json(body: unknown, status = 200): Response {
30
- return Response.json(body, { status });
31
- }
32
-
33
- /** A window the page cannot parse is an error, not the whole ledger. */
34
- function filterFromQuery(params: URLSearchParams): LedgerFilter | string {
35
- const filter: LedgerFilter = {};
36
- const project = params.get("project");
37
- if (project) filter.project = project;
38
- for (const key of ["since", "until"] as const) {
39
- const spec = params.get(key);
40
- if (!spec) continue;
41
- const at = parseSince(spec);
42
- if (!at) return `Unrecognised ${key}: ${spec}`;
43
- filter[key] = at;
44
- }
45
- return filter;
46
- }
47
-
48
- function page(): Response {
49
- return new Response(readFileSync(assets.ledgerPageTemplate()), {
50
- headers: { "content-type": "text/html; charset=utf-8" },
51
- });
52
- }
53
-
54
- function projects(): Response {
55
- const slugs = readAllProjects()
56
- .map((p) => p.name)
57
- .sort((a, b) => a.localeCompare(b));
58
- return json(slugs.map((slug) => ({ slug })));
59
- }
60
-
61
- function ledger(url: URL): Response {
62
- const filter = filterFromQuery(url.searchParams);
63
- if (typeof filter === "string") return json({ error: filter }, 400);
64
- return json(ledgerView(filter));
65
- }
66
-
67
- function status(port: number, startedAt: string): Response {
68
- const body: ServerStatus = {
69
- pid: process.pid,
70
- port,
71
- startedAt,
72
- ledgerFiles: ledgerFiles().length,
73
- machine: loadMachine().label,
74
- };
75
- return json(body);
76
- }
77
-
78
- export function startLedgerServer(port: number = DEFAULT_PORT) {
79
- const startedAt = new Date().toISOString();
80
- return Bun.serve({
81
- hostname: LOOPBACK,
82
- port,
83
- fetch(request, server) {
84
- if (request.method !== "GET") return json({ error: "read only" }, 405);
85
- const url = new URL(request.url);
86
- switch (url.pathname) {
87
- case "/":
88
- return page();
89
- case "/api/ledger":
90
- return ledger(url);
91
- case "/api/projects":
92
- return projects();
93
- case "/api/status":
94
- return status(server.port ?? port, startedAt);
95
- default:
96
- return json({ error: "not found" }, 404);
97
- }
98
- },
99
- });
100
- }
101
-
102
- function portFromArgv(argv: string[]): number {
103
- const flag = argv.find((arg) => arg.startsWith("--port="));
104
- const port = flag ? Number(flag.slice("--port=".length)) : DEFAULT_PORT;
105
- return Number.isInteger(port) && port >= 0 ? port : DEFAULT_PORT;
106
- }
107
-
108
- if (import.meta.main) {
109
- const server = startLedgerServer(portFromArgv(process.argv.slice(2)));
110
- console.log(`http://${LOOPBACK}:${server.port}/`);
111
- }