portable-agent-layer 0.1.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 (90) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +80 -0
  3. package/assets/agents/claude-researcher.md +43 -0
  4. package/assets/agents/investigative-researcher.md +44 -0
  5. package/assets/agents/multi-perspective-researcher.md +43 -0
  6. package/assets/skills/analyze-pdf.md +40 -0
  7. package/assets/skills/analyze-youtube.md +35 -0
  8. package/assets/skills/council.md +43 -0
  9. package/assets/skills/create-skill.md +31 -0
  10. package/assets/skills/extract-entities.md +63 -0
  11. package/assets/skills/extract-wisdom.md +18 -0
  12. package/assets/skills/first-principles.md +17 -0
  13. package/assets/skills/fyzz-chat-api.md +43 -0
  14. package/assets/skills/reflect.md +87 -0
  15. package/assets/skills/research.md +68 -0
  16. package/assets/skills/review.md +19 -0
  17. package/assets/skills/summarize.md +15 -0
  18. package/assets/templates/AGENTS.md.template +45 -0
  19. package/assets/templates/telos/BELIEFS.md +4 -0
  20. package/assets/templates/telos/CHALLENGES.md +4 -0
  21. package/assets/templates/telos/GOALS.md +12 -0
  22. package/assets/templates/telos/IDEAS.md +4 -0
  23. package/assets/templates/telos/IDENTITY.md +4 -0
  24. package/assets/templates/telos/LEARNED.md +4 -0
  25. package/assets/templates/telos/MISSION.md +4 -0
  26. package/assets/templates/telos/MODELS.md +4 -0
  27. package/assets/templates/telos/NARRATIVES.md +4 -0
  28. package/assets/templates/telos/PROJECTS.md +7 -0
  29. package/assets/templates/telos/STRATEGIES.md +4 -0
  30. package/bin/pal +24 -0
  31. package/bin/pal.bat +8 -0
  32. package/bin/pal.ps1 +30 -0
  33. package/package.json +82 -0
  34. package/src/cli/index.ts +344 -0
  35. package/src/cli/install.ts +86 -0
  36. package/src/cli/uninstall.ts +45 -0
  37. package/src/hooks/LoadContext.ts +41 -0
  38. package/src/hooks/SecurityValidator.ts +52 -0
  39. package/src/hooks/SkillGuard.ts +41 -0
  40. package/src/hooks/StopOrchestrator.ts +35 -0
  41. package/src/hooks/UserPromptOrchestrator.ts +35 -0
  42. package/src/hooks/handlers/backup.ts +41 -0
  43. package/src/hooks/handlers/failure.ts +136 -0
  44. package/src/hooks/handlers/rating.ts +409 -0
  45. package/src/hooks/handlers/relationship.ts +113 -0
  46. package/src/hooks/handlers/session-name.ts +121 -0
  47. package/src/hooks/handlers/synthesis.ts +109 -0
  48. package/src/hooks/handlers/tab.ts +8 -0
  49. package/src/hooks/handlers/update-counts.ts +151 -0
  50. package/src/hooks/handlers/work-learning.ts +183 -0
  51. package/src/hooks/handlers/work-session.ts +58 -0
  52. package/src/hooks/lib/claude-md.ts +121 -0
  53. package/src/hooks/lib/context.ts +433 -0
  54. package/src/hooks/lib/entities.ts +304 -0
  55. package/src/hooks/lib/export.ts +76 -0
  56. package/src/hooks/lib/inference.ts +91 -0
  57. package/src/hooks/lib/learning-category.ts +14 -0
  58. package/src/hooks/lib/log.ts +53 -0
  59. package/src/hooks/lib/models.ts +16 -0
  60. package/src/hooks/lib/paths.ts +80 -0
  61. package/src/hooks/lib/relationship.ts +135 -0
  62. package/src/hooks/lib/security.ts +122 -0
  63. package/src/hooks/lib/session-names.ts +247 -0
  64. package/src/hooks/lib/setup.ts +189 -0
  65. package/src/hooks/lib/signal-trends.ts +117 -0
  66. package/src/hooks/lib/signals.ts +37 -0
  67. package/src/hooks/lib/stdin.ts +18 -0
  68. package/src/hooks/lib/stop.ts +155 -0
  69. package/src/hooks/lib/time.ts +19 -0
  70. package/src/hooks/lib/token-usage.ts +42 -0
  71. package/src/hooks/lib/transcript.ts +76 -0
  72. package/src/hooks/lib/wisdom.ts +48 -0
  73. package/src/hooks/lib/work-tracking.ts +193 -0
  74. package/src/hooks/setup-check.ts +42 -0
  75. package/src/targets/claude/install.ts +145 -0
  76. package/src/targets/claude/uninstall.ts +101 -0
  77. package/src/targets/lib.ts +337 -0
  78. package/src/targets/opencode/install.ts +59 -0
  79. package/src/targets/opencode/plugin.ts +328 -0
  80. package/src/targets/opencode/uninstall.ts +57 -0
  81. package/src/tools/entity-save.ts +110 -0
  82. package/src/tools/export.ts +34 -0
  83. package/src/tools/fyzz-api.ts +104 -0
  84. package/src/tools/import.ts +123 -0
  85. package/src/tools/pattern-synthesis.ts +435 -0
  86. package/src/tools/pdf-download.ts +102 -0
  87. package/src/tools/relationship-reflect.ts +362 -0
  88. package/src/tools/session-summary.ts +206 -0
  89. package/src/tools/token-cost.ts +301 -0
  90. package/src/tools/youtube-analyze.ts +105 -0
