portable-agent-layer 0.9.0 → 0.11.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 (51) hide show
  1. package/assets/skills/{analyze-pdf.md → analyze-pdf/SKILL.md} +4 -4
  2. package/{src → assets/skills/analyze-pdf}/tools/pdf-download.ts +3 -3
  3. package/assets/skills/{analyze-youtube.md → analyze-youtube/SKILL.md} +4 -4
  4. package/{src → assets/skills/analyze-youtube}/tools/youtube-analyze.ts +2 -2
  5. package/assets/skills/{council.md → council/SKILL.md} +3 -2
  6. package/assets/skills/{create-skill.md → create-skill/SKILL.md} +2 -1
  7. package/assets/skills/{extract-entities.md → extract-entities/SKILL.md} +4 -5
  8. package/{src → assets/skills/extract-entities}/tools/entity-save.ts +3 -3
  9. package/assets/skills/{extract-wisdom.md → extract-wisdom/SKILL.md} +3 -2
  10. package/assets/skills/{first-principles.md → first-principles/SKILL.md} +3 -2
  11. package/assets/skills/{fyzz-chat-api.md → fyzz-chat-api/SKILL.md} +6 -6
  12. package/{src → assets/skills/fyzz-chat-api}/tools/fyzz-api.ts +6 -6
  13. package/assets/skills/{reflect.md → reflect/SKILL.md} +2 -1
  14. package/assets/skills/{research.md → research/SKILL.md} +2 -1
  15. package/assets/skills/{review.md → review/SKILL.md} +2 -1
  16. package/assets/skills/{summarize.md → summarize/SKILL.md} +3 -2
  17. package/assets/skills/telos/SKILL.md +60 -0
  18. package/assets/skills/telos/tools/update-telos.ts +101 -0
  19. package/assets/skills/think/SKILL.md +47 -0
  20. package/assets/templates/AGENTS.md.template +8 -37
  21. package/assets/templates/PAL/CONTEXT_ROUTING.md +12 -0
  22. package/assets/templates/PAL/MEMORY_SYSTEM.md +26 -0
  23. package/assets/templates/PAL/OPINION_TRACKING.md +3 -0
  24. package/assets/templates/PAL/STEERING_RULES.md +23 -0
  25. package/assets/templates/PAL/WORK_TRACKING.md +14 -0
  26. package/assets/templates/settings.claude.json +80 -0
  27. package/package.json +2 -5
  28. package/src/hooks/handlers/rating.ts +4 -47
  29. package/src/hooks/handlers/reflect-trigger.ts +83 -0
  30. package/src/hooks/handlers/relationship.ts +8 -5
  31. package/src/hooks/handlers/session-name.ts +8 -6
  32. package/src/hooks/handlers/work-learning.ts +1 -0
  33. package/src/hooks/handlers/work-session.ts +16 -3
  34. package/src/hooks/lib/claude-md.ts +9 -24
  35. package/src/hooks/lib/context.ts +31 -48
  36. package/src/hooks/lib/graduation.ts +6 -4
  37. package/src/hooks/lib/learning-store.ts +7 -117
  38. package/src/hooks/lib/opinions.ts +191 -0
  39. package/src/hooks/lib/paths.ts +2 -0
  40. package/src/hooks/lib/relationship.ts +5 -4
  41. package/src/hooks/lib/security.ts +2 -0
  42. package/src/hooks/lib/stop.ts +3 -0
  43. package/src/hooks/lib/text-similarity.ts +125 -0
  44. package/src/targets/claude/install.ts +16 -93
  45. package/src/targets/claude/uninstall.ts +22 -47
  46. package/src/targets/lib.ts +190 -48
  47. package/src/targets/opencode/install.ts +13 -2
  48. package/src/targets/opencode/uninstall.ts +4 -1
  49. package/src/tools/analyze.ts +49 -15
  50. package/src/tools/opinion.ts +250 -0
  51. package/src/tools/relationship-reflect.ts +215 -105
@@ -11,6 +11,18 @@
11
11
  import { parseArgs } from "node:util";
12
12
  import { analyze } from "../hooks/lib/graduation";
13
13
 
