@spences10/pi-context 0.0.10 → 0.0.12

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.
@@ -0,0 +1,11 @@
1
+ import { type ContextListResult, type ContextPurgeDetails, type ContextSearchResult, type ContextStats } from './store.js';
2
+ export declare function format_search_results(results: ContextSearchResult[]): string;
3
+ export declare function format_list_results(results: ContextListResult[]): string;
4
+ export declare function format_purge_details(details: ContextPurgeDetails): string;
5
+ export declare function format_stats(stats: ContextStats): string;
6
+ export declare function format_timestamp(timestamp: number | null): string;
7
+ export declare function format_days(days: number | null): string;
8
+ export declare function format_max_mb(max_mb: number | null): string;
9
+ export declare function format_kib(bytes: number): string;
10
+ export declare function format_output_limit(bytes: number, lines: number): string;
11
+ export declare function format_context_settings_status(stats: ContextStats): string;
@@ -0,0 +1,122 @@
1
+ import { CONTEXT_SETTINGS_PRESETS, get_context_capture_limits, get_context_mcp_output_limits, get_context_settings_config_path, load_context_settings_config, } from './config.js';
2
+ import { is_context_sidecar_enabled, } from './store.js';
3
+ export function format_search_results(results) {
4
+ if (results.length === 0)
5
+ return 'No indexed context matched.';
6
+ return results
7
+ .map((result, index) => [
8
+ `## ${index + 1}. ${result.title ?? result.chunk_id}`,
9
+ `Source: ${result.source_id} • Chunk: ${result.chunk_id} • Tool: ${result.tool_name}`,
10
+ '',
11
+ result.content,
12
+ ].join('\n'))
13
+ .join('\n\n---\n\n');
14
+ }
15
+ export function format_list_results(results) {
16
+ if (results.length === 0)
17
+ return 'No indexed context sources found.';
18
+ return results
19
+ .map((result) => [
20
+ `## ${result.source_id}`,
21
+ `Created: ${new Date(result.created_at).toISOString()} • Tool: ${result.tool_name}`,
22
+ `Size: ${result.bytes} bytes, ${result.lines} lines, ${result.chunk_count} chunks`,
23
+ `Project: ${result.project_path ?? '(none)'}`,
24
+ `Session: ${result.session_id ?? '(none)'}`,
25
+ result.input_summary
26
+ ? `Input: ${result.input_summary}`
27
+ : undefined,
28
+ result.first_chunk_title
29
+ ? `First chunk: ${result.first_chunk_title}`
30
+ : undefined,
31
+ result.preview ? `Preview: ${result.preview}` : undefined,
32
+ ]
33
+ .filter(Boolean)
34
+ .join('\n'))
35
+ .join('\n\n');
36
+ }
37
+ export function format_purge_details(details) {
38
+ const filters = [
39
+ details.source_id ? `source_id=${details.source_id}` : undefined,
40
+ details.project_path !== undefined
41
+ ? `project_path=${details.project_path ?? '(none)'}`
42
+ : undefined,
43
+ details.session_id !== undefined
44
+ ? `session_id=${details.session_id ?? '(none)'}`
45
+ : undefined,
46
+ details.older_than_days !== undefined
47
+ ? `older_than_days=${details.older_than_days}`
48
+ : undefined,
49
+ ]
50
+ .filter(Boolean)
51
+ .join(', ');
52
+ return `Deleted ${details.deleted} context source(s).${filters ? ` Filters: ${filters}.` : ''}`;
53
+ }
54
+ export function format_stats(stats) {
55
+ const scoped = stats.scope_project_path || stats.scope_session_id;
56
+ return [
57
+ '## context-sidecar stats',
58
+ '',
59
+ `- Enabled: ${is_context_sidecar_enabled()}`,
60
+ scoped
61
+ ? `- Scope: project=${stats.scope_project_path ?? '(none)'}, session=${stats.scope_session_id ?? '(none)'}`
62
+ : '- Scope: global',
63
+ `- Scoped sources: ${stats.sources}`,
64
+ `- Scoped chunks: ${stats.chunks}`,
65
+ `- Scoped raw bytes stored: ${stats.bytes_stored}`,
66
+ `- Global sources: ${stats.global_sources}`,
67
+ `- Global chunks: ${stats.global_chunks}`,
68
+ `- Global raw bytes stored: ${stats.global_bytes_stored}`,
69
+ `- Bytes returned: ${stats.bytes_returned}`,
70
+ `- Bytes saved: ${stats.bytes_saved}`,
71
+ `- Reduction: ${stats.reduction_pct}%`,
72
+ `- DB bytes: ${stats.total_bytes}`,
73
+ `- Scoped oldest source: ${format_timestamp(stats.oldest_created_at)}`,
74
+ `- Scoped newest source: ${format_timestamp(stats.newest_created_at)}`,
75
+ `- Global oldest source: ${format_timestamp(stats.global_oldest_created_at)}`,
76
+ `- Global newest source: ${format_timestamp(stats.global_newest_created_at)}`,
77
+ `- Retention days: ${stats.retention_days ?? 'disabled'}`,
78
+ `- Purge on shutdown: ${stats.purge_on_shutdown}`,
79
+ `- Max DB size: ${stats.max_mb === null ? 'disabled' : `${stats.max_mb} MiB`}`,
80
+ ].join('\n');
81
+ }
82
+ export function format_timestamp(timestamp) {
83
+ return timestamp === null
84
+ ? '(none)'
85
+ : new Date(timestamp).toISOString();
86
+ }
87
+ export function format_days(days) {
88
+ return days === null ? 'disabled' : `${days} day(s)`;
89
+ }
90
+ export function format_max_mb(max_mb) {
91
+ return max_mb === null ? 'disabled' : `${max_mb} MiB`;
92
+ }
93
+ export function format_kib(bytes) {
94
+ return `${Math.round(bytes / 1024)} KiB`;
95
+ }
96
+ export function format_output_limit(bytes, lines) {
97
+ return `${format_kib(bytes)} / ${lines} lines`;
98
+ }
99
+ export function format_context_settings_status(stats) {
100
+ const saved = load_context_settings_config();
101
+ const capture_limits = get_context_capture_limits();
102
+ const mcp_limits = get_context_mcp_output_limits();
103
+ return [
104
+ '## context-sidecar settings',
105
+ '',
106
+ `- Config path: ${get_context_settings_config_path()}`,
107
+ `- Saved preset: ${saved?.preset ?? '(none; using built-in defaults)'}`,
108
+ `- Effective retention: ${format_days(stats.retention_days)}`,
109
+ `- Effective max size: ${format_max_mb(stats.max_mb)}`,
110
+ `- Effective purge on shutdown: ${stats.purge_on_shutdown}`,
111
+ `- Effective tool capture threshold: ${format_output_limit(capture_limits.max_bytes, capture_limits.max_lines)}`,
112
+ `- Effective MCP capture threshold: ${format_output_limit(mcp_limits.max_bytes, mcp_limits.max_lines)}`,
113
+ '',
114
+ 'Presets:',
115
+ ...Object.entries(CONTEXT_SETTINGS_PRESETS).map(([key, preset]) => `- ${key}: ${preset.description}`),
116
+ '',
117
+ 'Usage:',
118
+ '- /context settings <preset>',
119
+ '- /context settings custom <days|off> <max-mb|off> [capture-kb] [capture-lines] [purge-on-shutdown]',
120
+ ].join('\n');
121
+ }
122
+ //# sourceMappingURL=context-format.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CAAC,EAAE;QACvG,EAAE;QACF,UAAU;QACV,GAAG,MAAM,CAAC,OAAO,CAAC,wBAAwB,CAAC,CAAC,GAAG,CAC9C,CAAC,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC,KAAK,GAAG,KAAK,MAAM,CAAC,WAAW,EAAE,CACpD;QACD,EAAE;QACF,QAAQ;QACR,8BAA8B;QAC9B,qGAAqG;KACrG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACd,CAAC"}
@@ -0,0 +1,10 @@
1
+ import type { ExtensionCommandContext } from '@earendil-works/pi-coding-agent';
2
+ import type { ContextScopeOptions } from './store.js';
3
+ export declare function is_text_content(item: unknown): item is {
4
+ type: 'text';
5
+ text: string;
6
+ };
7
+ export declare function summarize_tool_input(input: unknown): string | null;
8
+ export declare function should_skip_tool(tool_name: string): boolean;
9
+ export declare function session_id_from_context(ctx?: Pick<ExtensionCommandContext, 'sessionManager'>): string | null;
10
+ export declare function scope_from_context(ctx?: Pick<ExtensionCommandContext, 'cwd' | 'sessionManager'>): ContextScopeOptions;
@@ -0,0 +1,44 @@
1
+ export function is_text_content(item) {
2
+ return (!!item &&
3
+ typeof item === 'object' &&
4
+ item.type === 'text' &&
5
+ typeof item.text === 'string');
6
+ }
7
+ export function summarize_tool_input(input) {
8
+ if (!input || typeof input !== 'object')
9
+ return null;
10
+ try {
11
+ const json = JSON.stringify(input);
12
+ return json.length > 500 ? `${json.slice(0, 497)}...` : json;
13
+ }
14
+ catch {
15
+ return null;
16
+ }
17
+ }
18
+ export function should_skip_tool(tool_name) {
19
+ // Coverage policy:
20
+ // - context_* tools are retrieval/maintenance output; indexing them would
21
+ // recurse and make the sidecar harder to reason about.
22
+ // - team output is coordination state, not bulky artifact content; keep it in
23
+ // team/pirecall surfaces rather than duplicating mailbox/task state here.
24
+ // - MCP receipts are produced before generic tool_result hooks; the hook also
25
+ // ignores existing [context-sidecar] receipts so direct MCP storage is not
26
+ // indexed a second time.
27
+ return (tool_name === 'context_search' ||
28
+ tool_name === 'context_get' ||
29
+ tool_name === 'context_list' ||
30
+ tool_name === 'context_stats' ||
31
+ tool_name === 'context_purge' ||
32
+ tool_name === 'team');
33
+ }
34
+ export function session_id_from_context(ctx) {
35
+ const manager = ctx?.sessionManager;
36
+ return (manager?.getSessionFile?.() ?? manager?.getSessionId?.() ?? null);
37
+ }
38
+ export function scope_from_context(ctx) {
39
+ return {
40
+ project_path: ctx?.cwd ?? process.cwd(),
41
+ session_id: session_id_from_context(ctx),
42
+ };
43
+ }
44
+ //# sourceMappingURL=context-scope.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context-scope.js","sourceRoot":"","sources":["../src/context-scope.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,eAAe,CAC9B,IAAa;IAEb,OAAO,CACN,CAAC,CAAC,IAAI;QACN,OAAO,IAAI,KAAK,QAAQ;QACvB,IAA2B,CAAC,IAAI,KAAK,MAAM;QAC5C,OAAQ,IAA2B,CAAC,IAAI,KAAK,QAAQ,CACrD,CAAC;AACH,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,KAAc;IAClD,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC;IACrD,IAAI,CAAC;QACJ,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QACnC,OAAO,IAAI,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;IAC9D,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,IAAI,CAAC;IACb,CAAC;AACF,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,SAAiB;IACjD,mBAAmB;IACnB,0EAA0E;IAC1E,yDAAyD;IACzD,8EAA8E;IAC9E,4EAA4E;IAC5E,8EAA8E;IAC9E,6EAA6E;IAC7E,2BAA2B;IAC3B,OAAO,CACN,SAAS,KAAK,gBAAgB;QAC9B,SAAS,KAAK,aAAa;QAC3B,SAAS,KAAK,cAAc;QAC5B,SAAS,KAAK,eAAe;QAC7B,SAAS,KAAK,eAAe;QAC7B,SAAS,KAAK,MAAM,CACpB,CAAC;AACH,CAAC;AAED,MAAM,UAAU,uBAAuB,CACtC,GAAqD;IAErD,MAAM,OAAO,GAAG,GAAG,EAAE,cAAc,CAAC;IACpC,OAAO,CACN,OAAO,EAAE,cAAc,EAAE,EAAE,IAAI,OAAO,EAAE,YAAY,EAAE,EAAE,IAAI,IAAI,CAChE,CAAC;AACH,CAAC;AAED,MAAM,UAAU,kBAAkB,CACjC,GAA6D;IAE7D,OAAO;QACN,YAAY,EAAE,GAAG,EAAE,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE;QACvC,UAAU,EAAE,uBAAuB,CAAC,GAAG,CAAC;KACxC,CAAC;AACH,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { ExtensionAPI } from '@earendil-works/pi-coding-agent';
2
2
  export default function context_sidecar(pi: ExtensionAPI): void;
3
- export { CONTEXT_SETTINGS_PRESETS, context_settings_from_preset, get_context_capture_limits, get_context_mcp_output_limits, get_context_settings_config_path, load_context_settings_config, save_context_settings_config, } from './config.js';
3
+ export { context_settings_from_preset, CONTEXT_SETTINGS_PRESETS, get_context_capture_limits, get_context_mcp_output_limits, get_context_settings_config_path, load_context_settings_config, save_context_settings_config, } from './config.js';
4
4
  export type { ContextOutputLimits, ContextSettingsConfig, ContextSettingsPreset, ContextSettingsValues, } from './config.js';
5
5
  export { get_context_store, is_context_sidecar_enabled, maybe_store_context_output, parse_context_retention_policy, set_context_sidecar_enabled, should_index_text, } from './store.js';
6
6
  export type { ContextCleanupResult, ContextListResult, ContextPurgeDetails, ContextRetentionPolicy, ContextScopeOptions, ContextSearchResult, ContextStats, StoreContextInput, StoredContextOutput, } from './store.js';