@@ -0,0 +1,68 @@
1
+ ---
2
+ name: research
3
+ description: Multi-agent parallel research — quick/standard/extensive modes with specialized researcher agents for depth, breadth, and verification
4
+ ---
5
+
6
+ ## Mode Routing
7
+
8
+ | User says | Mode | Agents |
9
+ |-----------|------|--------|
10
+ | "quick research" / "minor research" | Quick | 1 agent |
11
+ | "research" / "do research" (default) | Standard | 2 parallel agents |
12
+ | "extensive research" / "deep research" | Extensive | 6 parallel agents |
13
+
14
+ ## Available Researcher Agents
15
+
16
+ - **claude-researcher** — academic depth, query decomposition, scholarly synthesis
17
+ - **multi-perspective-researcher** — breadth, multiple angles, diverse viewpoints
18
+ - **investigative-researcher** — verification rigor, triple-checks, source credibility
19
+
20
+ ## Quick Mode
21
+
22
+ Spawn **1 subagent** for a focused answer:
23
+
24
+ - Spawn `claude-researcher` with the full query and context
25
+
26
+ Wait for the result, then deliver it directly with light formatting.
27
+
28
+ ## Standard Mode (Default)
29
+
30
+ Craft **2 different queries** optimized for each researcher's strengths, then spawn both **in parallel (in a single message)**:
31
+
32
+ - Spawn `claude-researcher` with a query optimized for depth/analysis
33
+ - Spawn `multi-perspective-researcher` with a query optimized for breadth/perspectives
34
+
35
+ **Query design:**
36
+ - claude-researcher: focus on authoritative sources, technical depth, how/why
37
+ - multi-perspective-researcher: focus on different stakeholder views, trade-offs, alternatives
38
+
39
+ ## Extensive Mode
40
+
41
+ Craft **6 queries** (2 per researcher type, each from a different angle), then spawn all **in parallel (in a single message)**:
42
+
43
+ - Spawn `claude-researcher` — angle 1: core technical depth
44
+ - Spawn `claude-researcher` — angle 2: historical context / evolution
45
+ - Spawn `multi-perspective-researcher` — angle 3: stakeholder perspectives
46
+ - Spawn `multi-perspective-researcher` — angle 4: cross-domain connections
47
+ - Spawn `investigative-researcher` — angle 5: verify key claims
48
+ - Spawn `investigative-researcher` — angle 6: find contradictions / counter-evidence
49
+
50
+ ## Synthesis (All Modes)
51
+
52
+ After collecting agent results, synthesize into:
53
+
54
+ 1. **TLDR** — 1-2 sentence answer
55
+ 2. **Key findings** — bullet points, grouped by theme, noting which agent(s) found each
56
+ 3. **Cross-source agreement** — findings confirmed by multiple agents (high confidence)
57
+ 4. **Conflicts** — where agents disagree, with both sides presented
58
+ 5. **Gaps** — what remains unknown or needs further investigation
59
+ 6. **Sources** — deduplicated list of verified URLs from all agents
60
+
61
+ Keep total output under 1500 words unless the user asks for more.
62
+
63
+ ## Important
64
+
65
+ - All subagent spawns for a given mode MUST be in a **single message** for true parallel execution
66
+ - Do NOT run agents sequentially — that defeats the purpose
67
+ - Each agent returns independently — expect different formats and overlapping findings
68
+ - The synthesis step is YOUR job as the orchestrating agent, not the subagents'
@@ -0,0 +1,19 @@
1
+ ---
2
+ name: review
3
+ description: Security-focused code review with severity ratings
4
+ ---
5
+
6
+ When the user invokes /review <file, diff, or PR>:
7
+
8
+ 1. Read the target code or diff in full
9
+ 2. Analyze for:
10
+ - **Security** — OWASP top 10, injection, auth, data exposure
11
+ - **Logic** — edge cases, off-by-one, null handling, race conditions
12
+ - **Performance** — N+1 queries, unnecessary allocations, blocking calls
13
+ - **Style** — consistency with surrounding code (not your preferences)
14
+ 3. Output findings grouped by severity:
15
+ - CRITICAL — must fix before merge
16
+ - WARNING — should fix, creates risk
17
+ - SUGGESTION — nice to have
18
+ 4. Each finding includes: file:line, what's wrong, concrete fix
19
+ 5. End with a one-line verdict: APPROVE / REQUEST CHANGES / NEEDS DISCUSSION
@@ -0,0 +1,15 @@
1
+ ---
2
+ name: summarize
3
+ description: Structured summarization of documents, URLs, or conversations
4
+ ---
5
+
6
+ When the user invokes /summarize <target>:
7
+
8
+ 1. Fetch or read the target content
9
+ 2. Produce:
10
+ - **TLDR** (1 sentence)
11
+ - **Key points** (5-7 bullets)
12
+ - **Action items** (if any exist in the content)
13
+ - **Notable quotes/data** (verbatim, with attribution)
14
+ 3. Keep total output under 500 words
15
+ 4. If the content is very long, note what was covered vs skipped
@@ -0,0 +1,45 @@
1
+ # PAL — Portable Agent Layer
2
+
3
+ You have PA installed. PAL provides persistent personal context across sessions — the user's identity, goals, projects, beliefs, and challenges are stored in TELOS files and loaded into your context automatically. Use this information to tailor your responses to who they are and what they care about.
4
+
5
+ When TELOS is populated, you already know the user. When it's empty, first-run setup is required — follow the setup instructions below.
6
+
7
+ {{SETUP_PROMPT}}
8
+ {{TELOS}}
9
+ ## Memory
10
+
11
+ PAL has its own memory system that persists across sessions AND across tools (Claude Code, opencode). Always prefer PAL memory over any tool-native memory system.
12
+
13
+ ### Where to write
14
+
15
+ {{MEMORY_PATHS}}
16
+
17
+ ### Format
18
+
19
+ - **Wisdom frames**: One `.md` file per domain/topic. Each file contains bullet-point principles the user has validated or you've learned. Append new principles to existing files or create new domain files.
20
+ - **Relationship notes**: Daily `.md` file with bullet-point observations about the interaction (tone, preferences, corrections).
21
+ - **Session learnings**: One `.md` file per session with a `**Title:**` line summarizing what was learned.
22
+ - **Failure captures**: One directory per failure, named `{YYYYMMDD-HHmmss}_{slug}/`, containing a `capture.md` with what went wrong and why.
23
+
24
+ ## Work Tracking
25
+
26
+ PAL tracks your work across sessions in `memory/state/sessions.json` (auto-captured) and `memory/state/projects.json` (AI-managed).
27
+
28
+ ### Projects
29
+
30
+ Update `projects.json` via the work-tracking library when:
31
+ - **Starting sustained multi-session work** → create a project with objectives and an id (slugified, e.g. "pdf-template-engine")
32
+ - **Making a key decision** → add to the project's `decisions` array
33
+ - **Completing a milestone** → add to `completed`, remove from `nextSteps`
34
+ - **Session ends with open work** → update `nextSteps` and `handoff`
35
+ - **Work is done** → set status to "completed"
36
+
37
+ Do not create projects for one-off questions or quick fixes.
38
+
39
+ ### When to write
40
+
41
+ - When the user corrects you or gives feedback → wisdom frame
42
+ - When you learn something about how the user prefers to work → relationship note
43
+ - When a session produces reusable insights → session learning
44
+ - When something fails significantly (rating < 6) → failure capture
45
+ - Do NOT write memories about trivial exchanges or things already captured in TELOS.
@@ -0,0 +1,4 @@
1
+ # Beliefs
2
+
3
+ <!-- Your values, principles, and worldview. What do you hold to be true? -->
4
+
@@ -0,0 +1,4 @@
1
+ # Challenges
2
+
3
+ <!-- Current obstacles, open problems, things you're stuck on. -->
4
+
@@ -0,0 +1,12 @@
1
+ # Goals
2
+
3
+ <!-- Active goals with timeframes. What are you working toward right now? -->
4
+
5
+ ## Short-term
6
+ -
7
+
8
+ ## Medium-term
9
+ -
10
+
11
+ ## Long-term
12
+ -
@@ -0,0 +1,4 @@
1
+ # Ideas
2
+
3
+ <!-- Ideas you're exploring, things to revisit, seeds of future projects. -->
4
+
@@ -0,0 +1,4 @@
1
+ # AI Identity
2
+
3
+ <!-- The name and identity of your personal AI assistant. -->
4
+
@@ -0,0 +1,4 @@
1
+ # Learned
2
+
3
+ <!-- Hard-won lessons. Things you figured out the hard way that should inform future decisions. -->
4
+
@@ -0,0 +1,4 @@
1
+ # Mission
2
+
3
+ <!-- Your core purpose. What drives you? What impact do you want to have? -->
4
+
@@ -0,0 +1,4 @@
1
+ # Mental Models
2
+
3
+ <!-- Frameworks and mental models you use for thinking and decision-making. -->
4
+
@@ -0,0 +1,4 @@
1
+ # Narratives
2
+
3
+ <!-- Key stories and context about your life and work. Background that shapes how you think. -->
4
+
@@ -0,0 +1,7 @@
1
+ # Projects
2
+
3
+ <!-- Current projects, their status, and how they relate to each other. -->
4
+
5
+ | Project | Status | Priority | Notes |
6
+ |---------|--------|----------|-------|
7
+ | | | | |
@@ -0,0 +1,4 @@
1
+ # Strategies
2
+
3
+ <!-- How you approach problems. Preferred methods, workflows, decision heuristics. -->
4
+
package/bin/pal ADDED
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env bash
2
+ # Jarvis — Claude Code wrapper with session summary on exit.
3
+ #
4
+ # After Claude exits, finds the most recently modified transcript JSONL
5
+ # in ~/.claude/projects/ and extracts the sessionId from its last line.
6
+
7
+ PAL_DIR="$(cd "$(dirname "$0")/.." && pwd)"
8
+
9
+ # Run Claude (blocking — keeps the interactive terminal)
10
+ claude "$@"
11
+ EXIT_CODE=$?
12
+
13
+ # Find the most recently modified transcript and extract its session ID
14
+ LATEST=$(find "$HOME/.claude/projects" -name '*.jsonl' -type f -print0 2>/dev/null \
15
+ | xargs -0 ls -t 2>/dev/null | head -1)
16
+
17
+ if [ -n "$LATEST" ]; then
18
+ SESSION_ID=$(tail -1 "$LATEST" | python3 -c "import sys,json; print(json.loads(sys.stdin.readline()).get('sessionId',''))" 2>/dev/null)
19
+ if [ -n "$SESSION_ID" ]; then
20
+ bun run "$PAL_DIR/src/tools/session-summary.ts" -- --session "$SESSION_ID" 2>/dev/null
21
+ fi
22
+ fi
23
+
24
+ exit $EXIT_CODE
package/bin/pal.bat ADDED
@@ -0,0 +1,8 @@
1
+ @echo off
2
+ REM Jarvis — Claude Code wrapper with session summary on exit.
3
+ REM
4
+ REM Uses PowerShell to start Claude, capture its PID, read the session ID
5
+ REM from %USERPROFILE%\.claude\sessions\<PID>.json, then show a cost
6
+ REM summary after Claude exits.
7
+
8
+ powershell -NoProfile -ExecutionPolicy Bypass -File "%~dp0pal.ps1" %*
package/bin/pal.ps1 ADDED
@@ -0,0 +1,30 @@
1
+ # Jarvis — Claude Code wrapper with session summary on exit.
2
+ #
3
+ # After Claude exits, finds the most recently modified transcript JSONL
4
+ # in ~/.claude/projects/ and extracts the sessionId from its last line.
5
+
6
+ $palDir = Split-Path -Parent (Split-Path -Parent $MyInvocation.MyCommand.Path)
7
+
8
+ # Run Claude (blocking — keeps the interactive terminal)
9
+ & claude @args
10
+ $exitCode = $LASTEXITCODE
11
+
12
+ # Find the most recently modified transcript and extract its session ID
13
+ $latest = Get-ChildItem "$env:USERPROFILE\.claude\projects\*\*.jsonl" -ErrorAction SilentlyContinue |
14
+ Sort-Object LastWriteTime -Descending |
15
+ Select-Object -First 1
16
+
17
+ if ($latest) {
18
+ $lastLine = Get-Content $latest.FullName -Tail 1 -ErrorAction SilentlyContinue
19
+ if ($lastLine) {
20
+ try {
21
+ $sessionId = ($lastLine | ConvertFrom-Json).sessionId
22
+ if ($sessionId) {
23
+ $summaryScript = Join-Path $palDir "src" "tools" "session-summary.ts"
24
+ & bun run $summaryScript -- --session $sessionId 2>$null
25
+ }
26
+ } catch {}
27
+ }
28
+ }
29
+
30
+ exit $exitCode
package/package.json ADDED
@@ -0,0 +1,82 @@
1
+ {
2
+ "name": "portable-agent-layer",
3
+ "version": "0.1.0",
4
+ "description": "PAL — Portable Agent Layer: persistent personal context for AI coding assistants",
5
+ "type": "module",
6
+ "bin": {
7
+ "pal": "src/cli/index.ts"
8
+ },
9
+ "files": [
10
+ "src/",
11
+ "assets/",
12
+ "bin/",
13
+ "README.md",
14
+ "LICENSE"
15
+ ],
16
+ "engines": {
17
+ "bun": ">=1.3.0"
18
+ },
19
+ "keywords": [
20
+ "ai",
21
+ "claude",
22
+ "opencode",
23
+ "personal-ai",
24
+ "context",
25
+ "memory",
26
+ "telos",
27
+ "agent",
28
+ "portable"
29
+ ],
30
+ "license": "MIT",
31
+ "repository": {
32
+ "type": "git",
33
+ "url": "git+https://github.com/kovrichard/portable-agent-layer.git"
34
+ },
35
+ "scripts": {
36
+ "type-check": "tsc --noEmit",
37
+ "test": "bun test",
38
+ "format": "biome format",
39
+ "format-write": "biome format --write",
40
+ "lint": "biome lint",
41
+ "lint-write": "biome lint --write",
42
+ "check": "biome check",
43
+ "check-write": "biome check --write",
44
+ "lint-staged": "lint-staged",
45
+ "prepare": "husky",
46
+ "install:all": "bun run src/cli/install.ts",
47
+ "uninstall": "bun run src/cli/uninstall.ts",
48
+ "ai:entity-save": "bun run src/tools/entity-save.ts",
49
+ "ai:fyzz-api": "bun run src/tools/fyzz-api.ts",
50
+ "ai:pdf-download": "bun run src/tools/pdf-download.ts",
51
+ "ai:youtube-analyze": "bun run src/tools/youtube-analyze.ts",
52
+ "tool:patterns": "bun run src/tools/pattern-synthesis.ts",
53
+ "tool:reflect": "bun run src/tools/relationship-reflect.ts",
54
+ "tool:export": "bun run src/tools/export.ts",
55
+ "tool:import": "bun run src/tools/import.ts",
56
+ "tool:tokens": "bun run src/tools/token-cost.ts"
57
+ },
58
+ "lint-staged": {
59
+ "*.ts": [
60
+ "bun run check"
61
+ ]
62
+ },
63
+ "devDependencies": {
64
+ "@biomejs/biome": "2.4.7",
65
+ "@commitlint/cli": "^20.5.0",
66
+ "@commitlint/config-conventional": "^20.5.0",
67
+ "@opencode-ai/plugin": "latest",
68
+ "@semantic-release/changelog": "^6.0.3",
69
+ "@semantic-release/git": "^10.0.1",
70
+ "@semantic-release/github": "^12.0.6",
71
+ "@types/adm-zip": "^0.5.8",
72
+ "@types/bun": "latest",
73
+ "@types/node": "latest",
74
+ "husky": "^9.1.7",
75
+ "lint-staged": "^15.5.0",
76
+ "semantic-release": "^25.0.3",
77
+ "typescript": "^5.9.0"
78
+ },
79
+ "dependencies": {
80
+ "adm-zip": "^0.5.16"
81
+ }
82
+ }