@oh-my-pi/pi-coding-agent 14.5.3 → 14.5.5
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 +44 -0
- package/examples/extensions/plan-mode.ts +1 -1
- package/examples/sdk/README.md +1 -1
- package/package.json +7 -7
- package/src/config/prompt-templates.ts +103 -8
- package/src/config/settings-schema.ts +14 -13
- package/src/config/settings.ts +1 -1
- package/src/cursor.ts +4 -4
- package/src/edit/index.ts +111 -109
- package/src/edit/line-hash.ts +33 -3
- package/src/edit/modes/apply-patch.ts +6 -4
- package/src/edit/modes/atom.lark +27 -0
- package/src/edit/modes/atom.ts +1057 -841
- package/src/edit/modes/hashline.ts +9 -10
- package/src/edit/modes/patch.ts +23 -19
- package/src/edit/modes/replace.ts +19 -15
- package/src/edit/renderer.ts +65 -8
- package/src/edit/streaming.ts +47 -77
- package/src/extensibility/extensions/types.ts +11 -11
- package/src/extensibility/hooks/types.ts +6 -6
- package/src/lsp/edits.ts +8 -5
- package/src/lsp/index.ts +4 -4
- package/src/lsp/utils.ts +7 -7
- package/src/mcp/discoverable-tool-metadata.ts +1 -1
- package/src/mcp/manager.ts +3 -3
- package/src/mcp/tool-bridge.ts +4 -4
- package/src/memories/index.ts +1 -1
- package/src/modes/acp/acp-event-mapper.ts +1 -1
- package/src/modes/components/session-observer-overlay.ts +1 -1
- package/src/modes/components/settings-defs.ts +3 -3
- package/src/modes/components/tree-selector.ts +2 -2
- package/src/modes/utils/ui-helpers.ts +31 -7
- package/src/prompts/agents/explore.md +1 -1
- package/src/prompts/agents/librarian.md +2 -2
- package/src/prompts/agents/plan.md +2 -2
- package/src/prompts/agents/reviewer.md +1 -1
- package/src/prompts/agents/task.md +2 -2
- package/src/prompts/system/plan-mode-active.md +1 -1
- package/src/prompts/system/system-prompt.md +34 -31
- package/src/prompts/tools/apply-patch.md +0 -2
- package/src/prompts/tools/atom.md +81 -63
- package/src/prompts/tools/bash.md +7 -4
- package/src/prompts/tools/checkpoint.md +1 -1
- package/src/prompts/tools/find.md +6 -1
- package/src/prompts/tools/hashline.md +10 -11
- package/src/prompts/tools/patch.md +13 -13
- package/src/prompts/tools/read.md +4 -4
- package/src/prompts/tools/replace.md +3 -3
- package/src/prompts/tools/{grep.md → search.md} +4 -4
- package/src/sdk.ts +19 -9
- package/src/session/agent-session.ts +65 -0
- package/src/system-prompt.ts +15 -5
- package/src/task/executor.ts +5 -0
- package/src/task/index.ts +10 -1
- package/src/tools/ast-edit.ts +4 -6
- package/src/tools/ast-grep.ts +4 -6
- package/src/tools/bash.ts +1 -1
- package/src/tools/file-recorder.ts +6 -6
- package/src/tools/find.ts +11 -13
- package/src/tools/index.ts +7 -7
- package/src/tools/path-utils.ts +31 -4
- package/src/tools/read.ts +12 -6
- package/src/tools/renderers.ts +2 -2
- package/src/tools/{grep.ts → search.ts} +32 -40
- package/src/tools/write.ts +8 -4
- package/src/web/search/index.ts +1 -1
- package/src/edit/block.ts +0 -308
- package/src/edit/indent.ts +0 -150
package/src/edit/indent.ts
DELETED
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Indent helpers used by `splice_block`.
|
|
3
|
-
*
|
|
4
|
-
* Pure functions: take strings/lines, return strings/lines. No I/O. Designed
|
|
5
|
-
* to be easy to unit-test in isolation.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
export interface IndentStyle {
|
|
9
|
-
kind: "tab" | "space";
|
|
10
|
-
width: number;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const SAMPLE_LINES_FOR_DETECTION = 256;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Detect whether the file uses tab or space indentation, and the indent width
|
|
17
|
-
* for spaces. Sampling-based; defaults to {kind: "tab", width: 1} when nothing
|
|
18
|
-
* is conclusive.
|
|
19
|
-
*/
|
|
20
|
-
export function detectIndentStyle(text: string): IndentStyle {
|
|
21
|
-
const lines = text.split("\n", SAMPLE_LINES_FOR_DETECTION + 1).slice(0, SAMPLE_LINES_FOR_DETECTION);
|
|
22
|
-
let tabIndented = 0;
|
|
23
|
-
let spaceIndented = 0;
|
|
24
|
-
const spaceWidthCounts = new Map<number, number>();
|
|
25
|
-
for (const line of lines) {
|
|
26
|
-
if (line.length === 0) continue;
|
|
27
|
-
const ch0 = line[0];
|
|
28
|
-
if (ch0 === "\t") {
|
|
29
|
-
tabIndented++;
|
|
30
|
-
continue;
|
|
31
|
-
}
|
|
32
|
-
if (ch0 !== " ") continue;
|
|
33
|
-
let count = 0;
|
|
34
|
-
while (count < line.length && line[count] === " ") count++;
|
|
35
|
-
// Skip lines whose entire content is whitespace (no signal).
|
|
36
|
-
if (count === line.length) continue;
|
|
37
|
-
spaceIndented++;
|
|
38
|
-
// Record indent step. Try common values 2, 4, 8 by GCD-ish.
|
|
39
|
-
spaceWidthCounts.set(count, (spaceWidthCounts.get(count) ?? 0) + 1);
|
|
40
|
-
}
|
|
41
|
-
if (tabIndented > spaceIndented) return { kind: "tab", width: 1 };
|
|
42
|
-
if (spaceIndented === 0) return { kind: "tab", width: 1 };
|
|
43
|
-
|
|
44
|
-
// Pick the most common nonzero indent width that divides the others well.
|
|
45
|
-
const candidates = [2, 4, 8];
|
|
46
|
-
let bestCandidate = 4;
|
|
47
|
-
let bestScore = -1;
|
|
48
|
-
for (const cand of candidates) {
|
|
49
|
-
let score = 0;
|
|
50
|
-
for (const [width, count] of spaceWidthCounts) {
|
|
51
|
-
if (width % cand === 0) score += count;
|
|
52
|
-
}
|
|
53
|
-
if (score > bestScore) {
|
|
54
|
-
bestScore = score;
|
|
55
|
-
bestCandidate = cand;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
return { kind: "space", width: bestCandidate };
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Strip the common leading whitespace prefix from every non-empty line.
|
|
63
|
-
* Blank/whitespace-only lines pass through unchanged.
|
|
64
|
-
*
|
|
65
|
-
* Tab and space whitespace count as a single character each here; we look at
|
|
66
|
-
* raw prefix bytes. The block executor re-applies destination indent later,
|
|
67
|
-
* so tab/space mismatches in the agent's own input are normalized by
|
|
68
|
-
* `applyIndent` rather than here.
|
|
69
|
-
*/
|
|
70
|
-
export function stripCommonIndent(lines: readonly string[]): string[] {
|
|
71
|
-
let common: string | null = null;
|
|
72
|
-
for (const line of lines) {
|
|
73
|
-
if (line.trim().length === 0) continue;
|
|
74
|
-
const m = /^[\t ]*/.exec(line);
|
|
75
|
-
const prefix = m ? m[0] : "";
|
|
76
|
-
if (common === null) {
|
|
77
|
-
common = prefix;
|
|
78
|
-
continue;
|
|
79
|
-
}
|
|
80
|
-
// Reduce to the longest shared prefix.
|
|
81
|
-
let i = 0;
|
|
82
|
-
const limit = Math.min(common.length, prefix.length);
|
|
83
|
-
while (i < limit && common[i] === prefix[i]) i++;
|
|
84
|
-
common = common.slice(0, i);
|
|
85
|
-
if (common.length === 0) break;
|
|
86
|
-
}
|
|
87
|
-
if (!common) return [...lines];
|
|
88
|
-
return lines.map(line => (line.startsWith(common!) ? line.slice(common!.length) : line));
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Re-index leading whitespace of `lines` from the source style to the
|
|
93
|
-
* destination style, then prepend `prefix` to every non-empty line.
|
|
94
|
-
*
|
|
95
|
-
* - Source style is detected from the lines themselves.
|
|
96
|
-
* - Tab→space and space→tab conversion is applied to the *relative*
|
|
97
|
-
* indentation (everything past the common prefix has already been stripped
|
|
98
|
-
* by `stripCommonIndent`, so all leading whitespace here is "extra" indent).
|
|
99
|
-
* - Blank lines stay empty (no trailing whitespace).
|
|
100
|
-
*/
|
|
101
|
-
export function applyIndent(lines: readonly string[], prefix: string, destStyle: IndentStyle): string[] {
|
|
102
|
-
const sourceStyle = detectIndentStyle(lines.join("\n"));
|
|
103
|
-
return lines.map(line => {
|
|
104
|
-
if (line.trim().length === 0) return "";
|
|
105
|
-
const m = /^[\t ]*/.exec(line);
|
|
106
|
-
const leading = m ? m[0] : "";
|
|
107
|
-
const rest = line.slice(leading.length);
|
|
108
|
-
const normalized = normalizeIndent(leading, sourceStyle, destStyle);
|
|
109
|
-
return prefix + normalized + rest;
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
function normalizeIndent(leading: string, source: IndentStyle, dest: IndentStyle): string {
|
|
114
|
-
if (leading.length === 0) return leading;
|
|
115
|
-
// Compute total visual columns of the leading run, treating tabs in the
|
|
116
|
-
// source as `source.width` columns (or 1 column for tab-indented files,
|
|
117
|
-
// where the destination decides the visible width).
|
|
118
|
-
let columns = 0;
|
|
119
|
-
for (const ch of leading) {
|
|
120
|
-
if (ch === "\t") {
|
|
121
|
-
// Treat a source tab as one indent unit. Width = source.width or
|
|
122
|
-
// fallback 4 when source is tab style.
|
|
123
|
-
columns += source.kind === "tab" ? 1 : Math.max(1, Math.floor(source.width));
|
|
124
|
-
} else {
|
|
125
|
-
columns += 1;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
if (dest.kind === "tab") {
|
|
129
|
-
// Convert visual columns to whole tabs. When source was space-indented,
|
|
130
|
-
// columns is in spaces; divide by source.width to get logical levels.
|
|
131
|
-
let levels: number;
|
|
132
|
-
if (source.kind === "tab") {
|
|
133
|
-
levels = columns;
|
|
134
|
-
} else {
|
|
135
|
-
const w = Math.max(1, source.width);
|
|
136
|
-
levels = Math.round(columns / w);
|
|
137
|
-
}
|
|
138
|
-
return "\t".repeat(Math.max(0, levels));
|
|
139
|
-
}
|
|
140
|
-
// Destination is spaces. Convert to dest.width columns per level.
|
|
141
|
-
let levels: number;
|
|
142
|
-
if (source.kind === "tab") {
|
|
143
|
-
levels = columns; // tabs were 1 column each here
|
|
144
|
-
} else {
|
|
145
|
-
const w = Math.max(1, source.width);
|
|
146
|
-
levels = Math.round(columns / w);
|
|
147
|
-
}
|
|
148
|
-
const out = " ".repeat(Math.max(0, levels) * Math.max(1, dest.width));
|
|
149
|
-
return out;
|
|
150
|
-
}
|