@mrclrchtr/supi-context 1.14.3 → 1.16.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/README.md +22 -4
- package/node_modules/@mrclrchtr/supi-core/package.json +1 -1
- package/node_modules/@mrclrchtr/supi-core/src/context/context-provider-registry.ts +1 -1
- package/package.json +3 -2
- package/src/analysis.ts +3 -5
- package/src/config.ts +22 -0
- package/src/context.ts +28 -0
- package/src/prompt-inference.ts +2 -2
- package/src/settings-registration.ts +25 -0
- package/src/tool/guidance.ts +13 -0
package/README.md
CHANGED
|
@@ -26,13 +26,16 @@ pi install ./packages/supi-context
|
|
|
26
26
|
|
|
27
27
|
## What you get
|
|
28
28
|
|
|
29
|
-
After install, pi gets one user command:
|
|
29
|
+
After install, pi gets one user command and an optional agent-callable tool:
|
|
30
30
|
|
|
31
31
|
- `/supi-context` — render a detailed context-usage report for the current session
|
|
32
32
|
- `/supi-context full` — render the same report with the full guideline and tool-definition lists instead of previews
|
|
33
|
+
- `supi_context` — agent-callable tool (disabled by default; see Configuration)
|
|
33
34
|
|
|
34
35
|
The command sends a custom `supi-context` message, and this package registers a dedicated renderer so the report shows up as a structured TUI view instead of plain text.
|
|
35
36
|
|
|
37
|
+
The `supi_context` tool returns the same analysis as JSON, so the agent can inspect context usage programmatically — useful for checking remaining capacity before large operations or after heavy tool results.
|
|
38
|
+
|
|
36
39
|
## What the report shows
|
|
37
40
|
|
|
38
41
|
The report is meant to answer questions like:
|
|
@@ -66,9 +69,21 @@ It includes:
|
|
|
66
69
|
|
|
67
70
|
## Configuration
|
|
68
71
|
|
|
69
|
-
No settings are required.
|
|
72
|
+
No settings are required for the `/supi-context` command.
|
|
73
|
+
|
|
74
|
+
To enable the `supi_context` agent tool, set `agentToolEnabled` to `true` in your supi config:
|
|
75
|
+
|
|
76
|
+
```json
|
|
77
|
+
{
|
|
78
|
+
"supi-context": {
|
|
79
|
+
"agentToolEnabled": true
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Or toggle it via `/supi-settings` → **Context** → **Agent Tool**, then `/reload`.
|
|
70
85
|
|
|
71
|
-
|
|
86
|
+
The tool is disabled by default and requires a `/reload` or restart after toggling.
|
|
72
87
|
|
|
73
88
|
## Notes
|
|
74
89
|
|
|
@@ -79,7 +94,9 @@ This package does not add a model-callable tool; it adds a user command only.
|
|
|
79
94
|
|
|
80
95
|
## Source
|
|
81
96
|
|
|
82
|
-
- `src/context.ts` — command registration, cached prompt-option handling, and renderer wiring
|
|
97
|
+
- `src/context.ts` — command registration, agent tool registration, cached prompt-option handling, and renderer wiring
|
|
98
|
+
- `src/config.ts` — config loading with `agentToolEnabled` toggle
|
|
99
|
+
- `src/settings-registration.ts` — `/supi-settings` registration for the agent tool toggle
|
|
83
100
|
- `src/analysis.ts` — token accounting, attribution, and report data assembly
|
|
84
101
|
- `src/format.ts` — report orchestration for the TUI view
|
|
85
102
|
- `src/format-helpers.ts` — shared numeric and category helpers for report rendering
|
|
@@ -87,6 +104,7 @@ This package does not add a model-callable tool; it adds a user command only.
|
|
|
87
104
|
- `src/format-sections.ts` — instruction file, context file, skill, guideline, tool, compaction, and provider sections
|
|
88
105
|
- `src/prompt-inference.ts` — fallback recovery of context files, skills, and guideline sections from the live system prompt
|
|
89
106
|
- `src/renderer.ts` — custom renderer for `supi-context` messages
|
|
107
|
+
- `src/tool/guidance.ts` — tool description, prompt snippet, and guidelines for the agent tool
|
|
90
108
|
- `src/utils.ts` — token and plural-format helpers
|
|
91
109
|
|
|
92
110
|
Tests live under `__tests__/unit/`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mrclrchtr/supi-context",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.16.0",
|
|
4
4
|
"description": "SuPi Context extension — detailed context usage report via /supi-context command",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -30,7 +30,8 @@
|
|
|
30
30
|
"README.md"
|
|
31
31
|
],
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"
|
|
33
|
+
"typebox": "*",
|
|
34
|
+
"@mrclrchtr/supi-core": "1.16.0"
|
|
34
35
|
},
|
|
35
36
|
"bundledDependencies": [
|
|
36
37
|
"@mrclrchtr/supi-core"
|
package/src/analysis.ts
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
type BuildSystemPromptOptions,
|
|
5
5
|
buildSessionContext,
|
|
6
6
|
type ExtensionAPI,
|
|
7
|
-
type
|
|
7
|
+
type ExtensionContext,
|
|
8
8
|
type estimateTokens,
|
|
9
9
|
formatSkillsForPrompt,
|
|
10
10
|
getLatestCompactionEntry,
|
|
@@ -508,9 +508,7 @@ function computeToolDefinitions(pi: ExtensionAPI): {
|
|
|
508
508
|
};
|
|
509
509
|
}
|
|
510
510
|
|
|
511
|
-
function detectCompaction(
|
|
512
|
-
branch: ReturnType<ExtensionCommandContext["sessionManager"]["getBranch"]>,
|
|
513
|
-
): {
|
|
511
|
+
function detectCompaction(branch: ReturnType<ExtensionContext["sessionManager"]["getBranch"]>): {
|
|
514
512
|
summarizedTurns: number;
|
|
515
513
|
} | null {
|
|
516
514
|
const compactionEntry = getLatestCompactionEntry(branch);
|
|
@@ -559,7 +557,7 @@ export function extractInjectedContextFiles(messages: AgentMessage[]): InjectedF
|
|
|
559
557
|
}
|
|
560
558
|
|
|
561
559
|
export function analyzeContext(
|
|
562
|
-
ctx:
|
|
560
|
+
ctx: ExtensionContext,
|
|
563
561
|
pi: ExtensionAPI,
|
|
564
562
|
cachedOptions: BuildSystemPromptOptions | undefined,
|
|
565
563
|
full = false,
|
package/src/config.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// Configuration for supi-context.
|
|
2
|
+
//
|
|
3
|
+
// Config shape (in supi shared config, "context" section):
|
|
4
|
+
// {
|
|
5
|
+
// "agentToolEnabled": false // enable the supi_context agent-callable tool
|
|
6
|
+
// }
|
|
7
|
+
|
|
8
|
+
import { loadSupiConfig } from "@mrclrchtr/supi-core/config";
|
|
9
|
+
|
|
10
|
+
export interface ContextConfig {
|
|
11
|
+
/** Enable the supi_context agent-callable tool. Default: false */
|
|
12
|
+
agentToolEnabled: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const CONTEXT_DEFAULTS: ContextConfig = {
|
|
16
|
+
agentToolEnabled: false,
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/** Load merged supi-context config for the given working directory. */
|
|
20
|
+
export function loadContextConfig(cwd: string, homeDir?: string): ContextConfig {
|
|
21
|
+
return loadSupiConfig("context", cwd, CONTEXT_DEFAULTS, { homeDir });
|
|
22
|
+
}
|
package/src/context.ts
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
import type { BuildSystemPromptOptions, ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { Type } from "typebox";
|
|
2
3
|
import { analyzeContext } from "./analysis.ts";
|
|
4
|
+
import { loadContextConfig } from "./config.ts";
|
|
3
5
|
import { registerContextRenderer } from "./renderer.ts";
|
|
6
|
+
import { registerContextSettings } from "./settings-registration.ts";
|
|
7
|
+
import { promptGuidelines, promptSnippet, toolDescription } from "./tool/guidance.ts";
|
|
4
8
|
import { formatTokens } from "./utils.ts";
|
|
5
9
|
|
|
6
10
|
export default function contextExtension(pi: ExtensionAPI) {
|
|
7
11
|
let cachedOptions: BuildSystemPromptOptions | undefined;
|
|
8
12
|
|
|
13
|
+
// Register settings synchronously during factory
|
|
14
|
+
registerContextSettings();
|
|
15
|
+
|
|
9
16
|
pi.on("before_agent_start", async (event) => {
|
|
10
17
|
cachedOptions = event.systemPromptOptions;
|
|
11
18
|
});
|
|
@@ -31,4 +38,25 @@ export default function contextExtension(pi: ExtensionAPI) {
|
|
|
31
38
|
});
|
|
32
39
|
|
|
33
40
|
registerContextRenderer(pi);
|
|
41
|
+
|
|
42
|
+
// ── supi_context agent tool (gated on config) ────────────
|
|
43
|
+
|
|
44
|
+
if (loadContextConfig(process.cwd()).agentToolEnabled) {
|
|
45
|
+
pi.registerTool({
|
|
46
|
+
name: "supi_context",
|
|
47
|
+
label: "Context Usage",
|
|
48
|
+
description: toolDescription,
|
|
49
|
+
promptSnippet,
|
|
50
|
+
parameters: Type.Object({}),
|
|
51
|
+
promptGuidelines,
|
|
52
|
+
// biome-ignore lint/complexity/useMaxParams: pi tool execute signature
|
|
53
|
+
async execute(_toolCallId, _params, _signal, _onUpdate, ctx) {
|
|
54
|
+
const analysis = analyzeContext(ctx, pi, cachedOptions, true);
|
|
55
|
+
return {
|
|
56
|
+
content: [{ type: "text", text: JSON.stringify(analysis, null, 2) }],
|
|
57
|
+
details: undefined,
|
|
58
|
+
};
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
}
|
|
34
62
|
}
|
package/src/prompt-inference.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
BuildSystemPromptOptions,
|
|
3
|
-
|
|
3
|
+
ExtensionContext,
|
|
4
4
|
Skill,
|
|
5
5
|
} from "@earendil-works/pi-coding-agent";
|
|
6
6
|
|
|
@@ -123,7 +123,7 @@ export function extractGuidelinesSection(systemPrompt: string): string | null {
|
|
|
123
123
|
}
|
|
124
124
|
|
|
125
125
|
export function deriveOptionsFromSystemPrompt(
|
|
126
|
-
ctx:
|
|
126
|
+
ctx: ExtensionContext,
|
|
127
127
|
cachedOptions: BuildSystemPromptOptions | undefined,
|
|
128
128
|
): BuildSystemPromptOptions | undefined {
|
|
129
129
|
const systemPrompt = ctx.getSystemPrompt();
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// supi-context settings registration for the supi settings registry.
|
|
2
|
+
|
|
3
|
+
import { registerConfigSettings } from "@mrclrchtr/supi-core/config";
|
|
4
|
+
import { CONTEXT_DEFAULTS } from "./config.ts";
|
|
5
|
+
|
|
6
|
+
/** Register supi-context settings with the supi settings registry. */
|
|
7
|
+
export function registerContextSettings(homeDir?: string): void {
|
|
8
|
+
registerConfigSettings({
|
|
9
|
+
id: "context",
|
|
10
|
+
label: "Context",
|
|
11
|
+
section: "context",
|
|
12
|
+
defaults: CONTEXT_DEFAULTS,
|
|
13
|
+
buildItems: (settings) => [
|
|
14
|
+
{
|
|
15
|
+
id: "agentToolEnabled",
|
|
16
|
+
label: "Agent Tool",
|
|
17
|
+
description: "Enable supi_context agent tool for context usage queries",
|
|
18
|
+
currentValue: settings.agentToolEnabled ? "on" : "off",
|
|
19
|
+
values: ["on", "off"],
|
|
20
|
+
configType: "boolean" as const,
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
...(homeDir ? { homeDir } : {}),
|
|
24
|
+
});
|
|
25
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Prompt guidance and tool description for the supi_context agent tool.
|
|
2
|
+
|
|
3
|
+
export const toolDescription =
|
|
4
|
+
"Get detailed context usage information for the current session — token breakdown, context window, compaction state, injected files, guideline sources, and more.";
|
|
5
|
+
|
|
6
|
+
export const promptSnippet =
|
|
7
|
+
"supi_context — context usage report (token breakdown, context window)";
|
|
8
|
+
|
|
9
|
+
export const promptGuidelines = [
|
|
10
|
+
"Use supi_context to check context window usage when approaching limits or after large tool results.",
|
|
11
|
+
"Use supi_context before large operations to gauge remaining context window capacity.",
|
|
12
|
+
"Prefer supi_context over asking the user to run /supi-context — it gives you the same data directly.",
|
|
13
|
+
];
|