14
+ // ── ANSI Colors ──
15
+
16
+ const c = {
17
+ bold: (s: string) => `\x1b[1m${s}\x1b[0m`,
18
+ dim: (s: string) => `\x1b[2m${s}\x1b[0m`,
19
+ cyan: (s: string) => `\x1b[36m${s}\x1b[0m`,
20
+ yellow: (s: string) => `\x1b[33m${s}\x1b[0m`,
21
+ green: (s: string) => `\x1b[32m${s}\x1b[0m`,
22
+ red: (s: string) => `\x1b[31m${s}\x1b[0m`,
23
+ magenta: (s: string) => `\x1b[35m${s}\x1b[0m`,
24
+ };
25
+
14
26
  const { values } = parseArgs({
15
27
  args: Bun.argv.slice(2),
16
28
  options: {
@@ -24,7 +36,7 @@ if (values.help) {
24
36
  PAL Learning Analysis — unified graduation + ratings report
25
37
 
26
38
  Reads all captured failures (rating ≤3) and session learnings,
27
- groups recurring patterns via Jaccard similarity on context text,
39
+ groups recurring patterns via Dice similarity on context text,
28
40
  and summarizes rating trends.
29
41
 
30
42
  Sections:
@@ -57,47 +69,69 @@ if (!hasPatterns && !hasRatings) {
57
69
 
58
70
  if (result.ratings) {
59
71
  const r = result.ratings;
60
- console.log(`\n Ratings: ${r.average.toFixed(1)}/10 avg (${r.total} total)`);
61
- console.log(` Low (≤4): ${r.low.count} | High (≥7): ${r.high.count}`);
72
+ const avgColor = r.average >= 7 ? c.green : r.average <= 4 ? c.red : c.yellow;
73
+ console.log(
74
+ `\n ${c.bold("Ratings:")} ${avgColor(`${r.average.toFixed(1)}/10`)} avg (${r.total} total)`
75
+ );
76
+ console.log(
77
+ ` ${c.red(`Low (≤4): ${r.low.count}`)} | ${c.green(`High (≥7): ${r.high.count}`)}`
78
+ );
62
79
  }
63
80
 
64
81
  // ── Graduation Candidates ──
65
82
 
66
83
  if (result.candidates.length > 0) {
67
84
  console.log(
68
- `\n Graduation Report — ${result.candidates.length} pattern(s) detected\n`
85
+ `\n ${c.bold(c.green(`Graduation Report — ${result.candidates.length} pattern(s) detected`))}\n`
69
86
  );
70
- console.log(" ─────────────────────────────────────────────────\n");
87
+ console.log(` ${c.dim("─────────────────────────────────────────────────")}\n`);
71
88
 
72
89
  for (const candidate of result.candidates) {
73
- console.log(` [${candidate.domain}] ${candidate.entries.length}x occurrences`);
90
+ console.log(
91
+ ` ${c.cyan(`[${candidate.domain}]`)} ${c.bold(`${candidate.entries.length}x`)} occurrences`
92
+ );
74
93
  console.log("");
75
94
 
76
95
  for (const entry of candidate.entries) {
77
96
  const sourceType = entry.source.startsWith("failure:") ? "failure" : "learning";
97
+ const tag =
98
+ sourceType === "failure" ? c.red(`[${sourceType}]`) : c.yellow(`[${sourceType}]`);
78
99
  console.log(
79
- ` ${entry.date || "unknown"} [${sourceType}] ${entry.text.slice(0, 100)}`
100
+ ` ${c.dim(entry.date || "unknown")} ${tag} ${entry.text.slice(0, 100)}`
80
101
  );
81
102
  }
82
103
 
104
+ console.log(`\n ${c.dim("Files:")}`);
105
+ for (const entry of candidate.entries) {
106
+ console.log(` ${c.dim(entry.path)}`);
107
+ }
108
+
83
109
  console.log("");
84
- console.log(" Target frame:", `memory/wisdom/frames/${candidate.domain}.md`);
85
- console.log(" ─────────────────────────────────────────────────\n");
110
+ console.log(
111
+ ` Target frame: ${c.magenta(`memory/wisdom/frames/${candidate.domain}.md`)}`
112
+ );
113
+ console.log(` ${c.dim("─────────────────────────────────────────────────")}\n`);
86
114
  }
87
115
  }
88
116
 
89
117
  // ── Emerging Patterns ──
90
118
 
91
119
  if (result.emerging.length > 0) {
92
- console.log(` Emerging (2x — one more to graduate)\n`);
120
+ console.log(` ${c.bold(c.yellow("Emerging (2x — one more to graduate)"))}\n`);
93
121
  for (const group of result.emerging) {
94
- console.log(` [${group.domain}] ${group.entries.length}x`);
122
+ console.log(` ${c.cyan(`[${group.domain}]`)} ${c.bold(`${group.entries.length}x`)}`);
95
123
  for (const entry of group.entries) {
96
124
  const sourceType = entry.source.startsWith("failure:") ? "failure" : "learning";
125
+ const tag =
126
+ sourceType === "failure" ? c.red(`[${sourceType}]`) : c.yellow(`[${sourceType}]`);
97
127
  console.log(
98
- ` ${entry.date || "unknown"} [${sourceType}] ${entry.text.slice(0, 80)}`
128
+ ` ${c.dim(entry.date || "unknown")} ${tag} ${entry.text.slice(0, 80)}`
99
129
  );
100
130
  }
131
+ console.log(" Files:");
132
+ for (const entry of group.entries) {
133
+ console.log(` ${c.dim(entry.path)}`);
134
+ }
101
135
  console.log("");
102
136
  }
103
137
  }
@@ -105,7 +139,7 @@ if (result.emerging.length > 0) {
105
139
  // ── Recommendations ──
106
140
 
107
141
  if (result.recommendations.length > 0) {
108
- console.log(" Recommendations:\n");
142
+ console.log(` ${c.bold("Recommendations:")}\n`);
109
143
  for (const rec of result.recommendations) {
110
144
  console.log(` ${rec}`);
111
145
  }
@@ -113,6 +147,6 @@ if (result.recommendations.length > 0) {
113
147
  }
114
148
 
115
149
  if (result.candidates.length > 0) {
116
- console.log(" To crystallize: add a line to the wisdom frame file.");
117
- console.log(" Format: - Your principle here [CRYSTAL: 85%]\n");
150
+ console.log(` To crystallize: add a line to the wisdom frame file.`);
151
+ console.log(` Format: ${c.green("- Your principle here [CRYSTAL: 85%]")}\n`);
118
152
  }
@@ -0,0 +1,250 @@
1
+ #!/usr/bin/env bun
2
+ /**
3
+ * OpinionTracker — manage confidence-tracked opinions about the user.
4
+ *
5
+ * Called by the AI during conversation when it detects confirmations,
6
+ * contradictions, or new behavioral patterns.
7
+ *
8
+ * Usage:
9
+ * bun run tool:opinion -- list List all opinions
10
+ * bun run tool:opinion -- show "statement" Show opinion details
11
+ * bun run tool:opinion -- add "statement" [--category workflow] Add new opinion
12
+ * bun run tool:opinion -- evidence "statement" --supporting "why" Add supporting evidence
13
+ * bun run tool:opinion -- evidence "statement" --counter "why" Add counter evidence
14
+ * bun run tool:opinion -- evidence "statement" --confirmation "why" Explicit user confirmation
15
+ * bun run tool:opinion -- evidence "statement" --contradiction "why" Explicit user contradiction
16
+ */
17
+
18
+ import {
19
+ addEvidence,
20
+ createOpinion,
21
+ type EvidenceType,
22
+ findSimilarOpinion,
23
+ type OpinionCategory,
24
+ readOpinions,
25
+ saveOpinion,
26
+ } from "../hooks/lib/opinions";
27
+
28
+ const args = process.argv.slice(2);
29
+ const command = args[0];
30
+
31
+ const NOTIFICATION_THRESHOLD = 0.15;
32
+
33
+ function flag(name: string): string | undefined {
34
+ const idx = args.indexOf(`--${name}`);
35
+ return idx !== -1 ? args[idx + 1] : undefined;
36
+ }
37
+
38
+ const c = {
39
+ bold: (s: string) => `\x1b[1m${s}\x1b[0m`,
40
+ dim: (s: string) => `\x1b[2m${s}\x1b[0m`,
41
+ cyan: (s: string) => `\x1b[36m${s}\x1b[0m`,
42
+ yellow: (s: string) => `\x1b[33m${s}\x1b[0m`,
43
+ green: (s: string) => `\x1b[32m${s}\x1b[0m`,
44
+ red: (s: string) => `\x1b[31m${s}\x1b[0m`,
45
+ };
46
+
47
+ function bar(confidence: number): string {
48
+ const filled = Math.round(confidence * 10);
49
+ return "\u2588".repeat(filled) + "\u2591".repeat(10 - filled);
50
+ }
51
+
52
+ switch (command) {
53
+ case "list": {
54
+ const opinions = readOpinions();
55
+ if (opinions.length === 0) {
56
+ console.log("\n No opinions tracked yet.\n");
57
+ break;
58
+ }
59
+
60
+ const categories = new Map<string, typeof opinions>();
61
+ for (const op of opinions) {
62
+ const list = categories.get(op.category) ?? [];
63
+ list.push(op);
64
+ categories.set(op.category, list);
65
+ }
66
+
67
+ console.log(`\n ${c.bold("Tracked Opinions")} (${opinions.length} total)\n`);
68
+
69
+ for (const [category, ops] of categories) {
70
+ console.log(` ${c.cyan(category)}`);
71
+ for (const op of ops.sort((a, b) => b.confidence - a.confidence)) {
72
+ const pct = `${Math.round(op.confidence * 100)}%`;
73
+ const color =
74
+ op.confidence >= 0.85 ? c.green : op.confidence <= 0.3 ? c.red : c.yellow;
75
+ console.log(` [${bar(op.confidence)}] ${color(pct)} ${op.statement}`);
76
+ }
77
+ console.log("");
78
+ }
79
+ break;
80
+ }
81
+
82
+ case "show": {
83
+ const statement = args[1];
84
+ if (!statement) {
85
+ console.error('Usage: bun run tool:opinion -- show "statement"');
86
+ process.exit(1);
87
+ }
88
+
89
+ const opinions = readOpinions();
90
+ const match = findSimilarOpinion(statement, opinions);
91
+ if (!match) {
92
+ console.error(` No matching opinion found for: "${statement}"`);
93
+ process.exit(1);
94
+ }
95
+
96
+ const pct = Math.round(match.confidence * 100);
97
+ console.log(`\n ${c.bold("Opinion Details")}\n`);
98
+ console.log(` ${c.bold("Statement:")} ${match.statement}`);
99
+ console.log(` ${c.bold("Confidence:")} [${bar(match.confidence)}] ${pct}%`);
100
+ console.log(` ${c.bold("Category:")} ${match.category}`);
101
+ console.log(` ${c.bold("Created:")} ${match.created}`);
102
+ console.log(` ${c.bold("Updated:")} ${match.updated}`);
103
+ console.log(`\n ${c.bold("Evidence")} (${match.evidence.length} items)\n`);
104
+
105
+ const supporting = match.evidence.filter(
106
+ (e) => e.type === "supporting" || e.type === "confirmation"
107
+ );
108
+ const counter = match.evidence.filter(
109
+ (e) => e.type === "counter" || e.type === "contradiction"
110
+ );
111
+
112
+ if (supporting.length > 0) {
113
+ console.log(` ${c.green("Supporting:")}`);
114
+ for (const e of supporting) {
115
+ console.log(` ${c.dim(e.date)} [${e.type}] ${e.source}`);
116
+ }
117
+ }
118
+ if (counter.length > 0) {
119
+ console.log(` ${c.red("Counter:")}`);
120
+ for (const e of counter) {
121
+ console.log(` ${c.dim(e.date)} [${e.type}] ${e.source}`);
122
+ }
123
+ }
124
+ console.log("");
125
+ break;
126
+ }
127
+
128
+ case "add": {
129
+ const statement = args[1];
130
+ if (!statement) {
131
+ console.error(
132
+ 'Usage: bun run tool:opinion -- add "statement" [--category workflow]'
133
+ );
134
+ process.exit(1);
135
+ }
136
+
137
+ const category = (flag("category") || "general") as OpinionCategory;
138
+ const opinions = readOpinions();
139
+ const existing = findSimilarOpinion(statement, opinions);
140
+
141
+ if (existing) {
142
+ console.log(
143
+ ` Similar opinion already exists: "${existing.statement}" (${Math.round(existing.confidence * 100)}%)`
144
+ );
145
+ break;
146
+ }
147
+
148
+ const opinion = createOpinion(statement, "manual add");
149
+ opinion.category = category;
150
+ saveOpinion(opinion);
151
+ console.log(` Added: "${statement}" [${category}] at 50%`);
152
+ break;
153
+ }
154
+
155
+ case "evidence": {
156
+ const statement = args[1];
157
+ if (!statement) {
158
+ console.error(
159
+ 'Usage: bun run tool:opinion -- evidence "statement" --supporting "description"'
160
+ );
161
+ process.exit(1);
162
+ }
163
+
164
+ const opinions = readOpinions();
165
+ const match = findSimilarOpinion(statement, opinions);
166
+ if (!match) {
167
+ console.error(` No matching opinion found for: "${statement}"`);
168
+ process.exit(1);
169
+ }
170
+
171
+ let evidenceType: EvidenceType | undefined;
172
+ let description: string | undefined;
173
+
174
+ for (const t of ["supporting", "counter", "confirmation", "contradiction"] as const) {
175
+ const val = flag(t);
176
+ if (val) {
177
+ evidenceType = t;
178
+ description = val;
179
+ break;
180
+ }
181
+ }
182
+
183
+ if (!evidenceType || !description) {
184
+ console.error(
185
+ " Provide one of: --supporting, --counter, --confirmation, --contradiction"
186
+ );
187
+ process.exit(1);
188
+ }
189
+
190
+ const oldConfidence = match.confidence;
191
+ const updated = addEvidence(match, evidenceType, description);
192
+ saveOpinion(updated);
193
+
194
+ const shift = updated.confidence - oldConfidence;
195
+ const arrow = shift > 0 ? c.green("\u2191") : c.red("\u2193");
196
+ console.log(
197
+ ` ${arrow} ${Math.round(oldConfidence * 100)}% \u2192 ${Math.round(updated.confidence * 100)}% "${match.statement}"`
198
+ );
199
+ console.log(` [${evidenceType}] ${description}`);
200
+
201
+ if (Math.abs(shift) >= NOTIFICATION_THRESHOLD) {
202
+ console.log(
203
+ `\n ${c.bold(c.yellow("Major shift detected!"))} (${shift > 0 ? "+" : ""}${Math.round(shift * 100)}%)`
204
+ );
205
+ }
206
+ break;
207
+ }
208
+
209
+ case "--help":
210
+ case "-h":
211
+ case "help":
212
+ case undefined: {
213
+ console.log(`
214
+ OpinionTracker — manage confidence-tracked opinions about the user
215
+
216
+ The "statement" argument is fuzzy-matched (Dice similarity) against all
217
+ stored opinions. Use a few keywords from the opinion, not the exact text.
218
+
219
+ Commands:
220
+ list List all opinions with confidence bars
221
+ show "keywords" Show opinion details + full evidence history
222
+ add "statement" [--category X] Create new opinion (starts at 50%)
223
+ evidence "keywords" --supporting "why" Supporting evidence (+2%)
224
+ evidence "keywords" --counter "why" Counter evidence (-5%)
225
+ evidence "keywords" --confirmation "why" User explicitly confirmed (+10%)
226
+ evidence "keywords" --contradiction "why" User explicitly contradicted (-20%)
227
+
228
+ Categories: communication, technical, workflow, general
229
+
230
+ Examples:
231
+ bun run tool:opinion -- list
232
+ bun run tool:opinion -- evidence "concise direct responses" --confirmation "User said: keep it short"
233
+ bun run tool:opinion -- evidence "concise direct responses" --contradiction "User asked for detailed explanation"
234
+ bun run tool:opinion -- add "User prefers iterative development" --category workflow
235
+ bun run tool:opinion -- show "iterative development"
236
+
237
+ Confidence lifecycle:
238
+ New opinions start at 50%. Supporting notes from reflect add +2% each.
239
+ Explicit confirmations jump +10%, contradictions drop -20%.
240
+ At >=85%, opinions are auto-injected into every session context.
241
+
242
+ Usage: bun run tool:opinion -- <command> [args]
243
+ `);
244
+ break;
245
+ }
246
+
247
+ default:
248
+ console.error(` Unknown command: ${command}. Run with --help for usage.`);
249
+ process.exit(1);
250
+ }