pi-continuous-learning 0.3.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/LICENSE +21 -0
- package/README.md +326 -0
- package/dist/active-instincts.d.ts +4 -0
- package/dist/active-instincts.d.ts.map +1 -0
- package/dist/active-instincts.js +11 -0
- package/dist/active-instincts.js.map +1 -0
- package/dist/agents-md.d.ts +12 -0
- package/dist/agents-md.d.ts.map +1 -0
- package/dist/agents-md.js +23 -0
- package/dist/agents-md.js.map +1 -0
- package/dist/cli/analyze-prompt.d.ts +2 -0
- package/dist/cli/analyze-prompt.d.ts.map +1 -0
- package/dist/cli/analyze-prompt.js +72 -0
- package/dist/cli/analyze-prompt.js.map +1 -0
- package/dist/cli/analyze.d.ts +3 -0
- package/dist/cli/analyze.d.ts.map +1 -0
- package/dist/cli/analyze.js +214 -0
- package/dist/cli/analyze.js.map +1 -0
- package/dist/confidence.d.ts +25 -0
- package/dist/confidence.d.ts.map +1 -0
- package/dist/confidence.js +77 -0
- package/dist/confidence.js.map +1 -0
- package/dist/config.d.ts +19 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +89 -0
- package/dist/config.js.map +1 -0
- package/dist/error-logger.d.ts +34 -0
- package/dist/error-logger.d.ts.map +1 -0
- package/dist/error-logger.js +102 -0
- package/dist/error-logger.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +118 -0
- package/dist/index.js.map +1 -0
- package/dist/instinct-decay.d.ts +39 -0
- package/dist/instinct-decay.d.ts.map +1 -0
- package/dist/instinct-decay.js +93 -0
- package/dist/instinct-decay.js.map +1 -0
- package/dist/instinct-evolve.d.ts +5 -0
- package/dist/instinct-evolve.d.ts.map +1 -0
- package/dist/instinct-evolve.js +24 -0
- package/dist/instinct-evolve.js.map +1 -0
- package/dist/instinct-export.d.ts +40 -0
- package/dist/instinct-export.d.ts.map +1 -0
- package/dist/instinct-export.js +94 -0
- package/dist/instinct-export.js.map +1 -0
- package/dist/instinct-import.d.ts +50 -0
- package/dist/instinct-import.d.ts.map +1 -0
- package/dist/instinct-import.js +168 -0
- package/dist/instinct-import.js.map +1 -0
- package/dist/instinct-injector.d.ts +39 -0
- package/dist/instinct-injector.d.ts.map +1 -0
- package/dist/instinct-injector.js +89 -0
- package/dist/instinct-injector.js.map +1 -0
- package/dist/instinct-loader.d.ts +37 -0
- package/dist/instinct-loader.d.ts.map +1 -0
- package/dist/instinct-loader.js +96 -0
- package/dist/instinct-loader.js.map +1 -0
- package/dist/instinct-parser.d.ts +28 -0
- package/dist/instinct-parser.d.ts.map +1 -0
- package/dist/instinct-parser.js +143 -0
- package/dist/instinct-parser.js.map +1 -0
- package/dist/instinct-projects.d.ts +32 -0
- package/dist/instinct-projects.d.ts.map +1 -0
- package/dist/instinct-projects.js +96 -0
- package/dist/instinct-projects.js.map +1 -0
- package/dist/instinct-promote.d.ts +51 -0
- package/dist/instinct-promote.d.ts.map +1 -0
- package/dist/instinct-promote.js +169 -0
- package/dist/instinct-promote.js.map +1 -0
- package/dist/instinct-status.d.ts +39 -0
- package/dist/instinct-status.d.ts.map +1 -0
- package/dist/instinct-status.js +108 -0
- package/dist/instinct-status.js.map +1 -0
- package/dist/instinct-store.d.ts +30 -0
- package/dist/instinct-store.d.ts.map +1 -0
- package/dist/instinct-store.js +118 -0
- package/dist/instinct-store.js.map +1 -0
- package/dist/instinct-tools.d.ts +161 -0
- package/dist/instinct-tools.d.ts.map +1 -0
- package/dist/instinct-tools.js +240 -0
- package/dist/instinct-tools.js.map +1 -0
- package/dist/observations.d.ts +22 -0
- package/dist/observations.d.ts.map +1 -0
- package/dist/observations.js +62 -0
- package/dist/observations.js.map +1 -0
- package/dist/observer-guard.d.ts +3 -0
- package/dist/observer-guard.d.ts.map +1 -0
- package/dist/observer-guard.js +13 -0
- package/dist/observer-guard.js.map +1 -0
- package/dist/project.d.ts +16 -0
- package/dist/project.d.ts.map +1 -0
- package/dist/project.js +59 -0
- package/dist/project.js.map +1 -0
- package/dist/prompt-observer.d.ts +25 -0
- package/dist/prompt-observer.d.ts.map +1 -0
- package/dist/prompt-observer.js +63 -0
- package/dist/prompt-observer.js.map +1 -0
- package/dist/prompts/analyzer-user.d.ts +38 -0
- package/dist/prompts/analyzer-user.d.ts.map +1 -0
- package/dist/prompts/analyzer-user.js +105 -0
- package/dist/prompts/analyzer-user.js.map +1 -0
- package/dist/prompts/evolve-prompt.d.ts +3 -0
- package/dist/prompts/evolve-prompt.d.ts.map +1 -0
- package/dist/prompts/evolve-prompt.js +51 -0
- package/dist/prompts/evolve-prompt.js.map +1 -0
- package/dist/scrubber.d.ts +9 -0
- package/dist/scrubber.d.ts.map +1 -0
- package/dist/scrubber.js +40 -0
- package/dist/scrubber.js.map +1 -0
- package/dist/storage.d.ts +22 -0
- package/dist/storage.d.ts.map +1 -0
- package/dist/storage.js +71 -0
- package/dist/storage.js.map +1 -0
- package/dist/tool-observer.d.ts +32 -0
- package/dist/tool-observer.d.ts.map +1 -0
- package/dist/tool-observer.js +77 -0
- package/dist/tool-observer.js.map +1 -0
- package/dist/types.d.ts +64 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +6 -0
- package/dist/types.js.map +1 -0
- package/package.json +66 -0
- package/src/active-instincts.ts +13 -0
- package/src/agents-md.ts +23 -0
- package/src/cli/analyze-prompt.ts +71 -0
- package/src/cli/analyze.ts +286 -0
- package/src/confidence.ts +103 -0
- package/src/config.ts +111 -0
- package/src/error-logger.ts +130 -0
- package/src/index.ts +144 -0
- package/src/instinct-decay.ts +117 -0
- package/src/instinct-evolve.ts +44 -0
- package/src/instinct-export.ts +138 -0
- package/src/instinct-import.ts +260 -0
- package/src/instinct-injector.ts +128 -0
- package/src/instinct-loader.ts +146 -0
- package/src/instinct-parser.ts +171 -0
- package/src/instinct-projects.ts +119 -0
- package/src/instinct-promote.ts +231 -0
- package/src/instinct-status.ts +135 -0
- package/src/instinct-store.ts +149 -0
- package/src/instinct-tools.ts +340 -0
- package/src/observations.ts +82 -0
- package/src/observer-guard.ts +14 -0
- package/src/project.ts +70 -0
- package/src/prompt-observer.ts +92 -0
- package/src/prompts/analyzer-user.ts +156 -0
- package/src/prompts/evolve-prompt.ts +71 -0
- package/src/scrubber.ts +42 -0
- package/src/storage.ts +91 -0
- package/src/tool-observer.ts +114 -0
- package/src/types.ts +90 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pi Continuous Learning Extension - Entry Point
|
|
3
|
+
*
|
|
4
|
+
* Observes coding sessions, records events as observations, and injects
|
|
5
|
+
* learned instincts into the agent's system prompt. Background analysis
|
|
6
|
+
* runs via a separate standalone script (src/cli/analyze.ts).
|
|
7
|
+
*/
|
|
8
|
+
import { loadSkills } from "@mariozechner/pi-coding-agent";
|
|
9
|
+
import { loadConfig } from "./config.js";
|
|
10
|
+
import { detectProject } from "./project.js";
|
|
11
|
+
import { ensureStorageLayout } from "./storage.js";
|
|
12
|
+
import { cleanOldArchives } from "./observations.js";
|
|
13
|
+
import { handleToolStart, handleToolEnd } from "./tool-observer.js";
|
|
14
|
+
import { handleBeforeAgentStart, handleAgentEnd } from "./prompt-observer.js";
|
|
15
|
+
import { handleBeforeAgentStartInjection, handleAgentEndClearInstincts, } from "./instinct-injector.js";
|
|
16
|
+
import { handleInstinctStatus, COMMAND_NAME as STATUS_CMD } from "./instinct-status.js";
|
|
17
|
+
import { handleInstinctExport, COMMAND_NAME as EXPORT_CMD } from "./instinct-export.js";
|
|
18
|
+
import { handleInstinctImport, COMMAND_NAME as IMPORT_CMD } from "./instinct-import.js";
|
|
19
|
+
import { handleInstinctPromote, COMMAND_NAME as PROMOTE_CMD } from "./instinct-promote.js";
|
|
20
|
+
import { handleInstinctEvolve, COMMAND_NAME as EVOLVE_CMD } from "./instinct-evolve.js";
|
|
21
|
+
import { handleInstinctProjects, COMMAND_NAME as PROJECTS_CMD } from "./instinct-projects.js";
|
|
22
|
+
import { registerAllTools } from "./instinct-tools.js";
|
|
23
|
+
import { logError } from "./error-logger.js";
|
|
24
|
+
export default function (pi) {
|
|
25
|
+
let config = null;
|
|
26
|
+
let project = null;
|
|
27
|
+
let installedSkills = [];
|
|
28
|
+
pi.on("session_start", async (_event, ctx) => {
|
|
29
|
+
try {
|
|
30
|
+
config = loadConfig();
|
|
31
|
+
project = await detectProject(pi, ctx.cwd);
|
|
32
|
+
ensureStorageLayout(project);
|
|
33
|
+
cleanOldArchives(project.id);
|
|
34
|
+
try {
|
|
35
|
+
const result = loadSkills({ cwd: ctx.cwd });
|
|
36
|
+
installedSkills = result.skills.map((s) => ({ name: s.name, description: s.description }));
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
installedSkills = [];
|
|
40
|
+
}
|
|
41
|
+
registerAllTools(pi, project.id, project.name);
|
|
42
|
+
}
|
|
43
|
+
catch (err) {
|
|
44
|
+
logError(project?.id ?? null, "session_start", err);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
pi.on("session_shutdown", (_event, _ctx) => {
|
|
48
|
+
// No cleanup needed — analyzer runs as external process
|
|
49
|
+
});
|
|
50
|
+
pi.on("before_agent_start", (event, ctx) => {
|
|
51
|
+
try {
|
|
52
|
+
if (!project || !config)
|
|
53
|
+
return;
|
|
54
|
+
handleBeforeAgentStart(event, ctx, project);
|
|
55
|
+
return handleBeforeAgentStartInjection(event, ctx, config, project.id) ?? undefined;
|
|
56
|
+
}
|
|
57
|
+
catch (err) {
|
|
58
|
+
logError(project?.id ?? null, "before_agent_start", err);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
pi.on("agent_start", (_event, _ctx) => { });
|
|
62
|
+
pi.on("agent_end", (event, ctx) => {
|
|
63
|
+
try {
|
|
64
|
+
if (!project)
|
|
65
|
+
return;
|
|
66
|
+
handleAgentEnd(event, ctx, project);
|
|
67
|
+
handleAgentEndClearInstincts(event, ctx);
|
|
68
|
+
}
|
|
69
|
+
catch (err) {
|
|
70
|
+
logError(project?.id ?? null, "agent_end", err);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
pi.on("tool_execution_start", (event, ctx) => {
|
|
74
|
+
try {
|
|
75
|
+
if (!project)
|
|
76
|
+
return;
|
|
77
|
+
handleToolStart(event, ctx, project);
|
|
78
|
+
}
|
|
79
|
+
catch (err) {
|
|
80
|
+
logError(project?.id ?? null, "tool_execution_start", err);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
pi.on("tool_execution_end", (event, ctx) => {
|
|
84
|
+
try {
|
|
85
|
+
if (!project)
|
|
86
|
+
return;
|
|
87
|
+
handleToolEnd(event, ctx, project);
|
|
88
|
+
}
|
|
89
|
+
catch (err) {
|
|
90
|
+
logError(project?.id ?? null, "tool_execution_end", err);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
pi.registerCommand(STATUS_CMD, {
|
|
94
|
+
description: "Show all instincts grouped by domain with confidence scores",
|
|
95
|
+
handler: (args, ctx) => handleInstinctStatus(args, ctx, project?.id),
|
|
96
|
+
});
|
|
97
|
+
pi.registerCommand(EXPORT_CMD, {
|
|
98
|
+
description: "Export instincts to a JSON file",
|
|
99
|
+
handler: (args, ctx) => handleInstinctExport(args, ctx, project?.id),
|
|
100
|
+
});
|
|
101
|
+
pi.registerCommand(IMPORT_CMD, {
|
|
102
|
+
description: "Import instincts from a JSON file",
|
|
103
|
+
handler: (args, ctx) => handleInstinctImport(args, ctx, project?.id),
|
|
104
|
+
});
|
|
105
|
+
pi.registerCommand(PROMOTE_CMD, {
|
|
106
|
+
description: "Promote project instincts to global scope",
|
|
107
|
+
handler: (args, ctx) => handleInstinctPromote(args, ctx, project?.id),
|
|
108
|
+
});
|
|
109
|
+
pi.registerCommand(EVOLVE_CMD, {
|
|
110
|
+
description: "Analyze instincts and suggest improvements (LLM-powered)",
|
|
111
|
+
handler: (args, ctx) => handleInstinctEvolve(args, ctx, pi, project?.id, undefined, project?.root ?? null, installedSkills),
|
|
112
|
+
});
|
|
113
|
+
pi.registerCommand(PROJECTS_CMD, {
|
|
114
|
+
description: "List all known projects and their instinct counts",
|
|
115
|
+
handler: (args, ctx) => handleInstinctProjects(args, ctx),
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAE3D,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACpE,OAAO,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC9E,OAAO,EACL,+BAA+B,EAC/B,4BAA4B,GAC7B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,oBAAoB,EAAE,YAAY,IAAI,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACxF,OAAO,EAAE,oBAAoB,EAAE,YAAY,IAAI,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACxF,OAAO,EAAE,oBAAoB,EAAE,YAAY,IAAI,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACxF,OAAO,EAAE,qBAAqB,EAAE,YAAY,IAAI,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAC3F,OAAO,EAAE,oBAAoB,EAAE,YAAY,IAAI,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACxF,OAAO,EAAE,sBAAsB,EAAE,YAAY,IAAI,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAC9F,OAAO,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,WAAW,EAAE,2CAA2C;QACxD,OAAO,EAAE,CAAC,IAAY,EAAE,GAA4B,EAAE,EAAE,CACtD,qBAAqB,CAAC,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,CAAC;KAChD,CAAC,CAAC;IAEH,EAAE,CAAC,eAAe,CAAC,UAAU,EAAE;QAC7B,WAAW,EAAE,0DAA0D;QACvE,OAAO,EAAE,CAAC,IAAY,EAAE,GAA4B,EAAE,EAAE,CACtD,oBAAoB,CAClB,IAAI,EACJ,GAAG,EACH,EAAE,EACF,OAAO,EAAE,EAAE,EACX,SAAS,EACT,OAAO,EAAE,IAAI,IAAI,IAAI,EACrB,eAAe,CAChB;KACJ,CAAC,CAAC;IAEH,EAAE,CAAC,eAAe,CAAC,YAAY,EAAE;QAC/B,WAAW,EAAE,mDAAmD;QAChE,OAAO,EAAE,CAAC,IAAY,EAAE,GAA4B,EAAE,EAAE,CACtD,sBAAsB,CAAC,IAAI,EAAE,GAAG,CAAC;KACpC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Passive confidence decay for instincts.
|
|
3
|
+
* Applied at the start of each analysis run to age out stale instincts.
|
|
4
|
+
*
|
|
5
|
+
* Decay: -0.02 per week since updated_at, clamped to [0.1, 0.9].
|
|
6
|
+
* Instincts dropping below 0.1 are flagged for removal.
|
|
7
|
+
*
|
|
8
|
+
* US-031: Passive Confidence Decay
|
|
9
|
+
*/
|
|
10
|
+
import type { Instinct } from "./types.js";
|
|
11
|
+
/**
|
|
12
|
+
* Applies passive decay to a single instinct.
|
|
13
|
+
*
|
|
14
|
+
* Returns the updated instinct (with adjusted confidence and refreshed
|
|
15
|
+
* updated_at) when the decay is significant, or null if no meaningful
|
|
16
|
+
* change occurred.
|
|
17
|
+
*
|
|
18
|
+
* Does not mutate the input instinct.
|
|
19
|
+
*/
|
|
20
|
+
export declare function applyDecayToInstinct(instinct: Instinct): Instinct | null;
|
|
21
|
+
/**
|
|
22
|
+
* Applies decay to all instincts found in a directory.
|
|
23
|
+
* Saves any instincts with meaningful confidence changes.
|
|
24
|
+
*
|
|
25
|
+
* @param dir - Directory containing .md instinct files
|
|
26
|
+
* @returns Number of instincts updated on disk
|
|
27
|
+
*/
|
|
28
|
+
export declare function applyDecayInDir(dir: string): number;
|
|
29
|
+
/**
|
|
30
|
+
* Runs a full decay pass over personal instincts for a project and globally.
|
|
31
|
+
* Called at the start of each analysis run, before the Haiku subprocess
|
|
32
|
+
* applies feedback adjustments.
|
|
33
|
+
*
|
|
34
|
+
* @param projectId - Project ID to decay (skipped when null/undefined)
|
|
35
|
+
* @param baseDir - Base storage directory (defaults to ~/.pi/continuous-learning/)
|
|
36
|
+
* @returns Total number of instincts updated across both scopes
|
|
37
|
+
*/
|
|
38
|
+
export declare function runDecayPass(projectId?: string | null, baseDir?: string): number;
|
|
39
|
+
//# sourceMappingURL=instinct-decay.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instinct-decay.d.ts","sourceRoot":"","sources":["../src/instinct-decay.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AASH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAiB3C;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,QAAQ,GAAG,QAAQ,GAAG,IAAI,CAyBxE;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAanD;AAED;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAC1B,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,EACzB,OAAO,SAAe,GACrB,MAAM,CAYR"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Passive confidence decay for instincts.
|
|
3
|
+
* Applied at the start of each analysis run to age out stale instincts.
|
|
4
|
+
*
|
|
5
|
+
* Decay: -0.02 per week since updated_at, clamped to [0.1, 0.9].
|
|
6
|
+
* Instincts dropping below 0.1 are flagged for removal.
|
|
7
|
+
*
|
|
8
|
+
* US-031: Passive Confidence Decay
|
|
9
|
+
*/
|
|
10
|
+
import { applyPassiveDecay } from "./confidence.js";
|
|
11
|
+
import { listInstincts, saveInstinct } from "./instinct-store.js";
|
|
12
|
+
import { getBaseDir, getProjectInstinctsDir, getGlobalInstinctsDir, } from "./storage.js";
|
|
13
|
+
// ---------------------------------------------------------------------------
|
|
14
|
+
// Constants
|
|
15
|
+
// ---------------------------------------------------------------------------
|
|
16
|
+
/**
|
|
17
|
+
* Minimum confidence change required to persist the instinct back to disk.
|
|
18
|
+
* Prevents excessive writes for negligibly small elapsed times.
|
|
19
|
+
* At 5-minute analysis intervals, elapsed decay is ~0.000002 - well below this.
|
|
20
|
+
*/
|
|
21
|
+
const DECAY_CHANGE_THRESHOLD = 0.001;
|
|
22
|
+
// ---------------------------------------------------------------------------
|
|
23
|
+
// Public API
|
|
24
|
+
// ---------------------------------------------------------------------------
|
|
25
|
+
/**
|
|
26
|
+
* Applies passive decay to a single instinct.
|
|
27
|
+
*
|
|
28
|
+
* Returns the updated instinct (with adjusted confidence and refreshed
|
|
29
|
+
* updated_at) when the decay is significant, or null if no meaningful
|
|
30
|
+
* change occurred.
|
|
31
|
+
*
|
|
32
|
+
* Does not mutate the input instinct.
|
|
33
|
+
*/
|
|
34
|
+
export function applyDecayToInstinct(instinct) {
|
|
35
|
+
const result = applyPassiveDecay(instinct.confidence, instinct.updated_at);
|
|
36
|
+
const decayAmount = Math.abs(result.confidence - instinct.confidence);
|
|
37
|
+
const flagChanged = Boolean(result.flaggedForRemoval) !== Boolean(instinct.flagged_for_removal);
|
|
38
|
+
if (decayAmount < DECAY_CHANGE_THRESHOLD && !flagChanged) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
const updated = {
|
|
42
|
+
...instinct,
|
|
43
|
+
confidence: result.confidence,
|
|
44
|
+
updated_at: new Date().toISOString(),
|
|
45
|
+
};
|
|
46
|
+
// Set or clear flagged_for_removal using delete pattern (exactOptionalPropertyTypes)
|
|
47
|
+
if (result.flaggedForRemoval) {
|
|
48
|
+
updated.flagged_for_removal = true;
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
delete updated.flagged_for_removal;
|
|
52
|
+
}
|
|
53
|
+
return updated;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Applies decay to all instincts found in a directory.
|
|
57
|
+
* Saves any instincts with meaningful confidence changes.
|
|
58
|
+
*
|
|
59
|
+
* @param dir - Directory containing .md instinct files
|
|
60
|
+
* @returns Number of instincts updated on disk
|
|
61
|
+
*/
|
|
62
|
+
export function applyDecayInDir(dir) {
|
|
63
|
+
const instincts = listInstincts(dir);
|
|
64
|
+
let updatedCount = 0;
|
|
65
|
+
for (const instinct of instincts) {
|
|
66
|
+
const updated = applyDecayToInstinct(instinct);
|
|
67
|
+
if (updated !== null) {
|
|
68
|
+
saveInstinct(updated, dir);
|
|
69
|
+
updatedCount++;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return updatedCount;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Runs a full decay pass over personal instincts for a project and globally.
|
|
76
|
+
* Called at the start of each analysis run, before the Haiku subprocess
|
|
77
|
+
* applies feedback adjustments.
|
|
78
|
+
*
|
|
79
|
+
* @param projectId - Project ID to decay (skipped when null/undefined)
|
|
80
|
+
* @param baseDir - Base storage directory (defaults to ~/.pi/continuous-learning/)
|
|
81
|
+
* @returns Total number of instincts updated across both scopes
|
|
82
|
+
*/
|
|
83
|
+
export function runDecayPass(projectId, baseDir = getBaseDir()) {
|
|
84
|
+
let total = 0;
|
|
85
|
+
if (projectId) {
|
|
86
|
+
const projectDir = getProjectInstinctsDir(projectId, "personal", baseDir);
|
|
87
|
+
total += applyDecayInDir(projectDir);
|
|
88
|
+
}
|
|
89
|
+
const globalDir = getGlobalInstinctsDir("personal", baseDir);
|
|
90
|
+
total += applyDecayInDir(globalDir);
|
|
91
|
+
return total;
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=instinct-decay.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instinct-decay.js","sourceRoot":"","sources":["../src/instinct-decay.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EACL,UAAU,EACV,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,cAAc,CAAC;AAGtB,8EAA8E;AAC9E,YAAY;AACZ,8EAA8E;AAE9E;;;;GAIG;AACH,MAAM,sBAAsB,GAAG,KAAK,CAAC;AAErC,8EAA8E;AAC9E,aAAa;AACb,8EAA8E;AAE9E;;;;;;;;GAQG;AACH,MAAM,UAAU,oBAAoB,CAAC,QAAkB;IACrD,MAAM,MAAM,GAAG,iBAAiB,CAAC,QAAQ,CAAC,UAAU,EAAE,QAAQ,CAAC,UAAU,CAAC,CAAC;IAE3E,MAAM,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,UAAU,GAAG,QAAQ,CAAC,UAAU,CAAC,CAAC;IACtE,MAAM,WAAW,GACf,OAAO,CAAC,MAAM,CAAC,iBAAiB,CAAC,KAAK,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAC,CAAC;IAE9E,IAAI,WAAW,GAAG,sBAAsB,IAAI,CAAC,WAAW,EAAE,CAAC;QACzD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,OAAO,GAAa;QACxB,GAAG,QAAQ;QACX,UAAU,EAAE,MAAM,CAAC,UAAU;QAC7B,UAAU,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;KACrC,CAAC;IAEF,qFAAqF;IACrF,IAAI,MAAM,CAAC,iBAAiB,EAAE,CAAC;QAC5B,OAA6B,CAAC,mBAAmB,GAAG,IAAI,CAAC;IAC5D,CAAC;SAAM,CAAC;QACN,OAAQ,OAA6B,CAAC,mBAAmB,CAAC;IAC5D,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,eAAe,CAAC,GAAW;IACzC,MAAM,SAAS,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC;IACrC,IAAI,YAAY,GAAG,CAAC,CAAC;IAErB,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;QACjC,MAAM,OAAO,GAAG,oBAAoB,CAAC,QAAQ,CAAC,CAAC;QAC/C,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;YACrB,YAAY,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;YAC3B,YAAY,EAAE,CAAC;QACjB,CAAC;IACH,CAAC;IAED,OAAO,YAAY,CAAC;AACtB,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,YAAY,CAC1B,SAAyB,EACzB,OAAO,GAAG,UAAU,EAAE;IAEtB,IAAI,KAAK,GAAG,CAAC,CAAC;IAEd,IAAI,SAAS,EAAE,CAAC;QACd,MAAM,UAAU,GAAG,sBAAsB,CAAC,SAAS,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;QAC1E,KAAK,IAAI,eAAe,CAAC,UAAU,CAAC,CAAC;IACvC,CAAC;IAED,MAAM,SAAS,GAAG,qBAAqB,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IAC7D,KAAK,IAAI,eAAe,CAAC,SAAS,CAAC,CAAC;IAEpC,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ExtensionAPI, ExtensionCommandContext } from "@mariozechner/pi-coding-agent";
|
|
2
|
+
import type { InstalledSkill } from "./types.js";
|
|
3
|
+
export declare const COMMAND_NAME = "instinct-evolve";
|
|
4
|
+
export declare function handleInstinctEvolve(_args: string, ctx: ExtensionCommandContext, pi: ExtensionAPI, projectId?: string | null, baseDir?: string, projectRoot?: string | null, installedSkills?: InstalledSkill[]): Promise<void>;
|
|
5
|
+
//# sourceMappingURL=instinct-evolve.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instinct-evolve.d.ts","sourceRoot":"","sources":["../src/instinct-evolve.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AAC3F,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAWjD,eAAO,MAAM,YAAY,oBAAoB,CAAC;AAE9C,wBAAsB,oBAAoB,CACxC,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,uBAAuB,EAC5B,EAAE,EAAE,YAAY,EAChB,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,EACzB,OAAO,CAAC,EAAE,MAAM,EAChB,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,EAC3B,eAAe,CAAC,EAAE,cAAc,EAAE,GACjC,OAAO,CAAC,IAAI,CAAC,CAqBf"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { homedir } from "node:os";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { getBaseDir } from "./storage.js";
|
|
4
|
+
import { readAgentsMd } from "./agents-md.js";
|
|
5
|
+
import { loadProjectInstincts, loadGlobalInstincts } from "./instinct-store.js";
|
|
6
|
+
import { filterInstincts } from "./instinct-loader.js";
|
|
7
|
+
import { buildEvolvePrompt } from "./prompts/evolve-prompt.js";
|
|
8
|
+
const MAX_EVOLVE_INSTINCTS = 100;
|
|
9
|
+
export const COMMAND_NAME = "instinct-evolve";
|
|
10
|
+
export async function handleInstinctEvolve(_args, ctx, pi, projectId, baseDir, projectRoot, installedSkills) {
|
|
11
|
+
const effectiveBase = baseDir ?? getBaseDir();
|
|
12
|
+
const projectInstincts = projectId ? loadProjectInstincts(projectId, effectiveBase) : [];
|
|
13
|
+
const globalInstincts = loadGlobalInstincts(effectiveBase);
|
|
14
|
+
const allInstincts = filterInstincts([...projectInstincts, ...globalInstincts], 0.1, MAX_EVOLVE_INSTINCTS);
|
|
15
|
+
if (allInstincts.length === 0) {
|
|
16
|
+
ctx.ui.notify("No instincts to analyze. Keep using pi to accumulate instincts first.", "info");
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const agentsMdProject = projectRoot != null ? readAgentsMd(join(projectRoot, "AGENTS.md")) : null;
|
|
20
|
+
const agentsMdGlobal = readAgentsMd(join(homedir(), ".pi", "agent", "AGENTS.md"));
|
|
21
|
+
const prompt = buildEvolvePrompt(allInstincts, agentsMdProject, agentsMdGlobal, installedSkills);
|
|
22
|
+
pi.sendUserMessage(prompt, { deliverAs: "followUp" });
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=instinct-evolve.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instinct-evolve.js","sourceRoot":"","sources":["../src/instinct-evolve.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAChF,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAE/D,MAAM,oBAAoB,GAAG,GAAG,CAAC;AAEjC,MAAM,CAAC,MAAM,YAAY,GAAG,iBAAiB,CAAC;AAE9C,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,KAAa,EACb,GAA4B,EAC5B,EAAgB,EAChB,SAAyB,EACzB,OAAgB,EAChB,WAA2B,EAC3B,eAAkC;IAElC,MAAM,aAAa,GAAG,OAAO,IAAI,UAAU,EAAE,CAAC;IAC9C,MAAM,gBAAgB,GAAG,SAAS,CAAC,CAAC,CAAC,oBAAoB,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACzF,MAAM,eAAe,GAAG,mBAAmB,CAAC,aAAa,CAAC,CAAC;IAC3D,MAAM,YAAY,GAAG,eAAe,CAClC,CAAC,GAAG,gBAAgB,EAAE,GAAG,eAAe,CAAC,EACzC,GAAG,EACH,oBAAoB,CACrB,CAAC;IAEF,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC9B,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,uEAAuE,EAAE,MAAM,CAAC,CAAC;QAC/F,OAAO;IACT,CAAC;IAED,MAAM,eAAe,GACnB,WAAW,IAAI,IAAI,CAAC,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAC5E,MAAM,cAAc,GAAG,YAAY,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC;IAElF,MAAM,MAAM,GAAG,iBAAiB,CAAC,YAAY,EAAE,eAAe,EAAE,cAAc,EAAE,eAAe,CAAC,CAAC;IACjG,EAAE,CAAC,eAAe,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC,CAAC;AACxD,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* /instinct-export command for pi-continuous-learning.
|
|
3
|
+
* Exports instincts to a JSON file in the current directory.
|
|
4
|
+
* Optional args: scope (project|global) and domain filter.
|
|
5
|
+
*/
|
|
6
|
+
import type { ExtensionCommandContext } from "@mariozechner/pi-coding-agent";
|
|
7
|
+
import type { Instinct, InstinctScope } from "./types.js";
|
|
8
|
+
declare const COMMAND_NAME = "instinct-export";
|
|
9
|
+
export interface ExportArgs {
|
|
10
|
+
scope: InstinctScope | null;
|
|
11
|
+
domain: string | null;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Parses space-separated args string.
|
|
15
|
+
* If first token is "project" or "global", it is treated as scope filter.
|
|
16
|
+
* Remaining tokens (if any) are joined as domain filter.
|
|
17
|
+
*/
|
|
18
|
+
export declare function parseExportArgs(args: string): ExportArgs;
|
|
19
|
+
/**
|
|
20
|
+
* Filters instincts by optional scope and domain.
|
|
21
|
+
* Immutable - returns a new array.
|
|
22
|
+
*/
|
|
23
|
+
export declare function filterInstinctsForExport(instincts: Instinct[], scope: InstinctScope | null, domain: string | null): Instinct[];
|
|
24
|
+
/**
|
|
25
|
+
* Generates an export filename with timestamp.
|
|
26
|
+
* Format: instincts-export-<YYYYMMDDTHHmmss>.json
|
|
27
|
+
*/
|
|
28
|
+
export declare function buildExportFilename(now?: Date): string;
|
|
29
|
+
/**
|
|
30
|
+
* Loads instincts from disk (project + global) for export.
|
|
31
|
+
* Does NOT apply confidence filtering - export includes everything.
|
|
32
|
+
*/
|
|
33
|
+
export declare function loadAllInstinctsForExport(projectId?: string | null, baseDir?: string): Instinct[];
|
|
34
|
+
/**
|
|
35
|
+
* Command handler for /instinct-export.
|
|
36
|
+
* Loads instincts, applies optional filters, writes JSON file to cwd.
|
|
37
|
+
*/
|
|
38
|
+
export declare function handleInstinctExport(args: string, ctx: ExtensionCommandContext, projectId?: string | null, baseDir?: string): Promise<void>;
|
|
39
|
+
export { COMMAND_NAME };
|
|
40
|
+
//# sourceMappingURL=instinct-export.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instinct-export.d.ts","sourceRoot":"","sources":["../src/instinct-export.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AAC7E,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAO1D,QAAA,MAAM,YAAY,oBAAoB,CAAC;AASvC,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,aAAa,GAAG,IAAI,CAAC;IAC5B,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;CACvB;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,CAcxD;AAMD;;;GAGG;AACH,wBAAgB,wBAAwB,CACtC,SAAS,EAAE,QAAQ,EAAE,EACrB,KAAK,EAAE,aAAa,GAAG,IAAI,EAC3B,MAAM,EAAE,MAAM,GAAG,IAAI,GACpB,QAAQ,EAAE,CAMZ;AAMD;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,GAAE,IAAiB,GAAG,MAAM,CAQlE;AAMD;;;GAGG;AACH,wBAAgB,yBAAyB,CACvC,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,EACzB,OAAO,CAAC,EAAE,MAAM,GACf,QAAQ,EAAE,CAKZ;AAMD;;;GAGG;AACH,wBAAsB,oBAAoB,CACxC,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,uBAAuB,EAC5B,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,EACzB,OAAO,CAAC,EAAE,MAAM,GACf,OAAO,CAAC,IAAI,CAAC,CAef;AAED,OAAO,EAAE,YAAY,EAAE,CAAC"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* /instinct-export command for pi-continuous-learning.
|
|
3
|
+
* Exports instincts to a JSON file in the current directory.
|
|
4
|
+
* Optional args: scope (project|global) and domain filter.
|
|
5
|
+
*/
|
|
6
|
+
import { writeFileSync } from "node:fs";
|
|
7
|
+
import { join } from "node:path";
|
|
8
|
+
import { loadProjectInstincts, loadGlobalInstincts } from "./instinct-store.js";
|
|
9
|
+
// ---------------------------------------------------------------------------
|
|
10
|
+
// Constants
|
|
11
|
+
// ---------------------------------------------------------------------------
|
|
12
|
+
const COMMAND_NAME = "instinct-export";
|
|
13
|
+
const SCOPE_PROJECT = "project";
|
|
14
|
+
const SCOPE_GLOBAL = "global";
|
|
15
|
+
const VALID_SCOPES = [SCOPE_PROJECT, SCOPE_GLOBAL];
|
|
16
|
+
/**
|
|
17
|
+
* Parses space-separated args string.
|
|
18
|
+
* If first token is "project" or "global", it is treated as scope filter.
|
|
19
|
+
* Remaining tokens (if any) are joined as domain filter.
|
|
20
|
+
*/
|
|
21
|
+
export function parseExportArgs(args) {
|
|
22
|
+
const tokens = args.trim().split(/\s+/).filter(Boolean);
|
|
23
|
+
if (tokens.length === 0) {
|
|
24
|
+
return { scope: null, domain: null };
|
|
25
|
+
}
|
|
26
|
+
const first = tokens[0] ?? "";
|
|
27
|
+
const isScope = VALID_SCOPES.includes(first);
|
|
28
|
+
const scope = isScope ? first : null;
|
|
29
|
+
const domainTokens = isScope ? tokens.slice(1) : tokens;
|
|
30
|
+
const domain = domainTokens.length > 0 ? domainTokens.join(" ") : null;
|
|
31
|
+
return { scope, domain };
|
|
32
|
+
}
|
|
33
|
+
// ---------------------------------------------------------------------------
|
|
34
|
+
// Filtering
|
|
35
|
+
// ---------------------------------------------------------------------------
|
|
36
|
+
/**
|
|
37
|
+
* Filters instincts by optional scope and domain.
|
|
38
|
+
* Immutable - returns a new array.
|
|
39
|
+
*/
|
|
40
|
+
export function filterInstinctsForExport(instincts, scope, domain) {
|
|
41
|
+
return instincts.filter((instinct) => {
|
|
42
|
+
if (scope !== null && instinct.scope !== scope)
|
|
43
|
+
return false;
|
|
44
|
+
if (domain !== null && instinct.domain !== domain)
|
|
45
|
+
return false;
|
|
46
|
+
return true;
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
// ---------------------------------------------------------------------------
|
|
50
|
+
// Filename generation
|
|
51
|
+
// ---------------------------------------------------------------------------
|
|
52
|
+
/**
|
|
53
|
+
* Generates an export filename with timestamp.
|
|
54
|
+
* Format: instincts-export-<YYYYMMDDTHHmmss>.json
|
|
55
|
+
*/
|
|
56
|
+
export function buildExportFilename(now = new Date()) {
|
|
57
|
+
const iso = now.toISOString(); // "2026-03-26T17:12:20.216Z"
|
|
58
|
+
// Compact: remove dashes, colons, milliseconds, and trailing Z
|
|
59
|
+
const compact = iso
|
|
60
|
+
.replace(/-/g, "")
|
|
61
|
+
.replace(/:/g, "")
|
|
62
|
+
.replace(/\.\d+Z$/, "");
|
|
63
|
+
return `instincts-export-${compact}.json`;
|
|
64
|
+
}
|
|
65
|
+
// ---------------------------------------------------------------------------
|
|
66
|
+
// loadAllInstinctsForExport
|
|
67
|
+
// ---------------------------------------------------------------------------
|
|
68
|
+
/**
|
|
69
|
+
* Loads instincts from disk (project + global) for export.
|
|
70
|
+
* Does NOT apply confidence filtering - export includes everything.
|
|
71
|
+
*/
|
|
72
|
+
export function loadAllInstinctsForExport(projectId, baseDir) {
|
|
73
|
+
const projectInstincts = projectId != null ? loadProjectInstincts(projectId, baseDir) : [];
|
|
74
|
+
const globalInstincts = loadGlobalInstincts(baseDir);
|
|
75
|
+
return [...projectInstincts, ...globalInstincts];
|
|
76
|
+
}
|
|
77
|
+
// ---------------------------------------------------------------------------
|
|
78
|
+
// handleInstinctExport
|
|
79
|
+
// ---------------------------------------------------------------------------
|
|
80
|
+
/**
|
|
81
|
+
* Command handler for /instinct-export.
|
|
82
|
+
* Loads instincts, applies optional filters, writes JSON file to cwd.
|
|
83
|
+
*/
|
|
84
|
+
export async function handleInstinctExport(args, ctx, projectId, baseDir) {
|
|
85
|
+
const { scope, domain } = parseExportArgs(args);
|
|
86
|
+
const all = loadAllInstinctsForExport(projectId, baseDir);
|
|
87
|
+
const filtered = filterInstinctsForExport(all, scope, domain);
|
|
88
|
+
const filename = buildExportFilename();
|
|
89
|
+
const outputPath = join(ctx.cwd, filename);
|
|
90
|
+
writeFileSync(outputPath, JSON.stringify(filtered, null, 2), "utf-8");
|
|
91
|
+
ctx.ui.notify(`Exported ${filtered.length} instinct${filtered.length !== 1 ? "s" : ""} to ${outputPath}`, "info");
|
|
92
|
+
}
|
|
93
|
+
export { COMMAND_NAME };
|
|
94
|
+
//# sourceMappingURL=instinct-export.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instinct-export.js","sourceRoot":"","sources":["../src/instinct-export.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAGjC,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAEhF,8EAA8E;AAC9E,YAAY;AACZ,8EAA8E;AAE9E,MAAM,YAAY,GAAG,iBAAiB,CAAC;AACvC,MAAM,aAAa,GAAkB,SAAS,CAAC;AAC/C,MAAM,YAAY,GAAkB,QAAQ,CAAC;AAC7C,MAAM,YAAY,GAAsB,CAAC,aAAa,EAAE,YAAY,CAAC,CAAC;AAWtE;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,IAAY;IAC1C,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACxD,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxB,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;IACvC,CAAC;IAED,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IAC9B,MAAM,OAAO,GAAG,YAAY,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAE7C,MAAM,KAAK,GAAG,OAAO,CAAC,CAAC,CAAE,KAAuB,CAAC,CAAC,CAAC,IAAI,CAAC;IACxD,MAAM,YAAY,GAAG,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,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
4
|
+
* Destination is determined by each instinct's scope field:
|
|
5
|
+
* - scope "project" -> projects/<id>/instincts/inherited/
|
|
6
|
+
* - scope "global" -> instincts/inherited/
|
|
7
|
+
*/
|
|
8
|
+
import type { ExtensionCommandContext } from "@mariozechner/pi-coding-agent";
|
|
9
|
+
import type { Instinct } from "./types.js";
|
|
10
|
+
export declare const COMMAND_NAME = "instinct-import";
|
|
11
|
+
export interface ValidationError {
|
|
12
|
+
index: number;
|
|
13
|
+
reason: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Validates a raw JSON object as an Instinct.
|
|
17
|
+
* Returns an error string if invalid, null if valid.
|
|
18
|
+
*/
|
|
19
|
+
export declare function validateImportObject(obj: unknown, index: number): ValidationError | null;
|
|
20
|
+
export interface LoadResult {
|
|
21
|
+
valid: Instinct[];
|
|
22
|
+
invalid: ValidationError[];
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Reads and parses the import JSON file.
|
|
26
|
+
* Returns valid instincts and validation errors separately.
|
|
27
|
+
*/
|
|
28
|
+
export declare function loadImportFile(filePath: string): LoadResult;
|
|
29
|
+
export interface PartitionResult {
|
|
30
|
+
toImport: Instinct[];
|
|
31
|
+
duplicates: string[];
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Partitions instincts into those to import and those skipped as duplicates.
|
|
35
|
+
* Checks existing inherited instincts in both project and global directories.
|
|
36
|
+
*/
|
|
37
|
+
export declare function partitionByDuplicates(instincts: Instinct[], projectId: string | null | undefined, baseDir: string): PartitionResult;
|
|
38
|
+
/**
|
|
39
|
+
* Returns the inherited instincts directory for the given instinct.
|
|
40
|
+
* Project-scoped instincts go into the project's inherited dir.
|
|
41
|
+
* Global instincts go into the global inherited dir.
|
|
42
|
+
*/
|
|
43
|
+
export declare function getTargetDir(instinct: Instinct, projectId: string | null | undefined, baseDir: string): string;
|
|
44
|
+
/**
|
|
45
|
+
* Command handler for /instinct-import.
|
|
46
|
+
* Reads the JSON file at the given path, validates each instinct,
|
|
47
|
+
* skips duplicates, and saves valid instincts to inherited/ directories.
|
|
48
|
+
*/
|
|
49
|
+
export declare function handleInstinctImport(args: string, ctx: ExtensionCommandContext, projectId?: string | null, baseDir?: string): Promise<void>;
|
|
50
|
+
//# sourceMappingURL=instinct-import.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instinct-import.d.ts","sourceRoot":"","sources":["../src/instinct-import.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AAC7E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAY3C,eAAO,MAAM,YAAY,oBAAoB,CAAC;AAwB9C,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,GAAG,EAAE,OAAO,EACZ,KAAK,EAAE,MAAM,GACZ,eAAe,GAAG,IAAI,CAmBxB;AAMD,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,QAAQ,EAAE,CAAC;IAClB,OAAO,EAAE,eAAe,EAAE,CAAC;CAC5B;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,UAAU,CAqB3D;AAMD,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,QAAQ,EAAE,CAAC;IACrB,UAAU,EAAE,MAAM,EAAE,CAAC;CACtB;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,SAAS,EAAE,QAAQ,EAAE,EACrB,SAAS,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EACpC,OAAO,EAAE,MAAM,GACd,eAAe,CA2BjB;AAMD;;;;GAIG;AACH,wBAAgB,YAAY,CAC1B,QAAQ,EAAE,QAAQ,EAClB,SAAS,EAAE,MAAM,GAAG,IAAI,GA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