@aexol/spectral 0.9.58 → 0.9.59
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/CHANGELOG.md +6 -0
- package/README.md +43 -0
- package/dist/agent/index.d.ts +6 -1
- package/dist/agent/index.d.ts.map +1 -1
- package/dist/agent/index.js +133 -14
- package/dist/extensions/web/index.d.ts +10 -0
- package/dist/extensions/web/index.d.ts.map +1 -0
- package/dist/extensions/web/index.js +11 -0
- package/dist/extensions/web/tools/fetch.d.ts +3 -0
- package/dist/extensions/web/tools/fetch.d.ts.map +1 -0
- package/dist/extensions/web/tools/fetch.js +80 -0
- package/dist/extensions/web/utils/fetcher.d.ts +34 -0
- package/dist/extensions/web/utils/fetcher.d.ts.map +1 -0
- package/dist/extensions/web/utils/fetcher.js +289 -0
- package/dist/extensions/web/utils/parser.d.ts +15 -0
- package/dist/extensions/web/utils/parser.d.ts.map +1 -0
- package/dist/extensions/web/utils/parser.js +205 -0
- package/dist/memory/branch.d.ts.map +1 -1
- package/dist/memory/branch.js +16 -8
- package/dist/memory/commands/status.d.ts.map +1 -1
- package/dist/memory/commands/status.js +3 -2
- package/dist/memory/config.d.ts +12 -0
- package/dist/memory/config.d.ts.map +1 -1
- package/dist/memory/config.js +21 -2
- package/dist/memory/hooks/compaction-trigger.d.ts.map +1 -1
- package/dist/memory/hooks/compaction-trigger.js +19 -3
- package/dist/memory/index.d.ts.map +1 -1
- package/dist/memory/index.js +2 -0
- package/dist/memory/tool-output-compressor.d.ts +14 -20
- package/dist/memory/tool-output-compressor.d.ts.map +1 -1
- package/dist/memory/tool-output-compressor.js +391 -137
- package/dist/memory/tools/compact-context.d.ts +5 -0
- package/dist/memory/tools/compact-context.d.ts.map +1 -0
- package/dist/memory/tools/compact-context.js +772 -0
- package/dist/relay/dispatcher.d.ts +1 -1
- package/dist/relay/dispatcher.d.ts.map +1 -1
- package/dist/relay/dispatcher.js +61 -1
- package/dist/sdk/coding-agent/core/agent-session.d.ts +56 -3
- package/dist/sdk/coding-agent/core/agent-session.d.ts.map +1 -1
- package/dist/sdk/coding-agent/core/agent-session.js +408 -210
- package/dist/sdk/coding-agent/core/compaction/compaction.d.ts +57 -7
- package/dist/sdk/coding-agent/core/compaction/compaction.d.ts.map +1 -1
- package/dist/sdk/coding-agent/core/compaction/compaction.js +146 -27
- package/dist/sdk/coding-agent/core/compaction/dcp-lite.d.ts +24 -0
- package/dist/sdk/coding-agent/core/compaction/dcp-lite.d.ts.map +1 -0
- package/dist/sdk/coding-agent/core/compaction/dcp-lite.js +411 -0
- package/dist/sdk/coding-agent/core/compaction/index.d.ts +2 -0
- package/dist/sdk/coding-agent/core/compaction/index.d.ts.map +1 -1
- package/dist/sdk/coding-agent/core/compaction/index.js +2 -0
- package/dist/sdk/coding-agent/core/compaction/policy.d.ts +71 -0
- package/dist/sdk/coding-agent/core/compaction/policy.d.ts.map +1 -0
- package/dist/sdk/coding-agent/core/compaction/policy.js +147 -0
- package/dist/sdk/coding-agent/core/extensions/native-extensions.d.ts.map +1 -1
- package/dist/sdk/coding-agent/core/extensions/native-extensions.js +9 -0
- package/dist/sdk/coding-agent/core/extensions/types.d.ts +17 -0
- package/dist/sdk/coding-agent/core/extensions/types.d.ts.map +1 -1
- package/dist/sdk/coding-agent/core/settings-manager.d.ts +4 -10
- package/dist/sdk/coding-agent/core/settings-manager.d.ts.map +1 -1
- package/dist/sdk/coding-agent/core/settings-manager.js +17 -17
- package/dist/sdk/coding-agent/index.d.ts +1 -1
- package/dist/sdk/coding-agent/index.d.ts.map +1 -1
- package/dist/server/agent-bridge.d.ts +12 -5
- package/dist/server/agent-bridge.d.ts.map +1 -1
- package/dist/server/agent-bridge.js +65 -17
- package/dist/server/handlers/paths-home.d.ts +11 -0
- package/dist/server/handlers/paths-home.d.ts.map +1 -0
- package/dist/server/handlers/paths-home.js +10 -0
- package/dist/server/handlers/paths-list.d.ts +24 -0
- package/dist/server/handlers/paths-list.d.ts.map +1 -0
- package/dist/server/handlers/paths-list.js +56 -0
- package/dist/server/handlers/paths-pick-directory.d.ts.map +1 -1
- package/dist/server/handlers/paths-pick-directory.js +2 -1
- package/dist/server/handlers/sessions.d.ts +11 -1
- package/dist/server/handlers/sessions.d.ts.map +1 -1
- package/dist/server/handlers/sessions.js +22 -2
- package/dist/server/handlers/settings.d.ts +18 -1
- package/dist/server/handlers/settings.d.ts.map +1 -1
- package/dist/server/handlers/settings.js +63 -13
- package/dist/server/session-stream.d.ts +65 -37
- package/dist/server/session-stream.d.ts.map +1 -1
- package/dist/server/session-stream.js +525 -119
- package/dist/server/storage.d.ts +3 -0
- package/dist/server/storage.d.ts.map +1 -1
- package/dist/server/storage.js +25 -0
- package/dist/server/wire.d.ts +127 -2
- package/dist/server/wire.d.ts.map +1 -1
- package/package.json +2 -1
package/dist/memory/config.js
CHANGED
|
@@ -3,11 +3,17 @@ import { join } from "node:path";
|
|
|
3
3
|
import { getAgentDir } from "../sdk/coding-agent/index.js";
|
|
4
4
|
export const DEFAULTS = {
|
|
5
5
|
observationThresholdTokens: 1_000,
|
|
6
|
-
compactionThresholdTokens:
|
|
6
|
+
compactionThresholdTokens: 40_000,
|
|
7
7
|
reflectionThresholdTokens: 10_000,
|
|
8
8
|
passive: false,
|
|
9
9
|
debugLog: false,
|
|
10
10
|
observerMaxChunkTokens: 30_000,
|
|
11
|
+
dcpNudgeMinRawTokens: 15_000,
|
|
12
|
+
dcpNudgeMinContextTokens: 50_000,
|
|
13
|
+
dcpNudgeContextPercent: 35,
|
|
14
|
+
dcpNudgeTurnInterval: 5,
|
|
15
|
+
dcpInRunNudgeIterationThreshold: 15,
|
|
16
|
+
dcpInRunNudgeFrequency: 5,
|
|
11
17
|
};
|
|
12
18
|
const SETTINGS_KEY = "observational-memory";
|
|
13
19
|
const PASSIVE_ENV = "PI_OBSERVATIONAL_MEMORY_PASSIVE";
|
|
@@ -23,10 +29,17 @@ function normalizeTurnLimit(normalized, key) {
|
|
|
23
29
|
delete normalized[key];
|
|
24
30
|
}
|
|
25
31
|
else {
|
|
26
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
27
32
|
normalized[key] = value;
|
|
28
33
|
}
|
|
29
34
|
}
|
|
35
|
+
function normalizePercent(normalized, key) {
|
|
36
|
+
if (!(key in normalized))
|
|
37
|
+
return;
|
|
38
|
+
const value = normalized[key];
|
|
39
|
+
if (typeof value === "number" && Number.isFinite(value) && value > 0 && value <= 100)
|
|
40
|
+
return;
|
|
41
|
+
delete normalized[key];
|
|
42
|
+
}
|
|
30
43
|
const RELEVANCE_VALUES = ["low", "medium", "high", "critical"];
|
|
31
44
|
function normalizeInterAgentConfig(value) {
|
|
32
45
|
if (!value || typeof value !== "object")
|
|
@@ -55,6 +68,12 @@ function normalizeSettingsConfig(value) {
|
|
|
55
68
|
normalizeTurnLimit(normalized, "observerMaxChunkTokens");
|
|
56
69
|
normalizeTurnLimit(normalized, "reflectorMaxTurnsPerPass");
|
|
57
70
|
normalizeTurnLimit(normalized, "prunerMaxTurnsPerPass");
|
|
71
|
+
normalizeTurnLimit(normalized, "dcpNudgeMinRawTokens");
|
|
72
|
+
normalizeTurnLimit(normalized, "dcpNudgeMinContextTokens");
|
|
73
|
+
normalizeTurnLimit(normalized, "dcpNudgeTurnInterval");
|
|
74
|
+
normalizeTurnLimit(normalized, "dcpInRunNudgeIterationThreshold");
|
|
75
|
+
normalizeTurnLimit(normalized, "dcpInRunNudgeFrequency");
|
|
76
|
+
normalizePercent(normalized, "dcpNudgeContextPercent");
|
|
58
77
|
normalizeTurnLimit(normalized, "compactionMaxToolCalls");
|
|
59
78
|
if ("interAgent" in normalized) {
|
|
60
79
|
const normalizedInterAgent = normalizeInterAgentConfig(normalized.interAgent);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compaction-trigger.d.ts","sourceRoot":"","sources":["../../../src/memory/hooks/compaction-trigger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,
|
|
1
|
+
{"version":3,"file":"compaction-trigger.d.ts","sourceRoot":"","sources":["../../../src/memory/hooks/compaction-trigger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAoB,MAAM,iCAAiC,CAAC;AAGtF,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAkB7C,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,YAAY,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI,CAmGnF"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DEFAULT_COMPACTION_POLICY } from "../../sdk/coding-agent/core/compaction/index.js";
|
|
1
2
|
import { rawTokensSinceLastCompaction } from "../branch.js";
|
|
2
3
|
/**
|
|
3
4
|
* Regex matching spectral's internal retryable error detection.
|
|
@@ -5,11 +6,20 @@ import { rawTokensSinceLastCompaction } from "../branch.js";
|
|
|
5
6
|
* Pi will auto-retry — we must not trigger compaction between attempts.
|
|
6
7
|
*/
|
|
7
8
|
const RETRYABLE_ERROR_RE = /overloaded|provider.?returned.?error|rate.?limit|too many requests|429|500|502|503|504|service.?unavailable|server.?error|internal.?error|network.?error|connection.?error|connection.?refused|connection.?lost|websocket.?closed|websocket.?error|other side closed|fetch failed|upstream.?connect|reset before headers|socket hang up|ended without|http2 request did not get a response|timed? out|timeout|terminated|retry delay/i;
|
|
9
|
+
function getCompactionPolicy(ctx) {
|
|
10
|
+
return ctx.settingsManager?.getCompactionPolicy?.() ?? DEFAULT_COMPACTION_POLICY;
|
|
11
|
+
}
|
|
12
|
+
function getPostRunCompactionThresholdTokens(runtime, policy) {
|
|
13
|
+
return Math.max(runtime.config.compactionThresholdTokens, policy.autoOlderHistory.minRawTokens);
|
|
14
|
+
}
|
|
8
15
|
export function registerCompactionTrigger(ext, runtime) {
|
|
9
16
|
ext.on("agent_end", (event, ctx) => {
|
|
10
17
|
runtime.ensureConfig(ctx.cwd);
|
|
11
18
|
if (runtime.config.passive === true)
|
|
12
19
|
return;
|
|
20
|
+
const policy = getCompactionPolicy(ctx);
|
|
21
|
+
if (!policy.conversation.enabled || !policy.autoOlderHistory.enabled)
|
|
22
|
+
return;
|
|
13
23
|
if (runtime.compactInFlight)
|
|
14
24
|
return;
|
|
15
25
|
// Don't trigger compaction if Pi will auto-retry — the agent hasn't truly finished.
|
|
@@ -24,7 +34,8 @@ export function registerCompactionTrigger(ext, runtime) {
|
|
|
24
34
|
}
|
|
25
35
|
const entries = ctx.sessionManager.getBranch();
|
|
26
36
|
const tokens = rawTokensSinceLastCompaction(entries);
|
|
27
|
-
|
|
37
|
+
const thresholdTokens = getPostRunCompactionThresholdTokens(runtime, policy);
|
|
38
|
+
if (tokens < thresholdTokens)
|
|
28
39
|
return;
|
|
29
40
|
// Capture ctx properties synchronously — the setTimeout + async work below
|
|
30
41
|
// may outlive the extension ctx (stale after session replacement/reload).
|
|
@@ -53,15 +64,20 @@ export function registerCompactionTrigger(ext, runtime) {
|
|
|
53
64
|
}
|
|
54
65
|
const currentEntries = ctx.sessionManager.getBranch();
|
|
55
66
|
const currentTokens = rawTokensSinceLastCompaction(currentEntries);
|
|
56
|
-
if (currentTokens <
|
|
67
|
+
if (currentTokens < thresholdTokens) {
|
|
57
68
|
runtime.compactInFlight = false;
|
|
58
69
|
if (hasUI)
|
|
59
70
|
ui?.notify("Observational memory: compaction skipped — another compaction already ran during observer wait", "info");
|
|
60
71
|
return;
|
|
61
72
|
}
|
|
62
73
|
ctx.compact({
|
|
63
|
-
onComplete: () => {
|
|
74
|
+
onComplete: (result) => {
|
|
64
75
|
runtime.compactInFlight = false;
|
|
76
|
+
if (result.skipped) {
|
|
77
|
+
if (hasUI)
|
|
78
|
+
ui?.notify(`Observational memory: compaction skipped — ${result.message ?? "summary would not shrink context"}`, "warning");
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
65
81
|
if (hasUI)
|
|
66
82
|
ui?.notify("Observational memory: compaction complete", "info");
|
|
67
83
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/memory/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/memory/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAgBjE,MAAM,CAAC,OAAO,UAAU,mBAAmB,CAAC,GAAG,EAAE,YAAY,QAqB5D"}
|
package/dist/memory/index.js
CHANGED
|
@@ -6,6 +6,7 @@ import { registerInterAgentReceiver } from "./hooks/inter-agent-receiver.js";
|
|
|
6
6
|
import { registerObserverTrigger } from "./hooks/observer-trigger.js";
|
|
7
7
|
import { Runtime } from "./runtime.js";
|
|
8
8
|
import { registerToolOutputCompressor } from "./tool-output-compressor.js";
|
|
9
|
+
import { registerCompactContextTool } from "./tools/compact-context.js";
|
|
9
10
|
import { registerRecallTool } from "./tools/recall-observation.js";
|
|
10
11
|
import { registerReadProjectObservationsTool } from "./tools/read-project-observations.js";
|
|
11
12
|
import { registerReceiveAgentObservationsTool } from "./tools/receive-agent-observations.js";
|
|
@@ -16,6 +17,7 @@ export default function observationalMemory(ext) {
|
|
|
16
17
|
// Log extension load so we can confirm it's running in serve mode.
|
|
17
18
|
process.stderr.write("[obs-mem] extension loaded\n");
|
|
18
19
|
registerObserverTrigger(ext, runtime);
|
|
20
|
+
registerCompactContextTool(ext, runtime);
|
|
19
21
|
registerCompactionTrigger(ext, runtime);
|
|
20
22
|
registerCompactionHook(ext, runtime);
|
|
21
23
|
registerToolOutputCompressor(ext, runtime);
|
|
@@ -29,27 +29,9 @@
|
|
|
29
29
|
* - Docker/build output: collapse progress lines
|
|
30
30
|
*/
|
|
31
31
|
import type { ExtensionAPI } from "../sdk/coding-agent/index.js";
|
|
32
|
+
import { type ToolOutputCompressorPolicy } from "../sdk/coding-agent/core/compaction/policy.js";
|
|
32
33
|
import type { Runtime } from "./runtime.js";
|
|
33
|
-
export
|
|
34
|
-
/** Enable compression (default: true) */
|
|
35
|
-
enabled: boolean;
|
|
36
|
-
/** Maximum characters for any single tool result before truncation */
|
|
37
|
-
maxResultChars: number;
|
|
38
|
-
/** Maximum lines for read results before truncation */
|
|
39
|
-
maxReadLines: number;
|
|
40
|
-
/** Maximum lines for directory listings */
|
|
41
|
-
maxLsLines: number;
|
|
42
|
-
/** Maximum lines for grep/find results before grouping */
|
|
43
|
-
maxSearchLines: number;
|
|
44
|
-
/** Enable ANSI escape code stripping */
|
|
45
|
-
stripAnsi: boolean;
|
|
46
|
-
/** Enable comment stripping for code files */
|
|
47
|
-
stripComments: boolean;
|
|
48
|
-
/** Enable test-runner failure-only filtering */
|
|
49
|
-
testFailuresOnly: boolean;
|
|
50
|
-
/** Enable git output compacting */
|
|
51
|
-
compactGit: boolean;
|
|
52
|
-
}
|
|
34
|
+
export type CompressorConfig = ToolOutputCompressorPolicy;
|
|
53
35
|
export declare const DEFAULT_COMPRESSOR_CONFIG: CompressorConfig;
|
|
54
36
|
export interface CompressionStats {
|
|
55
37
|
originalChars: number;
|
|
@@ -57,5 +39,17 @@ export interface CompressionStats {
|
|
|
57
39
|
savingsPercent: number;
|
|
58
40
|
toolName: string;
|
|
59
41
|
}
|
|
42
|
+
export interface ToolOutputCompressionTelemetry {
|
|
43
|
+
events: number;
|
|
44
|
+
originalChars: number;
|
|
45
|
+
compressedChars: number;
|
|
46
|
+
byTool: Record<string, {
|
|
47
|
+
events: number;
|
|
48
|
+
originalChars: number;
|
|
49
|
+
compressedChars: number;
|
|
50
|
+
}>;
|
|
51
|
+
}
|
|
52
|
+
export declare function getToolOutputCompressionTelemetry(runtime: Runtime): ToolOutputCompressionTelemetry;
|
|
53
|
+
export declare function resetToolOutputCompressionTelemetry(runtime: Runtime): void;
|
|
60
54
|
export declare function registerToolOutputCompressor(ext: ExtensionAPI, runtime: Runtime): void;
|
|
61
55
|
//# sourceMappingURL=tool-output-compressor.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-output-compressor.d.ts","sourceRoot":"","sources":["../../src/memory/tool-output-compressor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"tool-output-compressor.d.ts","sourceRoot":"","sources":["../../src/memory/tool-output-compressor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAWjE,OAAO,EAGN,KAAK,0BAA0B,EAC/B,MAAM,+CAA+C,CAAC;AACvD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAO5C,MAAM,MAAM,gBAAgB,GAAG,0BAA0B,CAAC;AAE1D,eAAO,MAAM,yBAAyB,EAAE,gBAEvC,CAAC;AAqyBF,MAAM,WAAW,gBAAgB;IAChC,aAAa,EAAE,MAAM,CAAC;IACtB,eAAe,EAAE,MAAM,CAAC;IACxB,cAAc,EAAE,MAAM,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,8BAA8B;IAC9C,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,MAAM,CAAC;IACtB,eAAe,EAAE,MAAM,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,aAAa,EAAE,MAAM,CAAC;QAAC,eAAe,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAC3F;AA8BD,wBAAgB,iCAAiC,CAAC,OAAO,EAAE,OAAO,GAAG,8BAA8B,CAElG;AAED,wBAAgB,mCAAmC,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAE1E;AAkDD,wBAAgB,4BAA4B,CAC3C,GAAG,EAAE,YAAY,EACjB,OAAO,EAAE,OAAO,GACd,IAAI,CAqEN"}
|