takomi 2.1.13 → 2.1.15
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/.pi/agents/architect.md +73 -73
- package/.pi/agents/coder.md +70 -70
- package/.pi/agents/designer.md +72 -72
- package/.pi/agents/orchestrator.md +122 -122
- package/.pi/agents/reviewer.md +71 -71
- package/.pi/extensions/oauth-router/provider.ts +3 -1
- package/.pi/extensions/takomi-context-manager/config.ts +48 -48
- package/.pi/extensions/takomi-context-manager/context-router.ts +57 -57
- package/.pi/extensions/takomi-context-manager/diagnostics-tools.ts +28 -28
- package/.pi/extensions/takomi-context-manager/diagnostics.ts +55 -55
- package/.pi/extensions/takomi-context-manager/extension-conflicts.ts +56 -56
- package/.pi/extensions/takomi-context-manager/index.ts +56 -56
- package/.pi/extensions/takomi-context-manager/model-policy-gate.ts +228 -206
- package/.pi/extensions/takomi-context-manager/policy-registry.ts +97 -97
- package/.pi/extensions/takomi-context-manager/policy-tools.ts +35 -35
- package/.pi/extensions/takomi-context-manager/prerequisite-gates.ts +39 -39
- package/.pi/extensions/takomi-context-manager/prompt-rewriter.ts +100 -100
- package/.pi/extensions/takomi-context-manager/skill-registry.ts +87 -87
- package/.pi/extensions/takomi-context-manager/skill-tools.ts +80 -80
- package/.pi/extensions/takomi-context-manager/state.ts +68 -68
- package/.pi/extensions/takomi-context-manager/types.ts +77 -77
- package/.pi/extensions/takomi-runtime/command-text.ts +10 -2
- package/.pi/extensions/takomi-runtime/commands.ts +78 -5
- package/.pi/extensions/takomi-runtime/routing-policy.ts +187 -145
- package/.pi/extensions/takomi-subagents/native-render.ts +41 -41
- package/.pi/extensions/takomi-subagents/pi-subagents-internal.ts +35 -32
- package/.pi/extensions/takomi-subagents/run-types.ts +25 -25
- package/.pi/prompts/build-prompt.md +259 -259
- package/.pi/prompts/design-prompt.md +95 -95
- package/.pi/prompts/genesis-prompt.md +140 -140
- package/.pi/prompts/prime-prompt.md +110 -110
- package/.pi/themes/takomi-aurora.json +88 -88
- package/README.md +2 -4
- package/assets/.agent/skills/21st-dev-components/SKILL.md +244 -244
- package/assets/.agent/skills/anti-gravity/SKILL.md +112 -0
- package/assets/.agent/skills/gemini/SKILL.md +14 -223
- package/assets/.agent/skills/git-commit-generation/SKILL.md +195 -0
- package/package.json +1 -1
- package/src/pi-takomi-core/validation.ts +135 -135
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
|
|
2
|
-
import { Type } from "typebox";
|
|
3
|
-
import type { ContextManagerState } from "./state";
|
|
4
|
-
import { renderReport } from "./diagnostics";
|
|
5
|
-
|
|
6
|
-
export function registerDiagnostics(pi: ExtensionAPI, state: ContextManagerState): void {
|
|
7
|
-
pi.registerTool({
|
|
8
|
-
name: "context_report",
|
|
9
|
-
label: "Context Report",
|
|
10
|
-
description: "Show takomi-context-manager diagnostics for prompt rewriting, candidates, policies, gates, and progressive skill loading.",
|
|
11
|
-
promptSnippet: "Show context manager diagnostics and prompt composition decisions",
|
|
12
|
-
parameters: Type.Object({ verbose: Type.Optional(Type.Boolean({ description: "Include skill and policy indexes in the report" })) }),
|
|
13
|
-
async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
|
|
14
|
-
state.report.cwd = ctx.cwd;
|
|
15
|
-
state.report.toolCalls.contextReport += 1;
|
|
16
|
-
return { content: [{ type: "text", text: renderReport(state, params.verbose ?? false) }], details: state.report };
|
|
17
|
-
},
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
pi.registerCommand("context-report", {
|
|
21
|
-
description: "Show takomi-context-manager diagnostics",
|
|
22
|
-
handler: async (_args, ctx) => {
|
|
23
|
-
state.report.cwd = ctx.cwd;
|
|
24
|
-
state.report.toolCalls.contextReport += 1;
|
|
25
|
-
ctx.ui.notify(renderReport(state, true), "info");
|
|
26
|
-
},
|
|
27
|
-
});
|
|
28
|
-
}
|
|
1
|
+
import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
|
|
2
|
+
import { Type } from "typebox";
|
|
3
|
+
import type { ContextManagerState } from "./state";
|
|
4
|
+
import { renderReport } from "./diagnostics";
|
|
5
|
+
|
|
6
|
+
export function registerDiagnostics(pi: ExtensionAPI, state: ContextManagerState): void {
|
|
7
|
+
pi.registerTool({
|
|
8
|
+
name: "context_report",
|
|
9
|
+
label: "Context Report",
|
|
10
|
+
description: "Show takomi-context-manager diagnostics for prompt rewriting, candidates, policies, gates, and progressive skill loading.",
|
|
11
|
+
promptSnippet: "Show context manager diagnostics and prompt composition decisions",
|
|
12
|
+
parameters: Type.Object({ verbose: Type.Optional(Type.Boolean({ description: "Include skill and policy indexes in the report" })) }),
|
|
13
|
+
async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
|
|
14
|
+
state.report.cwd = ctx.cwd;
|
|
15
|
+
state.report.toolCalls.contextReport += 1;
|
|
16
|
+
return { content: [{ type: "text", text: renderReport(state, params.verbose ?? false) }], details: state.report };
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
pi.registerCommand("context-report", {
|
|
21
|
+
description: "Show takomi-context-manager diagnostics",
|
|
22
|
+
handler: async (_args, ctx) => {
|
|
23
|
+
state.report.cwd = ctx.cwd;
|
|
24
|
+
state.report.toolCalls.contextReport += 1;
|
|
25
|
+
ctx.ui.notify(renderReport(state, true), "info");
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
}
|
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
import type { ContextManagerState } from "./state";
|
|
2
|
-
import { sortedSkills } from "./skill-registry";
|
|
3
|
-
import { syncReportLedger } from "./state";
|
|
4
|
-
import { renderDuplicateExtensionGuidance } from "./extension-conflicts";
|
|
5
|
-
|
|
6
|
-
export function renderReport(state: ContextManagerState, verbose = false): string {
|
|
7
|
-
syncReportLedger(state);
|
|
8
|
-
const report = state.report;
|
|
9
|
-
const reduction = report.promptRewrite.originalLength > 0
|
|
10
|
-
? Math.round((1 - report.promptRewrite.rewrittenLength / report.promptRewrite.originalLength) * 1000) / 10
|
|
11
|
-
: 0;
|
|
12
|
-
const lines = [
|
|
13
|
-
"Takomi Context Manager Report",
|
|
14
|
-
`- Timestamp: ${report.timestamp}`,
|
|
15
|
-
`- CWD: ${report.cwd || "(unknown)"}`,
|
|
16
|
-
"- Scope: latest context-manager prompt rewrite and context-manager tool state only; this is not a full Pi session transcript.",
|
|
17
|
-
`- Skill count discovered: ${report.skillCount}`,
|
|
18
|
-
`- Prompt rewrite attempted: ${report.promptRewrite.attempted ? "yes" : "no"}`,
|
|
19
|
-
`- Prompt changed: ${report.promptRewrite.changed ? "yes" : "no"}`,
|
|
20
|
-
`- Original prompt length observed by context manager: ${report.promptRewrite.originalLength} chars`,
|
|
21
|
-
`- Rewritten prompt length returned by context manager: ${report.promptRewrite.rewrittenLength} chars`,
|
|
22
|
-
`- Context-manager prompt reduction: ${reduction}%`,
|
|
23
|
-
`- Sections compressed/removed by context manager: ${report.promptRewrite.removedSections.join(", ") || "none"}`,
|
|
24
|
-
`- Skills loaded through skill_load: ${report.loadedByTool.join(", ") || "none"}`,
|
|
25
|
-
`- Policies loaded through policy_load/gates: ${report.loadedPolicies.join(", ") || "none"}`,
|
|
26
|
-
`- Context-manager tracked read files: ${report.readFiles.length}`,
|
|
27
|
-
`- Context-manager tracked edited files: ${report.editedFiles.length}`,
|
|
28
|
-
`- Context-manager tracked written files: ${report.writtenFiles.length}`,
|
|
29
|
-
`- Blocked context-manager gated actions: ${report.blockedActions.length}`,
|
|
30
|
-
`- Duplicate Takomi extension tool-name warnings: ${report.duplicateExtensionWarnings.length}`,
|
|
31
|
-
`- Context-manager tool calls: skill_index=${report.toolCalls.skillIndex}, skill_manifest=${report.toolCalls.skillManifest}, skill_load=${report.toolCalls.skillLoad}, policy_manifest=${report.toolCalls.policyManifest}, policy_load=${report.toolCalls.policyLoad}, context_report=${report.toolCalls.contextReport}`,
|
|
32
|
-
`- Rewrite warnings: ${report.promptRewrite.warnings.join("; ") || "none"}`,
|
|
33
|
-
"- Note: native Pi read/edit/write/bash calls are not counted here unless a context-manager tool explicitly records them.",
|
|
34
|
-
];
|
|
35
|
-
if (report.candidates.length > 0) {
|
|
36
|
-
lines.push("- Candidates:");
|
|
37
|
-
for (const candidate of report.candidates) {
|
|
38
|
-
lines.push(` - ${candidate.name} (${candidate.confidence}, ${candidate.score}): ${candidate.reasons.join("; ")}`);
|
|
39
|
-
}
|
|
40
|
-
} else {
|
|
41
|
-
lines.push("- Candidates: none");
|
|
42
|
-
}
|
|
43
|
-
if (report.duplicateExtensionWarnings.length > 0 || verbose) {
|
|
44
|
-
lines.push("", "Extension Conflict Diagnostics:", ...renderDuplicateExtensionGuidance(report.duplicateExtensionWarnings));
|
|
45
|
-
}
|
|
46
|
-
if (verbose) {
|
|
47
|
-
lines.push("", "Skill Index:", ...sortedSkills(state.skills).map((skill) => `- ${skill.name}`));
|
|
48
|
-
lines.push("", "Policy Packs:", ...[...state.policies.values()].map((policy) => `- ${policy.name}: ${policy.description}`));
|
|
49
|
-
if (report.blockedActions.length > 0) {
|
|
50
|
-
lines.push("", "Blocked Actions:");
|
|
51
|
-
for (const action of report.blockedActions.slice(-10)) lines.push(`- ${action.timestamp} ${action.toolName}: ${action.reason}`);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
return lines.join("\n");
|
|
55
|
-
}
|
|
1
|
+
import type { ContextManagerState } from "./state";
|
|
2
|
+
import { sortedSkills } from "./skill-registry";
|
|
3
|
+
import { syncReportLedger } from "./state";
|
|
4
|
+
import { renderDuplicateExtensionGuidance } from "./extension-conflicts";
|
|
5
|
+
|
|
6
|
+
export function renderReport(state: ContextManagerState, verbose = false): string {
|
|
7
|
+
syncReportLedger(state);
|
|
8
|
+
const report = state.report;
|
|
9
|
+
const reduction = report.promptRewrite.originalLength > 0
|
|
10
|
+
? Math.round((1 - report.promptRewrite.rewrittenLength / report.promptRewrite.originalLength) * 1000) / 10
|
|
11
|
+
: 0;
|
|
12
|
+
const lines = [
|
|
13
|
+
"Takomi Context Manager Report",
|
|
14
|
+
`- Timestamp: ${report.timestamp}`,
|
|
15
|
+
`- CWD: ${report.cwd || "(unknown)"}`,
|
|
16
|
+
"- Scope: latest context-manager prompt rewrite and context-manager tool state only; this is not a full Pi session transcript.",
|
|
17
|
+
`- Skill count discovered: ${report.skillCount}`,
|
|
18
|
+
`- Prompt rewrite attempted: ${report.promptRewrite.attempted ? "yes" : "no"}`,
|
|
19
|
+
`- Prompt changed: ${report.promptRewrite.changed ? "yes" : "no"}`,
|
|
20
|
+
`- Original prompt length observed by context manager: ${report.promptRewrite.originalLength} chars`,
|
|
21
|
+
`- Rewritten prompt length returned by context manager: ${report.promptRewrite.rewrittenLength} chars`,
|
|
22
|
+
`- Context-manager prompt reduction: ${reduction}%`,
|
|
23
|
+
`- Sections compressed/removed by context manager: ${report.promptRewrite.removedSections.join(", ") || "none"}`,
|
|
24
|
+
`- Skills loaded through skill_load: ${report.loadedByTool.join(", ") || "none"}`,
|
|
25
|
+
`- Policies loaded through policy_load/gates: ${report.loadedPolicies.join(", ") || "none"}`,
|
|
26
|
+
`- Context-manager tracked read files: ${report.readFiles.length}`,
|
|
27
|
+
`- Context-manager tracked edited files: ${report.editedFiles.length}`,
|
|
28
|
+
`- Context-manager tracked written files: ${report.writtenFiles.length}`,
|
|
29
|
+
`- Blocked context-manager gated actions: ${report.blockedActions.length}`,
|
|
30
|
+
`- Duplicate Takomi extension tool-name warnings: ${report.duplicateExtensionWarnings.length}`,
|
|
31
|
+
`- Context-manager tool calls: skill_index=${report.toolCalls.skillIndex}, skill_manifest=${report.toolCalls.skillManifest}, skill_load=${report.toolCalls.skillLoad}, policy_manifest=${report.toolCalls.policyManifest}, policy_load=${report.toolCalls.policyLoad}, context_report=${report.toolCalls.contextReport}`,
|
|
32
|
+
`- Rewrite warnings: ${report.promptRewrite.warnings.join("; ") || "none"}`,
|
|
33
|
+
"- Note: native Pi read/edit/write/bash calls are not counted here unless a context-manager tool explicitly records them.",
|
|
34
|
+
];
|
|
35
|
+
if (report.candidates.length > 0) {
|
|
36
|
+
lines.push("- Candidates:");
|
|
37
|
+
for (const candidate of report.candidates) {
|
|
38
|
+
lines.push(` - ${candidate.name} (${candidate.confidence}, ${candidate.score}): ${candidate.reasons.join("; ")}`);
|
|
39
|
+
}
|
|
40
|
+
} else {
|
|
41
|
+
lines.push("- Candidates: none");
|
|
42
|
+
}
|
|
43
|
+
if (report.duplicateExtensionWarnings.length > 0 || verbose) {
|
|
44
|
+
lines.push("", "Extension Conflict Diagnostics:", ...renderDuplicateExtensionGuidance(report.duplicateExtensionWarnings));
|
|
45
|
+
}
|
|
46
|
+
if (verbose) {
|
|
47
|
+
lines.push("", "Skill Index:", ...sortedSkills(state.skills).map((skill) => `- ${skill.name}`));
|
|
48
|
+
lines.push("", "Policy Packs:", ...[...state.policies.values()].map((policy) => `- ${policy.name}: ${policy.description}`));
|
|
49
|
+
if (report.blockedActions.length > 0) {
|
|
50
|
+
lines.push("", "Blocked Actions:");
|
|
51
|
+
for (const action of report.blockedActions.slice(-10)) lines.push(`- ${action.timestamp} ${action.toolName}: ${action.reason}`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return lines.join("\n");
|
|
55
|
+
}
|
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
import { access } from "node:fs/promises";
|
|
2
|
-
import os from "node:os";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
import type { ContextManagerState } from "./state";
|
|
5
|
-
|
|
6
|
-
type KnownTakomiExtension = {
|
|
7
|
-
toolName: string;
|
|
8
|
-
relativePath: string;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
const KNOWN_TAKOMI_EXTENSIONS: KnownTakomiExtension[] = [
|
|
12
|
-
{ toolName: "takomi_workflow", relativePath: path.join("takomi-runtime", "index.ts") },
|
|
13
|
-
{ toolName: "takomi_board", relativePath: path.join("takomi-runtime", "index.ts") },
|
|
14
|
-
{ toolName: "takomi_subagent", relativePath: path.join("takomi-subagents", "index.ts") },
|
|
15
|
-
];
|
|
16
|
-
|
|
17
|
-
async function exists(filePath: string): Promise<boolean> {
|
|
18
|
-
try {
|
|
19
|
-
await access(filePath);
|
|
20
|
-
return true;
|
|
21
|
-
} catch {
|
|
22
|
-
return false;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function homePiExtensionsRoot(): string {
|
|
27
|
-
return path.join(os.homedir(), ".pi", "agent", "extensions");
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export async function detectDuplicateTakomiExtensions(cwd: string): Promise<Array<{ toolName: string; paths: string[] }>> {
|
|
31
|
-
const globalRoot = homePiExtensionsRoot();
|
|
32
|
-
const projectRoot = path.resolve(cwd, ".pi", "extensions");
|
|
33
|
-
const warnings: Array<{ toolName: string; paths: string[] }> = [];
|
|
34
|
-
|
|
35
|
-
for (const known of KNOWN_TAKOMI_EXTENSIONS) {
|
|
36
|
-
const globalPath = path.join(globalRoot, known.relativePath);
|
|
37
|
-
const projectPath = path.join(projectRoot, known.relativePath);
|
|
38
|
-
if (await exists(globalPath) && await exists(projectPath)) {
|
|
39
|
-
warnings.push({ toolName: known.toolName, paths: [globalPath, projectPath] });
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return warnings;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export function renderDuplicateExtensionGuidance(warnings: Array<{ toolName: string; paths: string[] }>): string[] {
|
|
47
|
-
if (warnings.length === 0) return ["- Duplicate Takomi extensions: none detected"];
|
|
48
|
-
const lines = ["- Duplicate Takomi extensions detected:"];
|
|
49
|
-
for (const warning of warnings) {
|
|
50
|
-
lines.push(` - ${warning.toolName}`);
|
|
51
|
-
for (const filePath of warning.paths) lines.push(` - ${filePath}`);
|
|
52
|
-
}
|
|
53
|
-
lines.push("- Recommended dev command: use scripts/pi-dev.ps1, which starts Pi with --no-extensions and explicit project-local Takomi extensions.");
|
|
54
|
-
lines.push("- For global Pi sessions, disable/remove one duplicate source or prefer explicit extension loading to avoid tool registration conflicts.");
|
|
55
|
-
return lines;
|
|
56
|
-
}
|
|
1
|
+
import { access } from "node:fs/promises";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import type { ContextManagerState } from "./state";
|
|
5
|
+
|
|
6
|
+
type KnownTakomiExtension = {
|
|
7
|
+
toolName: string;
|
|
8
|
+
relativePath: string;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const KNOWN_TAKOMI_EXTENSIONS: KnownTakomiExtension[] = [
|
|
12
|
+
{ toolName: "takomi_workflow", relativePath: path.join("takomi-runtime", "index.ts") },
|
|
13
|
+
{ toolName: "takomi_board", relativePath: path.join("takomi-runtime", "index.ts") },
|
|
14
|
+
{ toolName: "takomi_subagent", relativePath: path.join("takomi-subagents", "index.ts") },
|
|
15
|
+
];
|
|
16
|
+
|
|
17
|
+
async function exists(filePath: string): Promise<boolean> {
|
|
18
|
+
try {
|
|
19
|
+
await access(filePath);
|
|
20
|
+
return true;
|
|
21
|
+
} catch {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function homePiExtensionsRoot(): string {
|
|
27
|
+
return path.join(os.homedir(), ".pi", "agent", "extensions");
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export async function detectDuplicateTakomiExtensions(cwd: string): Promise<Array<{ toolName: string; paths: string[] }>> {
|
|
31
|
+
const globalRoot = homePiExtensionsRoot();
|
|
32
|
+
const projectRoot = path.resolve(cwd, ".pi", "extensions");
|
|
33
|
+
const warnings: Array<{ toolName: string; paths: string[] }> = [];
|
|
34
|
+
|
|
35
|
+
for (const known of KNOWN_TAKOMI_EXTENSIONS) {
|
|
36
|
+
const globalPath = path.join(globalRoot, known.relativePath);
|
|
37
|
+
const projectPath = path.join(projectRoot, known.relativePath);
|
|
38
|
+
if (await exists(globalPath) && await exists(projectPath)) {
|
|
39
|
+
warnings.push({ toolName: known.toolName, paths: [globalPath, projectPath] });
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return warnings;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function renderDuplicateExtensionGuidance(warnings: Array<{ toolName: string; paths: string[] }>): string[] {
|
|
47
|
+
if (warnings.length === 0) return ["- Duplicate Takomi extensions: none detected"];
|
|
48
|
+
const lines = ["- Duplicate Takomi extensions detected:"];
|
|
49
|
+
for (const warning of warnings) {
|
|
50
|
+
lines.push(` - ${warning.toolName}`);
|
|
51
|
+
for (const filePath of warning.paths) lines.push(` - ${filePath}`);
|
|
52
|
+
}
|
|
53
|
+
lines.push("- Recommended dev command: use scripts/pi-dev.ps1, which starts Pi with --no-extensions and explicit project-local Takomi extensions.");
|
|
54
|
+
lines.push("- For global Pi sessions, disable/remove one duplicate source or prefer explicit extension loading to avoid tool registration conflicts.");
|
|
55
|
+
return lines;
|
|
56
|
+
}
|
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
|
|
2
|
-
import { loadConfig, DEFAULT_CONFIG } from "./config";
|
|
3
|
-
import { createState } from "./state";
|
|
4
|
-
import { collectSkillsFromOptions, collectSkillsFromXml, mergeSkills } from "./skill-registry";
|
|
5
|
-
import { discoverPolicies } from "./policy-registry";
|
|
6
|
-
import { findCandidates } from "./context-router";
|
|
7
|
-
import { rewritePrompt } from "./prompt-rewriter";
|
|
8
|
-
import { registerSkillTools } from "./skill-tools";
|
|
9
|
-
import { registerPolicyTools } from "./policy-tools";
|
|
10
|
-
import { registerDiagnostics } from "./diagnostics-tools";
|
|
11
|
-
import { installPrerequisiteGates } from "./prerequisite-gates";
|
|
12
|
-
import { installModelPolicyGate } from "./model-policy-gate";
|
|
13
|
-
import { detectDuplicateTakomiExtensions } from "./extension-conflicts";
|
|
14
|
-
import type { ContextManagerConfig } from "./types";
|
|
15
|
-
|
|
16
|
-
export default function takomiContextManager(pi: ExtensionAPI) {
|
|
17
|
-
const state = createState();
|
|
18
|
-
let config: ContextManagerConfig = DEFAULT_CONFIG;
|
|
19
|
-
|
|
20
|
-
registerSkillTools(pi, state);
|
|
21
|
-
registerPolicyTools(pi, state);
|
|
22
|
-
registerDiagnostics(pi, state);
|
|
23
|
-
installPrerequisiteGates(pi, state, () => config);
|
|
24
|
-
installModelPolicyGate(pi, state);
|
|
25
|
-
|
|
26
|
-
pi.on("before_agent_start", async (event, ctx) => {
|
|
27
|
-
config = await loadConfig(ctx.cwd);
|
|
28
|
-
state.policies = await discoverPolicies(ctx.cwd, config);
|
|
29
|
-
const duplicateExtensionWarnings = await detectDuplicateTakomiExtensions(ctx.cwd);
|
|
30
|
-
const optionSkills = collectSkillsFromOptions(event.systemPromptOptions);
|
|
31
|
-
const xmlSkills = collectSkillsFromXml(event.systemPrompt);
|
|
32
|
-
state.skills = mergeSkills([...optionSkills, ...xmlSkills]);
|
|
33
|
-
|
|
34
|
-
const candidates = findCandidates(event.prompt, state.skills, config);
|
|
35
|
-
const rewrite = rewritePrompt(event.systemPrompt, state.skills, candidates, config);
|
|
36
|
-
state.report = {
|
|
37
|
-
...state.report,
|
|
38
|
-
timestamp: new Date().toISOString(),
|
|
39
|
-
cwd: ctx.cwd,
|
|
40
|
-
userPrompt: event.prompt,
|
|
41
|
-
skillCount: state.skills.size,
|
|
42
|
-
candidates,
|
|
43
|
-
duplicateExtensionWarnings,
|
|
44
|
-
promptRewrite: {
|
|
45
|
-
attempted: true,
|
|
46
|
-
changed: rewrite.changed,
|
|
47
|
-
originalLength: event.systemPrompt.length,
|
|
48
|
-
rewrittenLength: rewrite.prompt.length,
|
|
49
|
-
removedSections: rewrite.removedSections,
|
|
50
|
-
warnings: rewrite.warnings,
|
|
51
|
-
},
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
return { systemPrompt: rewrite.prompt };
|
|
55
|
-
});
|
|
56
|
-
}
|
|
1
|
+
import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
|
|
2
|
+
import { loadConfig, DEFAULT_CONFIG } from "./config";
|
|
3
|
+
import { createState } from "./state";
|
|
4
|
+
import { collectSkillsFromOptions, collectSkillsFromXml, mergeSkills } from "./skill-registry";
|
|
5
|
+
import { discoverPolicies } from "./policy-registry";
|
|
6
|
+
import { findCandidates } from "./context-router";
|
|
7
|
+
import { rewritePrompt } from "./prompt-rewriter";
|
|
8
|
+
import { registerSkillTools } from "./skill-tools";
|
|
9
|
+
import { registerPolicyTools } from "./policy-tools";
|
|
10
|
+
import { registerDiagnostics } from "./diagnostics-tools";
|
|
11
|
+
import { installPrerequisiteGates } from "./prerequisite-gates";
|
|
12
|
+
import { installModelPolicyGate } from "./model-policy-gate";
|
|
13
|
+
import { detectDuplicateTakomiExtensions } from "./extension-conflicts";
|
|
14
|
+
import type { ContextManagerConfig } from "./types";
|
|
15
|
+
|
|
16
|
+
export default function takomiContextManager(pi: ExtensionAPI) {
|
|
17
|
+
const state = createState();
|
|
18
|
+
let config: ContextManagerConfig = DEFAULT_CONFIG;
|
|
19
|
+
|
|
20
|
+
registerSkillTools(pi, state);
|
|
21
|
+
registerPolicyTools(pi, state);
|
|
22
|
+
registerDiagnostics(pi, state);
|
|
23
|
+
installPrerequisiteGates(pi, state, () => config);
|
|
24
|
+
installModelPolicyGate(pi, state);
|
|
25
|
+
|
|
26
|
+
pi.on("before_agent_start", async (event, ctx) => {
|
|
27
|
+
config = await loadConfig(ctx.cwd);
|
|
28
|
+
state.policies = await discoverPolicies(ctx.cwd, config);
|
|
29
|
+
const duplicateExtensionWarnings = await detectDuplicateTakomiExtensions(ctx.cwd);
|
|
30
|
+
const optionSkills = collectSkillsFromOptions(event.systemPromptOptions);
|
|
31
|
+
const xmlSkills = collectSkillsFromXml(event.systemPrompt);
|
|
32
|
+
state.skills = mergeSkills([...optionSkills, ...xmlSkills]);
|
|
33
|
+
|
|
34
|
+
const candidates = findCandidates(event.prompt, state.skills, config);
|
|
35
|
+
const rewrite = rewritePrompt(event.systemPrompt, state.skills, candidates, config);
|
|
36
|
+
state.report = {
|
|
37
|
+
...state.report,
|
|
38
|
+
timestamp: new Date().toISOString(),
|
|
39
|
+
cwd: ctx.cwd,
|
|
40
|
+
userPrompt: event.prompt,
|
|
41
|
+
skillCount: state.skills.size,
|
|
42
|
+
candidates,
|
|
43
|
+
duplicateExtensionWarnings,
|
|
44
|
+
promptRewrite: {
|
|
45
|
+
attempted: true,
|
|
46
|
+
changed: rewrite.changed,
|
|
47
|
+
originalLength: event.systemPrompt.length,
|
|
48
|
+
rewrittenLength: rewrite.prompt.length,
|
|
49
|
+
removedSections: rewrite.removedSections,
|
|
50
|
+
warnings: rewrite.warnings,
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
return { systemPrompt: rewrite.prompt };
|
|
55
|
+
});
|
|
56
|
+
}
|