pi-repl-py 0.4.0 → 0.5.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/index.ts +3 -0
- package/package.json +1 -1
- package/src/extension/prompt.ts +30 -20
package/index.ts
CHANGED
|
@@ -151,6 +151,9 @@ export default function (pi: ExtensionAPI) {
|
|
|
151
151
|
throw new Error("pi-repl is dormant in this session. Start pi with --repl (or PI_REPL_FORCE=1) to use execute.");
|
|
152
152
|
}
|
|
153
153
|
if (ctx?.cwd) location = { cwd: ctx.cwd, sessionFile: ctx.sessionManager?.getSessionFile?.() ?? undefined };
|
|
154
|
+
// --- establish the body slot at call time so Ctrl+O can expand a live (still-awaiting) stream;
|
|
155
|
+
// --- without this the host only renders the result once the first partial or the final result lands ---
|
|
156
|
+
onUpdate?.({ content: [], details: {} });
|
|
154
157
|
// --- previous engine died mid-session; acquire revives it ---
|
|
155
158
|
const { engine: m } = await lifecycle.acquire("cell");
|
|
156
159
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-repl-py",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A pi extension with a single tool: execute, running a TypeScript host with a persistent Python (ipykernel) evaluator and a user-configurable toolbox of functions.",
|
|
6
6
|
"keywords": [
|
package/src/extension/prompt.ts
CHANGED
|
@@ -6,14 +6,13 @@
|
|
|
6
6
|
// more signal; the machine reads every line every turn.
|
|
7
7
|
|
|
8
8
|
export const executeToolDescription =
|
|
9
|
-
"Execute Python cells in a persistent ipython kernel that stays alive across cells and turns
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"full-file dumps and raw result lists bloat the conversation.";
|
|
9
|
+
"Execute Python cells in a persistent ipython kernel that stays alive across cells and turns, replacing " +
|
|
10
|
+
"the default read, bash, edit, write, and search tools. Everything you define (variables, imports, and " +
|
|
11
|
+
"helpers preloaded into the workspace namespace) survives for reuse in later cells. A cell returns its " +
|
|
12
|
+
"final expression — bare final expressions are auto-printed, and output is trimmed at 1,000,000 " +
|
|
13
|
+
"characters per cell / 4,096 per line. Treat these as facts about how the workspace reports, not as " +
|
|
14
|
+
"limits to test: assign the values you want to keep so they stay in scope for later cells, and let a " +
|
|
15
|
+
"cell's return value be the proof of its work rather than re-stating that work in prose.";
|
|
17
16
|
|
|
18
17
|
export const executePromptSnippet =
|
|
19
18
|
"Execute Python cells in a persistent ipython kernel (replaces read, bash, edit, write, and search; state survives across cells and turns)";
|
|
@@ -22,29 +21,40 @@ export const executePromptSnippet =
|
|
|
22
21
|
export function buildPromptGuidelines(preloaded: string[]): string[] {
|
|
23
22
|
return [
|
|
24
23
|
"## Your only workspace",
|
|
25
|
-
"`execute` is the only callable
|
|
24
|
+
"`execute` is your workspace: a persistent Python session that is the only callable surface. What you define — variables, functions, data — survives across cells and turns, and the work is proven by the results each cell returns.",
|
|
26
25
|
"",
|
|
27
|
-
"##
|
|
28
|
-
"
|
|
26
|
+
"## Go deep in the cell; prove it by the result",
|
|
27
|
+
"Depth, the cell, not the transcript. Do the heavy reasoning in variables and filters; a cell's worth is shown by what it returns as a result, not by restating that result in prose. Every printed value enters the context — and equating length with value is the trap — so let the code's result, not a recap paragraph, be the evidence.",
|
|
28
|
+
"",
|
|
29
|
+
"## The gather-filter-advance shape",
|
|
30
|
+
"Leave raw data in the workspace. Search results, reads, command output, file contents — whatever you fetch — land in variables, never in the transcript.",
|
|
31
|
+
"",
|
|
32
|
+
"1. **Gather.** One cell assigns the whole: result = search(q), doc = load(path), out = run(...) — nothing printed, ends on the assignment.",
|
|
33
|
+
"2. **Advance.** The next cell prints only the fragment that decides the next step — titles only, a slice of content — and you pick from that sliver.",
|
|
34
|
+
"3. **Peel, don't re-fetch.** You already hold the whole; walk into the pieces you need without re-running it.",
|
|
35
|
+
"4. **Emit, then drop.** When the reasoning lands, print the conclusion; the rest stays in the variable, or is overwritten when done.",
|
|
36
|
+
"",
|
|
37
|
+
"Each printed value is the one that changes the next cell; the transcript stays thin, the work dense in variables.",
|
|
38
|
+
"",
|
|
39
|
+
"Windows, not bans: reading something whole is fine when the task genuinely needs all of it — do that, then keep reasoning on it. The point is not to never read fully; it is to read by window by default and hold the whole, so you never re-fetch the same big thing twice.",
|
|
29
40
|
"",
|
|
30
41
|
"## A cell is a small program",
|
|
31
|
-
"Compose filesystem
|
|
42
|
+
"Compose whatever the step needs — filesystem, shell, search, transforms — in one cell, and end it on the return value the next step consumes. The cell itself (what ran) carries the meaning; the transcript carries only that returned value.",
|
|
43
|
+
"",
|
|
44
|
+
"Name what recurs: when the same operation shows up twice, give it a name once — a function in the namespace — and call it. A defined function is work already proven; every call is a new return-value result, and you never re-print the steps that made it.",
|
|
32
45
|
"",
|
|
33
46
|
"## Revise on observations",
|
|
34
47
|
"Revise prior actions or emit new actions upon new observations.", // CodeAct core
|
|
35
48
|
"",
|
|
36
49
|
"## Probe, then build",
|
|
37
|
-
"Inspect
|
|
50
|
+
"Inspect where you are — a small slice — before committing; then build one step and let its returned result name the next. The proof of each step is the cell's result, not a summary of it.",
|
|
38
51
|
"",
|
|
39
52
|
"## File and search work",
|
|
40
|
-
"Prefer a surgical old-text/new-text replacement over rewriting a file: read the region first,
|
|
53
|
+
"Prefer a surgical old-text/new-text replacement over rewriting a file: read the region first, fix an exact unique anchor that appears once, replace exactly, then verify. Prefer many small verified edits over one big blind rewrite — a parse error mid-way can strand an anchor. Use complete writes only for new files or intentional full rewrites. After an edit errors or writes a partial result, read the file back from disk before reasoning about it. When walking directories, prune generated dirs and never print a raw tree.",
|
|
41
54
|
"",
|
|
42
55
|
"## Repository discipline",
|
|
43
56
|
"Make the smallest valid change, preserve conventions, verify afterward, and never invent files, APIs, conventions, or test results.",
|
|
44
57
|
"",
|
|
45
|
-
"## Context is expensive",
|
|
46
|
-
"Every printed value enters the conversation. Explore and filter in variables; print only the small, bounded slice for the next decision. Never dump a whole file, a raw result list, or an unbounded output, and never rely on truncation to control it.",
|
|
47
|
-
"",
|
|
48
58
|
...(preloaded.length
|
|
49
59
|
? [
|
|
50
60
|
"## Helpers",
|
|
@@ -55,12 +65,12 @@ export function buildPromptGuidelines(preloaded: string[]): string[] {
|
|
|
55
65
|
]
|
|
56
66
|
: []),
|
|
57
67
|
"## Shell and search",
|
|
58
|
-
"Always pass a `timeout` to `subprocess.run(...)` — a silent cell must die, not hang.
|
|
68
|
+
"Always pass a `timeout` to `subprocess.run(...)` — a silent cell must die, not hang. Capture the result in a variable and read a slice, not dump the whole stdout into the transcript: use `rg`/`grep`/`find` for deep searches, not Python loops.",
|
|
59
69
|
"",
|
|
60
70
|
"## Environment & rescue",
|
|
61
71
|
"The evaluator runs in a project-local venv, not the system Python. Do not install a project's dependencies into the evaluator; run external projects through their own interface. If output begins with `<repl_engine_reset>`, the kernel was rebuilt — re-verify any revived variable before reusing it.",
|
|
62
72
|
"",
|
|
63
|
-
"##
|
|
64
|
-
"
|
|
73
|
+
"## The operating principle above the manual",
|
|
74
|
+
"The rules above are working forms of one principle: the work happens in the workspace — in cells and their results — and the transcript carries only what decides or concludes. When a case isn't spelled out, apply the principle over the example: wherever the work can live in the workspace instead of the transcript, keep it there, and let the returned result be the proof. The result is the certificate; the rest of the work stays out of the reply.",
|
|
65
75
|
];
|
|
66
76
|
}
|