@the-forge-flow/ultra-compress-pi 0.1.1
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 +144 -0
- package/dist/commands/index.d.ts +6 -0
- package/dist/commands/index.d.ts.map +1 -0
- package/dist/commands/index.js +5 -0
- package/dist/commands/index.js.map +1 -0
- package/dist/commands/types.d.ts +18 -0
- package/dist/commands/types.d.ts.map +1 -0
- package/dist/commands/types.js +2 -0
- package/dist/commands/types.js.map +1 -0
- package/dist/commands/uc-file.d.ts +7 -0
- package/dist/commands/uc-file.d.ts.map +1 -0
- package/dist/commands/uc-file.js +105 -0
- package/dist/commands/uc-file.js.map +1 -0
- package/dist/commands/uc-revert.d.ts +3 -0
- package/dist/commands/uc-revert.d.ts.map +1 -0
- package/dist/commands/uc-revert.js +38 -0
- package/dist/commands/uc-revert.js.map +1 -0
- package/dist/commands/uc-status.d.ts +3 -0
- package/dist/commands/uc-status.d.ts.map +1 -0
- package/dist/commands/uc-status.js +27 -0
- package/dist/commands/uc-status.js.map +1 -0
- package/dist/commands/uc.d.ts +3 -0
- package/dist/commands/uc.d.ts.map +1 -0
- package/dist/commands/uc.js +28 -0
- package/dist/commands/uc.js.map +1 -0
- package/dist/hooks/agent-end.d.ts +10 -0
- package/dist/hooks/agent-end.d.ts.map +1 -0
- package/dist/hooks/agent-end.js +38 -0
- package/dist/hooks/agent-end.js.map +1 -0
- package/dist/hooks/before-agent-start.d.ts +13 -0
- package/dist/hooks/before-agent-start.d.ts.map +1 -0
- package/dist/hooks/before-agent-start.js +11 -0
- package/dist/hooks/before-agent-start.js.map +1 -0
- package/dist/hooks/index.d.ts +7 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +4 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/session-start.d.ts +13 -0
- package/dist/hooks/session-start.d.ts.map +1 -0
- package/dist/hooks/session-start.js +11 -0
- package/dist/hooks/session-start.js.map +1 -0
- package/dist/index.d.ts +40 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +101 -0
- package/dist/index.js.map +1 -0
- package/dist/services/backup-path.d.ts +2 -0
- package/dist/services/backup-path.d.ts.map +1 -0
- package/dist/services/backup-path.js +7 -0
- package/dist/services/backup-path.js.map +1 -0
- package/dist/services/compress-pipeline.d.ts +12 -0
- package/dist/services/compress-pipeline.d.ts.map +1 -0
- package/dist/services/compress-pipeline.js +81 -0
- package/dist/services/compress-pipeline.js.map +1 -0
- package/dist/services/file-ops.d.ts +12 -0
- package/dist/services/file-ops.d.ts.map +1 -0
- package/dist/services/file-ops.js +58 -0
- package/dist/services/file-ops.js.map +1 -0
- package/dist/services/index.d.ts +8 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +7 -0
- package/dist/services/index.js.map +1 -0
- package/dist/services/level-prompts.d.ts +3 -0
- package/dist/services/level-prompts.d.ts.map +1 -0
- package/dist/services/level-prompts.js +78 -0
- package/dist/services/level-prompts.js.map +1 -0
- package/dist/services/level-rules.d.ts +9 -0
- package/dist/services/level-rules.d.ts.map +1 -0
- package/dist/services/level-rules.js +110 -0
- package/dist/services/level-rules.js.map +1 -0
- package/dist/services/llm-factory.d.ts +15 -0
- package/dist/services/llm-factory.d.ts.map +1 -0
- package/dist/services/llm-factory.js +24 -0
- package/dist/services/llm-factory.js.map +1 -0
- package/dist/services/path-guard.d.ts +8 -0
- package/dist/services/path-guard.d.ts.map +1 -0
- package/dist/services/path-guard.js +42 -0
- package/dist/services/path-guard.js.map +1 -0
- package/dist/services/state-store.d.ts +10 -0
- package/dist/services/state-store.d.ts.map +1 -0
- package/dist/services/state-store.js +106 -0
- package/dist/services/state-store.js.map +1 -0
- package/dist/services/stats.d.ts +4 -0
- package/dist/services/stats.d.ts.map +1 -0
- package/dist/services/stats.js +18 -0
- package/dist/services/stats.js.map +1 -0
- package/dist/services/validator.d.ts +3 -0
- package/dist/services/validator.d.ts.map +1 -0
- package/dist/services/validator.js +87 -0
- package/dist/services/validator.js.map +1 -0
- package/dist/skills/ultra-compress/SKILL.md +94 -0
- package/dist/types.d.ts +62 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +41 -0
- package/dist/types.js.map +1 -0
- package/package.json +90 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-start.js","sourceRoot":"","sources":["../../src/hooks/session-start.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAqBvE,MAAM,UAAU,sBAAsB,CAAC,IAAsB;IAC5D,OAAO,KAAK,UAAU,cAAc,CAAC,MAAM,EAAE,GAAG;QAC/C,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACxC,MAAM,iBAAiB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACjC,IAAI,MAAM,CAAC,KAAK,KAAK,KAAK,EAAE,CAAC;YAC5B,IAAI,CAAC,MAAM,CAAC,mBAAmB,MAAM,CAAC,KAAK,gBAAgB,EAAE,MAAM,CAAC,CAAC;QACtE,CAAC;IACF,CAAC,CAAC;AACH,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { type LLMFactoryContext } from "./services/llm-factory";
|
|
2
|
+
import type { ActiveLevel, CompressOptions, CompressResult, Level } from "./types";
|
|
3
|
+
type PiEventHandler = (event: unknown, ctx: unknown) => unknown | Promise<unknown>;
|
|
4
|
+
interface PiRegisteredCommand {
|
|
5
|
+
description?: string;
|
|
6
|
+
getArgumentCompletions?(prefix: string): Array<{
|
|
7
|
+
value: string;
|
|
8
|
+
label: string;
|
|
9
|
+
}> | null;
|
|
10
|
+
handler(args: string, ctx: PiCommandContext): Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
interface PiCommandContext {
|
|
13
|
+
ui?: {
|
|
14
|
+
notify?: (message: string, level?: string) => void;
|
|
15
|
+
};
|
|
16
|
+
cwd?: string;
|
|
17
|
+
modelRegistry?: LLMFactoryContext["modelRegistry"];
|
|
18
|
+
signal?: AbortSignal;
|
|
19
|
+
}
|
|
20
|
+
export interface PiExtensionApi {
|
|
21
|
+
on(event: string, handler: PiEventHandler): void;
|
|
22
|
+
registerCommand(name: string, config: PiRegisteredCommand): void;
|
|
23
|
+
cwd?: string;
|
|
24
|
+
}
|
|
25
|
+
export default function ultraCompressExtension(pi: PiExtensionApi): void;
|
|
26
|
+
export type { ActiveLevel, CompressOptions, CompressResult, Level, Mode, } from "./types";
|
|
27
|
+
export { PIContextRequiredError } from "./types";
|
|
28
|
+
export { buildLevelPromptFragment } from "./services/level-prompts";
|
|
29
|
+
export { validateCompression } from "./services/validator";
|
|
30
|
+
export declare function getActiveLevel(projectRoot?: string): Promise<Level>;
|
|
31
|
+
export type CtxLike = LLMFactoryContext & {
|
|
32
|
+
cwd?: string;
|
|
33
|
+
};
|
|
34
|
+
export declare function compressText(input: string, level: ActiveLevel, ctx: CtxLike, opts?: CompressOptions): Promise<CompressResult>;
|
|
35
|
+
export declare function compressTextLexical(input: string, level: ActiveLevel): {
|
|
36
|
+
compressed: string;
|
|
37
|
+
before: number;
|
|
38
|
+
after: number;
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,KAAK,iBAAiB,EAAW,MAAM,wBAAwB,CAAC;AAEzE,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAInF,KAAK,cAAc,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;AAEnF,UAAU,mBAAmB;IAC5B,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M,OAAO,GAAG,iBAAiB,GAAG;IAAE,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAE3D,wBAAsB,YAAY,CACjC,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,WAAW,EAClB,GAAG,EAAE,OAAO,EACZ,IAAI,CAAC,EAAE,eAAe,GACpB,OAAO,CAAC,cAAc,CAAC,CAazB;AAED,wBAAgB,mBAAmB,CAClC,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,WAAW,GAChB;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAGvD"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { dirname, join } from "node:path";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
import { createUcCommand, createUcFileCommand, createUcRevertCommand, createUcStatusCommand, } from "./commands";
|
|
4
|
+
import { createAgentEndHook, createBeforeAgentStartHook, createSessionStartHook } from "./hooks";
|
|
5
|
+
import { compressTextPipeline } from "./services/compress-pipeline";
|
|
6
|
+
import { applyLevelLexical } from "./services/level-rules";
|
|
7
|
+
import { makeLLM } from "./services/llm-factory";
|
|
8
|
+
import { loadState } from "./services/state-store";
|
|
9
|
+
function wrapCommand(def) {
|
|
10
|
+
return {
|
|
11
|
+
description: def.description,
|
|
12
|
+
...(def.getArgumentCompletions ? { getArgumentCompletions: def.getArgumentCompletions } : {}),
|
|
13
|
+
async handler(args, piCtx) {
|
|
14
|
+
const ctx = {
|
|
15
|
+
cwd: piCtx.cwd ?? process.cwd(),
|
|
16
|
+
ui: {
|
|
17
|
+
notify: (message, level = "info") => {
|
|
18
|
+
piCtx.ui?.notify?.(message, level);
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
await def.handler(args, ctx);
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export default function ultraCompressExtension(pi) {
|
|
27
|
+
const notify = (message, level = "info") => {
|
|
28
|
+
process.stderr.write(`[ultra-compress] ${level}: ${message}\n`);
|
|
29
|
+
};
|
|
30
|
+
pi.registerCommand("uc", wrapCommand(createUcCommand()));
|
|
31
|
+
pi.registerCommand("uc-file", wrapCommand(createUcFileCommand({
|
|
32
|
+
llm: (ctx) => {
|
|
33
|
+
const piCtx = ctx;
|
|
34
|
+
const factoryCtx = {};
|
|
35
|
+
if (piCtx.modelRegistry !== undefined)
|
|
36
|
+
factoryCtx.modelRegistry = piCtx.modelRegistry;
|
|
37
|
+
if (piCtx.signal !== undefined)
|
|
38
|
+
factoryCtx.signal = piCtx.signal;
|
|
39
|
+
return makeLLM(factoryCtx);
|
|
40
|
+
},
|
|
41
|
+
})));
|
|
42
|
+
pi.registerCommand("uc-status", wrapCommand(createUcStatusCommand()));
|
|
43
|
+
pi.registerCommand("uc-revert", wrapCommand(createUcRevertCommand()));
|
|
44
|
+
const sessionStart = createSessionStartHook({ notify });
|
|
45
|
+
const beforeAgentStart = createBeforeAgentStartHook();
|
|
46
|
+
const agentEnd = createAgentEndHook();
|
|
47
|
+
pi.on("session_start", async (event, ctx) => {
|
|
48
|
+
const e = event;
|
|
49
|
+
const c = ctx;
|
|
50
|
+
if (typeof c?.cwd !== "string")
|
|
51
|
+
return;
|
|
52
|
+
await sessionStart({ reason: e?.reason ?? "startup" }, { cwd: c.cwd });
|
|
53
|
+
});
|
|
54
|
+
pi.on("before_agent_start", async (event, ctx) => {
|
|
55
|
+
const e = event;
|
|
56
|
+
const c = ctx;
|
|
57
|
+
if (typeof e?.prompt !== "string" || typeof e?.systemPrompt !== "string")
|
|
58
|
+
return;
|
|
59
|
+
if (typeof c?.cwd !== "string")
|
|
60
|
+
return;
|
|
61
|
+
return await beforeAgentStart({ prompt: e.prompt, systemPrompt: e.systemPrompt }, { cwd: c.cwd });
|
|
62
|
+
});
|
|
63
|
+
pi.on("agent_end", async (event, ctx) => {
|
|
64
|
+
const c = ctx;
|
|
65
|
+
if (typeof c?.cwd !== "string")
|
|
66
|
+
return;
|
|
67
|
+
const e = event;
|
|
68
|
+
await agentEnd(e, { cwd: c.cwd });
|
|
69
|
+
});
|
|
70
|
+
const extensionDir = dirname(fileURLToPath(import.meta.url));
|
|
71
|
+
const skillsDir = join(extensionDir, "skills");
|
|
72
|
+
pi.on("resources_discover", () => ({ skills: [skillsDir] }));
|
|
73
|
+
}
|
|
74
|
+
export { PIContextRequiredError } from "./types";
|
|
75
|
+
export { buildLevelPromptFragment } from "./services/level-prompts";
|
|
76
|
+
export { validateCompression } from "./services/validator";
|
|
77
|
+
export async function getActiveLevel(projectRoot) {
|
|
78
|
+
const state = await loadState(projectRoot);
|
|
79
|
+
return state.level;
|
|
80
|
+
}
|
|
81
|
+
export async function compressText(input, level, ctx, opts) {
|
|
82
|
+
const factoryCtx = {};
|
|
83
|
+
if (ctx.modelRegistry !== undefined)
|
|
84
|
+
factoryCtx.modelRegistry = ctx.modelRegistry;
|
|
85
|
+
if (ctx.signal !== undefined)
|
|
86
|
+
factoryCtx.signal = ctx.signal;
|
|
87
|
+
const llm = makeLLM(factoryCtx);
|
|
88
|
+
return compressTextPipeline({
|
|
89
|
+
input,
|
|
90
|
+
level,
|
|
91
|
+
mode: "file",
|
|
92
|
+
llm,
|
|
93
|
+
...(opts?.maxRepairRetries !== undefined ? { maxRepairRetries: opts.maxRepairRetries } : {}),
|
|
94
|
+
...(ctx.signal ? { signal: ctx.signal } : {}),
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
export function compressTextLexical(input, level) {
|
|
98
|
+
const compressed = applyLevelLexical(input, level);
|
|
99
|
+
return { compressed, before: input.length, after: compressed.length };
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,IAAI,EAA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EAAE,KAAK,CAAC,CAAC;IACnD,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,KAAK,EAAE,UAAU,CAAC,MAAM,EAAE,CAAC;AACvE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"backup-path.d.ts","sourceRoot":"","sources":["../../src/services/backup-path.ts"],"names":[],"mappings":"AAGA,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEjD"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Canonical backup path for ultra-compress — always appends ".original.md"
|
|
2
|
+
// regardless of the source extension. Matches the spec literally and keeps
|
|
3
|
+
// the collision check trivial (single filename per source).
|
|
4
|
+
export function backupPathFor(abs) {
|
|
5
|
+
return `${abs}.original.md`;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=backup-path.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"backup-path.js","sourceRoot":"","sources":["../../src/services/backup-path.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,2EAA2E;AAC3E,4DAA4D;AAC5D,MAAM,UAAU,aAAa,CAAC,GAAW;IACxC,OAAO,GAAG,GAAG,cAAc,CAAC;AAC7B,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type ActiveLevel, type CompressResult, type Mode } from "../types";
|
|
2
|
+
export type LLMCall = (prompt: string, signal?: AbortSignal) => Promise<string>;
|
|
3
|
+
export interface CompressPipelineInput {
|
|
4
|
+
input: string;
|
|
5
|
+
level: ActiveLevel;
|
|
6
|
+
mode: Mode;
|
|
7
|
+
llm: LLMCall;
|
|
8
|
+
maxRepairRetries?: number;
|
|
9
|
+
signal?: AbortSignal;
|
|
10
|
+
}
|
|
11
|
+
export declare function compressTextPipeline(opts: CompressPipelineInput): Promise<CompressResult>;
|
|
12
|
+
//# sourceMappingURL=compress-pipeline.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compress-pipeline.d.ts","sourceRoot":"","sources":["../../src/services/compress-pipeline.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,cAAc,EAAE,KAAK,IAAI,EAAwB,MAAM,UAAU,CAAC;AAKlG,MAAM,MAAM,OAAO,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;AAEhF,MAAM,WAAW,qBAAqB;IACrC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,WAAW,CAAC;IACnB,IAAI,EAAE,IAAI,CAAC;IACX,GAAG,EAAE,OAAO,CAAC;IACb,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,MAAM,CAAC,EAAE,WAAW,CAAC;CACrB;AAuCD,wBAAsB,oBAAoB,CAAC,IAAI,EAAE,qBAAqB,GAAG,OAAO,CAAC,cAAc,CAAC,CAyD/F"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { ValidatorFailedError } from "../types";
|
|
2
|
+
import { buildLevelPromptFragment } from "./level-prompts";
|
|
3
|
+
import { applyLevelLexical, maskProtectedZones, unmaskProtectedZones } from "./level-rules";
|
|
4
|
+
import { validateCompression } from "./validator";
|
|
5
|
+
const OUTER_FENCE_RE = /^\s*```(?:\w+)?\n([\s\S]*?)\n```\s*$/;
|
|
6
|
+
function stripOuterFence(s) {
|
|
7
|
+
const m = s.match(OUTER_FENCE_RE);
|
|
8
|
+
if (!m)
|
|
9
|
+
return s;
|
|
10
|
+
// m[1] is guaranteed to exist since OUTER_FENCE_RE has one capture group
|
|
11
|
+
// biome-ignore lint/style/noNonNullAssertion: capture group always exists
|
|
12
|
+
return m[1];
|
|
13
|
+
}
|
|
14
|
+
function buildInitialPrompt(maskedPrePass, level, mode) {
|
|
15
|
+
const rules = buildLevelPromptFragment(level, mode);
|
|
16
|
+
return `${rules}\n\nInput to compress:\n\n${maskedPrePass}`;
|
|
17
|
+
}
|
|
18
|
+
function buildRepairPrompt(masked, previousOutput, errors, level, mode) {
|
|
19
|
+
return `${buildLevelPromptFragment(level, mode)}
|
|
20
|
+
|
|
21
|
+
Previous output had these specific errors. DO NOT recompress or rephrase — PATCH ONLY these drifts:
|
|
22
|
+
|
|
23
|
+
${errors.map((e) => `- ${e}`).join("\n")}
|
|
24
|
+
|
|
25
|
+
Original masked input:
|
|
26
|
+
${masked}
|
|
27
|
+
|
|
28
|
+
Previous attempt:
|
|
29
|
+
${previousOutput}
|
|
30
|
+
|
|
31
|
+
Return a corrected version that keeps the level-${level} compression but fixes the listed drifts.`;
|
|
32
|
+
}
|
|
33
|
+
export async function compressTextPipeline(opts) {
|
|
34
|
+
const { input, level, mode, llm, maxRepairRetries = 2, signal } = opts;
|
|
35
|
+
const { masked, tokens } = maskProtectedZones(input);
|
|
36
|
+
const lexical = applyLevelLexical(masked, level);
|
|
37
|
+
const prompt = buildInitialPrompt(lexical, level, mode);
|
|
38
|
+
let attempt = 0;
|
|
39
|
+
let lastOutput = "";
|
|
40
|
+
let lastErrors = [];
|
|
41
|
+
const warnings = [];
|
|
42
|
+
while (attempt <= maxRepairRetries) {
|
|
43
|
+
const raw = attempt === 0
|
|
44
|
+
? await llm(prompt, signal)
|
|
45
|
+
: await llm(buildRepairPrompt(lexical, lastOutput, lastErrors, level, mode), signal);
|
|
46
|
+
let stripped = stripOuterFence(raw.trim());
|
|
47
|
+
// Remove punctuation immediately after protected token references to avoid duplication
|
|
48
|
+
stripped = stripped.replace(/⟨PROT:\d+⟩[.,;:!?]/g, (match) => match.slice(0, -1));
|
|
49
|
+
lastOutput = stripped;
|
|
50
|
+
// Check protected tokens survived the LLM pass BEFORE unmasking, so
|
|
51
|
+
// dropped tokens surface as a specific repair signal rather than as
|
|
52
|
+
// vague "missing URL" errors downstream.
|
|
53
|
+
const missing = [];
|
|
54
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
55
|
+
if (!stripped.includes(`⟨PROT:${i}⟩`))
|
|
56
|
+
missing.push(`⟨PROT:${i}⟩`);
|
|
57
|
+
}
|
|
58
|
+
if (missing.length > 0) {
|
|
59
|
+
lastErrors = [
|
|
60
|
+
`dropped protected tokens: ${missing.join(", ")} — these MUST appear verbatim in the output`,
|
|
61
|
+
];
|
|
62
|
+
attempt += 1;
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
const unmasked = unmaskProtectedZones(stripped, tokens);
|
|
66
|
+
const report = validateCompression(input, unmasked);
|
|
67
|
+
if (report.ok) {
|
|
68
|
+
return {
|
|
69
|
+
compressed: unmasked,
|
|
70
|
+
before: input.length,
|
|
71
|
+
after: unmasked.length,
|
|
72
|
+
ratio: (input.length - unmasked.length) / input.length,
|
|
73
|
+
warnings: [...warnings, ...report.warnings],
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
lastErrors = report.errors;
|
|
77
|
+
attempt += 1;
|
|
78
|
+
}
|
|
79
|
+
throw new ValidatorFailedError(lastErrors);
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=compress-pipeline.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compress-pipeline.js","sourceRoot":"","sources":["../../src/services/compress-pipeline.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoD,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAClG,OAAO,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAC5F,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAalD,MAAM,cAAc,GAAG,sCAAsC,CAAC;AAE9D,SAAS,eAAe,CAAC,CAAS;IACjC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;IAClC,IAAI,CAAC,CAAC;QAAE,OAAO,CAAC,CA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,MAAM,EAAE,KAAK,CAAC,MAAM;gBACpB,KAAK,EAAE,QAAQ,CAAC,MAAM;gBACtB,KAAK,EAAE,CAAC,KAAK,CAAC,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC,MAAM;gBACtD,QAAQ,EAAE,CAAC,GAAG,QAAQ,EAAE,GAAG,MAAM,CAAC,QAAQ,CAAC;aAC3C,CAAC;QACH,CAAC;QAED,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC;QAC3B,OAAO,IAAI,CAAC,CAAC;IACd,CAAC;IAED,MAAM,IAAI,oBAAoB,CAAC,UAAU,CAAC,CAAC;AAC5C,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare function isSupportedExtension(ext: string): boolean;
|
|
2
|
+
export declare function extOf(path: string): string;
|
|
3
|
+
export declare function resolveForCompression(inputPath: string, cwd: string): {
|
|
4
|
+
abs: string;
|
|
5
|
+
backupPath: string;
|
|
6
|
+
content: string;
|
|
7
|
+
};
|
|
8
|
+
export declare function writeWithBackup(abs: string, backupPath: string, compressed: string): void;
|
|
9
|
+
export declare function restoreFromBackup(abs: string): {
|
|
10
|
+
backupPath: string;
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=file-ops.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-ops.d.ts","sourceRoot":"","sources":["../../src/services/file-ops.ts"],"names":[],"mappings":"AAQA,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAEzD;AAED,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAG1C;AAKD,wBAAgB,qBAAqB,CACpC,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,MAAM,GACT;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CA8BtD;AAID,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI,CAGzF;AAGD,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG;IAAE,UAAU,EAAE,MAAM,CAAA;CAAE,CAWrE"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { existsSync, readFileSync, renameSync, unlinkSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { BackupExistsError, FileTooLargeError, UnsupportedFileTypeError } from "../types";
|
|
3
|
+
import { backupPathFor } from "./backup-path";
|
|
4
|
+
import { safeResolveInCwd } from "./path-guard";
|
|
5
|
+
const MAX_BYTES = 500 * 1024;
|
|
6
|
+
const SUPPORTED_EXT = new Set([".md", ".txt", ".rst", ".markdown"]);
|
|
7
|
+
export function isSupportedExtension(ext) {
|
|
8
|
+
return SUPPORTED_EXT.has(ext.toLowerCase());
|
|
9
|
+
}
|
|
10
|
+
export function extOf(path) {
|
|
11
|
+
const i = path.lastIndexOf(".");
|
|
12
|
+
return i >= 0 ? path.slice(i).toLowerCase() : "";
|
|
13
|
+
}
|
|
14
|
+
// Resolve `inputPath` against `cwd` with path-traversal + symlink guards,
|
|
15
|
+
// reject unsupported extensions and over-size files, and reject if a backup
|
|
16
|
+
// already exists. Returns { abs, backupPath, content } ready for compression.
|
|
17
|
+
export function resolveForCompression(inputPath, cwd) {
|
|
18
|
+
const abs = safeResolveInCwd(inputPath, cwd);
|
|
19
|
+
if (!existsSync(abs)) {
|
|
20
|
+
throw new UnsupportedFileTypeError(abs, "file not found");
|
|
21
|
+
}
|
|
22
|
+
const ext = extOf(abs);
|
|
23
|
+
if (!isSupportedExtension(ext)) {
|
|
24
|
+
throw new UnsupportedFileTypeError(abs, `extension ${ext || "(none)"} not in ${[...SUPPORTED_EXT].join(",")}`);
|
|
25
|
+
}
|
|
26
|
+
if (abs.endsWith(".original.md")) {
|
|
27
|
+
throw new UnsupportedFileTypeError(abs, "path looks like a backup file");
|
|
28
|
+
}
|
|
29
|
+
const backupPath = backupPathFor(abs);
|
|
30
|
+
if (existsSync(backupPath)) {
|
|
31
|
+
throw new BackupExistsError(backupPath);
|
|
32
|
+
}
|
|
33
|
+
const buf = readFileSync(abs);
|
|
34
|
+
if (buf.byteLength > MAX_BYTES) {
|
|
35
|
+
throw new FileTooLargeError(abs, buf.byteLength);
|
|
36
|
+
}
|
|
37
|
+
return { abs, backupPath, content: buf.toString("utf8") };
|
|
38
|
+
}
|
|
39
|
+
// Move `abs` → `backupPath` and write `compressed` to `abs`. Caller must have
|
|
40
|
+
// already confirmed the backup path is free (resolveForCompression does this).
|
|
41
|
+
export function writeWithBackup(abs, backupPath, compressed) {
|
|
42
|
+
renameSync(abs, backupPath);
|
|
43
|
+
writeFileSync(abs, compressed, "utf8");
|
|
44
|
+
}
|
|
45
|
+
// Restore `abs` from its backup. Throws if no backup exists.
|
|
46
|
+
export function restoreFromBackup(abs) {
|
|
47
|
+
const backupPath = backupPathFor(abs);
|
|
48
|
+
if (!existsSync(backupPath)) {
|
|
49
|
+
const e = new Error(`ultra-compress: no backup at ${backupPath}`);
|
|
50
|
+
e.name = "NoBackupError";
|
|
51
|
+
throw e;
|
|
52
|
+
}
|
|
53
|
+
const content = readFileSync(backupPath, "utf8");
|
|
54
|
+
writeFileSync(abs, content, "utf8");
|
|
55
|
+
unlinkSync(backupPath);
|
|
56
|
+
return { backupPath };
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=file-ops.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-ops.js","sourceRoot":"","sources":["../../src/services/file-ops.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC1F,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,MAAM,UAAU,CAAC;AAC1F,OAAO,EAAE,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,UAAU,CAAC,CAAC;IACvB,OAAO,EAAE,UAAU,EAAE,CAAC;AACvB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { compressTextPipeline } from "./compress-pipeline";
|
|
2
|
+
export type { LLMCall, CompressPipelineInput } from "./compress-pipeline";
|
|
3
|
+
export { buildLevelPromptFragment } from "./level-prompts";
|
|
4
|
+
export { applyLevelLexical, maskProtectedZones, unmaskProtectedZones } from "./level-rules";
|
|
5
|
+
export { validateCompression } from "./validator";
|
|
6
|
+
export { levelFactor, estimateCharsSaved } from "./stats";
|
|
7
|
+
export { loadState, saveLevel, saveState, resetSessionStats, appendCompressedFile, incrementAutoClarity, addCharsSaved, } from "./state-store";
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,YAAY,EAAE,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAC1E,OAAO,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAC5F,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAC1D,OAAO,EACN,SAAS,EACT,SAAS,EACT,SAAS,EACT,iBAAiB,EACjB,oBAAoB,EACpB,oBAAoB,EACpB,aAAa,GACb,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { compressTextPipeline } from "./compress-pipeline";
|
|
2
|
+
export { buildLevelPromptFragment } from "./level-prompts";
|
|
3
|
+
export { applyLevelLexical, maskProtectedZones, unmaskProtectedZones } from "./level-rules";
|
|
4
|
+
export { validateCompression } from "./validator";
|
|
5
|
+
export { levelFactor, estimateCharsSaved } from "./stats";
|
|
6
|
+
export { loadState, saveLevel, saveState, resetSessionStats, appendCompressedFile, incrementAutoClarity, addCharsSaved, } from "./state-store";
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAE3D,OAAO,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAC5F,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAC1D,OAAO,EACN,SAAS,EACT,SAAS,EACT,SAAS,EACT,iBAAiB,EACjB,oBAAoB,EACpB,oBAAoB,EACpB,aAAa,GACb,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"level-prompts.d.ts","sourceRoot":"","sources":["../../src/services/level-prompts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AA6ElD,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,IAAI,GAAG,MAAM,CAK/E"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
const RUNTIME_BASE = `
|
|
2
|
+
You are operating in ultra-compress mode. Reduce output tokens by compressing prose.
|
|
3
|
+
|
|
4
|
+
Auto-Clarity override: temporarily fall back to full prose for the CURRENT assistant message when the turn involves any of:
|
|
5
|
+
- security / safety warnings
|
|
6
|
+
- destructive operations needing confirmation (rm -rf, git reset --hard, force push, DROP, etc.)
|
|
7
|
+
- numbered multi-step sequences where order matters
|
|
8
|
+
- verbatim-quoted error messages or logs
|
|
9
|
+
Resume the active level on the next turn.
|
|
10
|
+
|
|
11
|
+
Always preserve: fenced + inline code, URLs, file paths, CLI commands, tool names, $ARGUMENTS, quoted error strings, numeric versions/dates, frontmatter, heading structure.
|
|
12
|
+
`.trim();
|
|
13
|
+
const RUNTIME_RULES = {
|
|
14
|
+
lite: `
|
|
15
|
+
LEVEL = lite. Drop filler words (just, really, basically, actually, simply, essentially).
|
|
16
|
+
Drop hedging (might be worth, could consider, you might want to).
|
|
17
|
+
Drop pleasantries (sure, certainly, of course, happy to, I'd recommend).
|
|
18
|
+
Keep articles (a/an/the) and full sentences. Professional but tight.`.trim(),
|
|
19
|
+
standard: `
|
|
20
|
+
LEVEL = standard. Inherit lite rules, plus:
|
|
21
|
+
Drop articles (a/an/the). Drop connectives (however, furthermore, additionally, moreover).
|
|
22
|
+
Fragments allowed. Pattern: [thing] [action] [reason]. [next step].
|
|
23
|
+
Substitute: utilize→use, in order to→to, make sure to→ensure, the reason is because→because.
|
|
24
|
+
Use shorter synonyms: big (not extensive), fix (not implement a solution for).`.trim(),
|
|
25
|
+
ultra: `
|
|
26
|
+
LEVEL = ultra. Inherit standard rules, plus:
|
|
27
|
+
Abbreviate technical words: database→DB, authentication→auth, configuration→config,
|
|
28
|
+
request→req, response→res, function→fn, implementation→impl, environment→env, error→err.
|
|
29
|
+
Use arrow causality: "X causes Y" → "X → Y".
|
|
30
|
+
Strip conjunctions where meaning survives.`.trim(),
|
|
31
|
+
symbolic: `
|
|
32
|
+
LEVEL = symbolic. Inherit ultra rules, plus:
|
|
33
|
+
When context makes it unambiguous to the reader, use math/logic notation:
|
|
34
|
+
∀ (for all), ∃ (exists), ∧ (and), ∨ (or), ¬ (not), → (implies), ⟺ (iff),
|
|
35
|
+
∈ (in), ∉ (not in), ⊂ (subset), ∪ (union), ∩ (intersect), ∅ (empty set), { } (set).
|
|
36
|
+
Fold conditions into predicates: "pred(x) ⟺ A ∧ B".
|
|
37
|
+
IMPORTANT: Fall back to LEVEL=ultra if the conversation context suggests the human
|
|
38
|
+
is not fluent in this notation (e.g. UI/design questions, non-technical topics).`.trim(),
|
|
39
|
+
};
|
|
40
|
+
const FILE_BASE = `
|
|
41
|
+
You are rewriting a markdown file to reduce token cost. Follow the level rules below.
|
|
42
|
+
|
|
43
|
+
Preserve byte-identical: frontmatter, fenced code blocks, inline code spans, URLs, file paths,
|
|
44
|
+
CLI command lines, tool names, $ARGUMENTS, headings (count + order + exact text optional at ultra+),
|
|
45
|
+
numeric versions/dates, numbered lists, table structure, bullet nesting depth.
|
|
46
|
+
|
|
47
|
+
Do NOT wrap your response in any markdown code fence. Output ONLY the rewritten file body.
|
|
48
|
+
Preserve any ⟨PROT:N⟩ tokens verbatim — they are placeholders for protected content.
|
|
49
|
+
`.trim();
|
|
50
|
+
const FILE_RULES = {
|
|
51
|
+
lite: "LEVEL = lite. Drop filler/hedging/pleasantries from prose. Preserve all structure verbatim. Target ~15-25% reduction.",
|
|
52
|
+
standard: `LEVEL = standard. Inherit lite rules, plus:
|
|
53
|
+
Drop articles and connectives. Allow fragments. Apply substitutions (utilize→use, in order to→to, make sure to→ensure).
|
|
54
|
+
R6: tables/lists stay structurally intact; only wording compresses.
|
|
55
|
+
R7: prune redundant examples (leave one canonical example per concept).
|
|
56
|
+
Target ~35-50% reduction.`,
|
|
57
|
+
ultra: `LEVEL = ultra. Inherit standard rules, plus:
|
|
58
|
+
Abbreviate (DB, auth, config, req, res, fn, impl, env, err).
|
|
59
|
+
Arrow causality (X → Y).
|
|
60
|
+
R1: concepts appearing ≥3× get Greek-letter definitions in a "Let:" block at the top.
|
|
61
|
+
R8: literals appearing ≥2× become named constants.
|
|
62
|
+
R10: repeated parameterized patterns become F(x, y).
|
|
63
|
+
Target ~50-65% reduction.`,
|
|
64
|
+
symbolic: `LEVEL = symbolic. Inherit ultra rules, plus:
|
|
65
|
+
R2: multi-bullet conditions collapse to predicates: pred(x) ⟺ A ∧ B ∧ C.
|
|
66
|
+
R3: quantifier rewrites — "for each x in Y" → ∀ x ∈ Y:, "if any x" → ∃ x:.
|
|
67
|
+
R4: implications as arrows — "if X then Y" → X → Y.
|
|
68
|
+
R9: workflows become O_name { step₁; step₂; … } → output.
|
|
69
|
+
Use Greek vars (φ, γ, τ, π, σ) for repeated concepts.
|
|
70
|
+
Target ~55-70% reduction.`,
|
|
71
|
+
};
|
|
72
|
+
export function buildLevelPromptFragment(level, mode) {
|
|
73
|
+
if (mode === "runtime") {
|
|
74
|
+
return `${RUNTIME_BASE}\n\n${RUNTIME_RULES[level]}`;
|
|
75
|
+
}
|
|
76
|
+
return `${FILE_BASE}\n\n${FILE_RULES[level]}`;
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=level-prompts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"level-prompts.js","sourceRoot":"","sources":["../../src/services/level-prompts.ts"],"names":[],"mappings":"AAEA,MAAM,YAAY,GAAG;;;;;;;;;;;CAWpB,CAAC,IAAI,EAAE,CAAC;AAET,MAAM,aAAa,GAAgC;IAClD,IAAI,EAAE;;;;qEAI8D,CAAC,IAAI,EAAE;IAC3E,QAAQ,EAAE;;;;;+EAKoE,CAAC,IAAI,EAAE;IACrF,KAAK,EAAE;;;;;2CAKmC,CAAC,IAAI,EAAE;IACjD,QAAQ,EAAE;;;;;;;iFAOsE,CAAC,IAAI,EAAE;CACvF,CAAC;AAEF,MAAM,SAAS,GAAG;;;;;;;;;CASjB,CAAC,IAAI,EAAE,CAAC;AAET,MAAM,UAAU,GAAgC;IAC/C,IAAI,EAAE,uHAAuH;IAC7H,QAAQ,EAAE;;;;0BAIe;IACzB,KAAK,EAAE;;;;;;0BAMkB;IACzB,QAAQ,EAAE;;;;;;0BAMe;CACzB,CAAC;AAEF,MAAM,UAAU,wBAAwB,CAAC,KAAkB,EAAE,IAAU;IACtE,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACxB,OAAO,GAAG,YAAY,OAAO,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC;IACrD,CAAC;IACD,OAAO,GAAG,SAAS,OAAO,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;AAC/C,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ActiveLevel } from "../types";
|
|
2
|
+
export interface MaskResult {
|
|
3
|
+
masked: string;
|
|
4
|
+
tokens: string[];
|
|
5
|
+
}
|
|
6
|
+
export declare function maskProtectedZones(input: string): MaskResult;
|
|
7
|
+
export declare function unmaskProtectedZones(masked: string, tokens: string[]): string;
|
|
8
|
+
export declare function applyLevelLexical(input: string, level: ActiveLevel): string;
|
|
9
|
+
//# sourceMappingURL=level-rules.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"level-rules.d.ts","sourceRoot":"","sources":["../../src/services/level-rules.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAE5C,MAAM,WAAW,UAAU;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,EAAE,CAAC;CACjB;AAWD,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAW5D;AAED,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,CAM7E;AAyED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,GAAG,MAAM,CAwB3E"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
const PROTECTED_PATTERNS = [
|
|
2
|
+
/```[\s\S]*?```/g,
|
|
3
|
+
/`[^`\n]+`/g,
|
|
4
|
+
/\bhttps?:\/\/\S+/g,
|
|
5
|
+
/\$ARGUMENTS\b/g,
|
|
6
|
+
/(?:^|\s)(\.?[\w.\-/]+\/[\w.\-/]+)(?=\s|$)/g,
|
|
7
|
+
/(?:^|\s)([\w.-]+\.(?:ts|js|tsx|jsx|md|json|yaml|yml|py|rs|go|sh|sql))(?=\s|$)/g,
|
|
8
|
+
];
|
|
9
|
+
export function maskProtectedZones(input) {
|
|
10
|
+
const tokens = [];
|
|
11
|
+
let masked = input;
|
|
12
|
+
for (const pattern of PROTECTED_PATTERNS) {
|
|
13
|
+
masked = masked.replace(pattern, (match) => {
|
|
14
|
+
const token = `⟨PROT:${tokens.length}⟩`;
|
|
15
|
+
tokens.push(match);
|
|
16
|
+
return token;
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
return { masked, tokens };
|
|
20
|
+
}
|
|
21
|
+
export function unmaskProtectedZones(masked, tokens) {
|
|
22
|
+
let out = masked;
|
|
23
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
24
|
+
out = out.replace(`⟨PROT:${i}⟩`, tokens[i] ?? "");
|
|
25
|
+
}
|
|
26
|
+
return out;
|
|
27
|
+
}
|
|
28
|
+
const FILLERS = [
|
|
29
|
+
"just",
|
|
30
|
+
"really",
|
|
31
|
+
"basically",
|
|
32
|
+
"actually",
|
|
33
|
+
"simply",
|
|
34
|
+
"essentially",
|
|
35
|
+
"generally",
|
|
36
|
+
"literally",
|
|
37
|
+
"obviously",
|
|
38
|
+
];
|
|
39
|
+
const HEDGING_PHRASES = [
|
|
40
|
+
"it might be worth",
|
|
41
|
+
"you could consider",
|
|
42
|
+
"you might want to",
|
|
43
|
+
"it could be",
|
|
44
|
+
"perhaps you could",
|
|
45
|
+
];
|
|
46
|
+
const PLEASANTRIES = [
|
|
47
|
+
"sure",
|
|
48
|
+
"certainly",
|
|
49
|
+
"of course",
|
|
50
|
+
"happy to",
|
|
51
|
+
"i'd recommend",
|
|
52
|
+
"i would recommend",
|
|
53
|
+
];
|
|
54
|
+
const CONNECTIVES = ["however", "furthermore", "additionally", "moreover"];
|
|
55
|
+
const ARTICLES = /\b(?:a|an|the)\b/gi;
|
|
56
|
+
const SUBSTITUTIONS = [
|
|
57
|
+
[/\butilize\b/gi, "use"],
|
|
58
|
+
[/\bin order to\b/gi, "to"],
|
|
59
|
+
[/\bmake sure to\b/gi, "ensure"],
|
|
60
|
+
[/\bthe reason is because\b/gi, "because"],
|
|
61
|
+
[/\bat this point in time\b/gi, "now"],
|
|
62
|
+
[/\bprior to\b/gi, "before"],
|
|
63
|
+
];
|
|
64
|
+
const ABBREVIATIONS = [
|
|
65
|
+
[/\bdatabase\b/gi, "DB"],
|
|
66
|
+
[/\bauthentication\b/gi, "auth"],
|
|
67
|
+
[/\bconfiguration\b/gi, "config"],
|
|
68
|
+
[/\brequest\b/gi, "req"],
|
|
69
|
+
[/\bresponse\b/gi, "res"],
|
|
70
|
+
[/\bfunction\b/gi, "fn"],
|
|
71
|
+
[/\bimplementation\b/gi, "impl"],
|
|
72
|
+
[/\benvironment\b/gi, "env"],
|
|
73
|
+
[/\berror\b/gi, "err"],
|
|
74
|
+
];
|
|
75
|
+
function wordListRegex(words) {
|
|
76
|
+
const escaped = words.map((w) => w.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
|
|
77
|
+
return new RegExp(`\\b(?:${escaped.join("|")})\\b`, "gi");
|
|
78
|
+
}
|
|
79
|
+
function phraseRegex(phrases) {
|
|
80
|
+
const escaped = phrases.map((p) => p.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
|
|
81
|
+
return new RegExp(`(?:${escaped.join("|")})`, "gi");
|
|
82
|
+
}
|
|
83
|
+
function collapseWhitespace(s) {
|
|
84
|
+
return s
|
|
85
|
+
.replace(/[ \t]+/g, " ")
|
|
86
|
+
.replace(/ +([.,;:!?])/g, "$1")
|
|
87
|
+
.trim();
|
|
88
|
+
}
|
|
89
|
+
export function applyLevelLexical(input, level) {
|
|
90
|
+
let out = input;
|
|
91
|
+
out = out.replace(phraseRegex(HEDGING_PHRASES), "");
|
|
92
|
+
out = out.replace(phraseRegex(PLEASANTRIES), "");
|
|
93
|
+
out = out.replace(wordListRegex(FILLERS), "");
|
|
94
|
+
if (level === "lite")
|
|
95
|
+
return collapseWhitespace(out);
|
|
96
|
+
out = out.replace(ARTICLES, "");
|
|
97
|
+
out = out.replace(wordListRegex(CONNECTIVES), "");
|
|
98
|
+
for (const [pat, rep] of SUBSTITUTIONS) {
|
|
99
|
+
out = out.replace(pat, rep);
|
|
100
|
+
}
|
|
101
|
+
if (level === "standard")
|
|
102
|
+
return collapseWhitespace(out);
|
|
103
|
+
for (const [pat, rep] of ABBREVIATIONS) {
|
|
104
|
+
out = out.replace(pat, rep);
|
|
105
|
+
}
|
|
106
|
+
if (level === "ultra")
|
|
107
|
+
return collapseWhitespace(out);
|
|
108
|
+
return collapseWhitespace(out);
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=level-rules.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"level-rules.js","sourceRoot":"","sources":["../../src/services/level-rules.ts"],"names":[],"mappings":"AAOA,MAAM,kBAAkB,GAAa;IACpC,iBAAiB;IACjB,YAAY;IACZ,mBAAmB;IACnB,gBAAgB;IAChB,4CAA4C;IAC5C,gFAAgF;CAChF,CAAC;AAEF,MAAM,UAAU,kBAAkB,CAAC,KAAa;IAC/C,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,IAAI,MAAM,GAAG,KAAK,CAAC;IACnB,KAAK,MAAM,OAAO,IAAI,kBAAkB,EAAE,CAAC;QAC1C,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;YAC1C,MAAM,KAAK,GAAG,SAAS,MAAM,CAAC,MAAM,GAAG,CAAC;YACxC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACnB,OAAO,KAAK,CAAC;QACd,CAAC,CAAC,CAAC;IACJ,CAAC;IACD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;AAC3B,CAAC;AAED,MAAM,UAAU,oB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