@zhushanwen/pi-system-prompt 1.1.5 → 1.1.6
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/package.json +3 -3
- package/src/__tests__/system-prompt.test.ts +5 -5
- package/src/index.ts +11 -11
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zhushanwen/pi-system-prompt",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.6",
|
|
4
4
|
"description": "System prompt injection extension for Pi — reads config and appends to system prompt",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.ts",
|
|
7
|
-
"
|
|
7
|
+
"taiji": {
|
|
8
8
|
"role": "taiji"
|
|
9
9
|
},
|
|
10
10
|
"pi": {
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"vitest": "^4.1.8"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@zhushanwen/pi-extension-logger": "0.
|
|
35
|
+
"@zhushanwen/pi-extension-logger": "0.6.1"
|
|
36
36
|
},
|
|
37
37
|
"scripts": {
|
|
38
38
|
"typecheck": "npx tsc --noEmit",
|
|
@@ -36,8 +36,8 @@ vi.mock('node:fs', () => ({
|
|
|
36
36
|
statSync: vi.fn(),
|
|
37
37
|
}))
|
|
38
38
|
|
|
39
|
-
const DATA_DIR = '/
|
|
40
|
-
const GLOBAL_DIR = '/
|
|
39
|
+
const DATA_DIR = '/taiji-test/data'
|
|
40
|
+
const GLOBAL_DIR = '/taiji-test/global-agents'
|
|
41
41
|
const CONFIG_PATH = path.join(DATA_DIR, 'system-prompt.json')
|
|
42
42
|
|
|
43
43
|
/** hook 注册表桩(参照 msg-id-mapper harness 模式) */
|
|
@@ -114,15 +114,15 @@ function setupFs(setup: FsSetup = {}): void {
|
|
|
114
114
|
})
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
-
const ENV_KEYS = ['
|
|
117
|
+
const ENV_KEYS = ['TAIJI_AGENT_DATA_DIR', 'TAIJI_GLOBAL_AGENTS_DIR', 'PI_CODING_AGENT_DIR'] as const
|
|
118
118
|
const savedEnv: Record<string, string | undefined> = {}
|
|
119
119
|
const savedArgv = process.argv
|
|
120
120
|
|
|
121
121
|
beforeEach(() => {
|
|
122
122
|
vi.clearAllMocks() // 清跨用例的 fs mock 调用记录(「守卫不触发」类断言依赖零计数)
|
|
123
123
|
for (const k of ENV_KEYS) savedEnv[k] = process.env[k]
|
|
124
|
-
process.env.
|
|
125
|
-
process.env.
|
|
124
|
+
process.env.TAIJI_AGENT_DATA_DIR = DATA_DIR
|
|
125
|
+
process.env.TAIJI_GLOBAL_AGENTS_DIR = GLOBAL_DIR
|
|
126
126
|
delete process.env.PI_CODING_AGENT_DIR
|
|
127
127
|
setupFs()
|
|
128
128
|
})
|
package/src/index.ts
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* targets the global agents directory and never picks up override files.
|
|
15
15
|
* Opt-in by file existence: no file → no injection. Skipped when
|
|
16
16
|
* pi was spawned with `--no-context-files` (consistent with pi's native
|
|
17
|
-
* context-file opt-out). `
|
|
17
|
+
* context-file opt-out). `TAIJI_GLOBAL_AGENTS_DIR` overrides the global
|
|
18
18
|
* directory (test hook / escape hatch).
|
|
19
19
|
*
|
|
20
20
|
* Injection order per turn: base prompt → global instructions → append config
|
|
@@ -30,7 +30,7 @@ import { readFileSync, readdirSync, statSync } from 'node:fs'
|
|
|
30
30
|
import type { ExtensionAPI, BeforeAgentStartEvent } from '@earendil-works/pi-coding-agent'
|
|
31
31
|
import { getLogger } from '@zhushanwen/pi-extension-logger'
|
|
32
32
|
|
|
33
|
-
const logger = getLogger('
|
|
33
|
+
const logger = getLogger('taiji-system-prompt-extension')
|
|
34
34
|
|
|
35
35
|
const CONFIG_FILE = 'system-prompt.json'
|
|
36
36
|
|
|
@@ -72,7 +72,7 @@ const GLOBAL_AGENTS_CANDIDATES = ['AGENTS.md', 'AGENTS.MD', 'CLAUDE.md', 'CLAUDE
|
|
|
72
72
|
* Resolve the data directory from the environment.
|
|
73
73
|
*
|
|
74
74
|
* Priority:
|
|
75
|
-
* 1. `process.env.
|
|
75
|
+
* 1. `process.env.TAIJI_AGENT_DATA_DIR` (explicit)
|
|
76
76
|
* 2. `path.resolve(process.env.PI_CODING_AGENT_DIR ?? '', '..')`
|
|
77
77
|
* (PI_CODING_AGENT_DIR == <dataDir>/agent, one level up == dataDir)
|
|
78
78
|
*
|
|
@@ -80,7 +80,7 @@ const GLOBAL_AGENTS_CANDIDATES = ['AGENTS.md', 'AGENTS.MD', 'CLAUDE.md', 'CLAUDE
|
|
|
80
80
|
* layout shape is handled — one level up. An OLD-layout value
|
|
81
81
|
* (`<dataDir>/pi/agent`, pre-migration) would resolve to `<dataDir>/pi`,
|
|
82
82
|
* accepted here on purpose: in every shipped scenario the runtime injects
|
|
83
|
-
*
|
|
83
|
+
* TAIJI_AGENT_DATA_DIR (priority 1 covers it), so priority 2 only serves
|
|
84
84
|
* standalone hosts already on the new layout. session-reader's
|
|
85
85
|
* discovery/env.ts strips both shapes for its diagnostics; this resolver
|
|
86
86
|
* deliberately stays single-shape (registered divergence, not a bug).
|
|
@@ -89,8 +89,8 @@ const GLOBAL_AGENTS_CANDIDATES = ['AGENTS.md', 'AGENTS.MD', 'CLAUDE.md', 'CLAUDE
|
|
|
89
89
|
* take effect without reloading the extension.
|
|
90
90
|
*/
|
|
91
91
|
function resolveDataDir(): string {
|
|
92
|
-
if (process.env.
|
|
93
|
-
return process.env.
|
|
92
|
+
if (process.env.TAIJI_AGENT_DATA_DIR) {
|
|
93
|
+
return process.env.TAIJI_AGENT_DATA_DIR
|
|
94
94
|
}
|
|
95
95
|
return path.resolve(process.env.PI_CODING_AGENT_DIR ?? '', '..')
|
|
96
96
|
}
|
|
@@ -99,15 +99,15 @@ function resolveDataDir(): string {
|
|
|
99
99
|
* Resolve the global agents directory.
|
|
100
100
|
*
|
|
101
101
|
* Priority:
|
|
102
|
-
* 1. `process.env.
|
|
102
|
+
* 1. `process.env.TAIJI_GLOBAL_AGENTS_DIR` (explicit override; tests / escape
|
|
103
103
|
* hatch)
|
|
104
104
|
* 2. `~/.agents` (the user-global agents dir that also hosts skills/templates)
|
|
105
105
|
*
|
|
106
106
|
* Re-read on every handler invocation so env changes take effect.
|
|
107
107
|
*/
|
|
108
108
|
function resolveGlobalAgentsDir(): string {
|
|
109
|
-
if (process.env.
|
|
110
|
-
return process.env.
|
|
109
|
+
if (process.env.TAIJI_GLOBAL_AGENTS_DIR) {
|
|
110
|
+
return process.env.TAIJI_GLOBAL_AGENTS_DIR
|
|
111
111
|
}
|
|
112
112
|
return path.join(homedir(), '.agents')
|
|
113
113
|
}
|
|
@@ -242,7 +242,7 @@ function buildSystemPrompt(event: BeforeAgentStartEvent): { systemPrompt: string
|
|
|
242
242
|
* 落盘诊断,不泄露配置内容。
|
|
243
243
|
*
|
|
244
244
|
* 通道:extension-logger 的 error → appendEntry 写入 session JSONL(需 setPiHandle
|
|
245
|
-
* 注入 pi handle 后生效);
|
|
245
|
+
* 注入 pi handle 后生效);TAIJI_AGENT_DEBUG=1 时另落文件日志。仅当 logger 自身抛错
|
|
246
246
|
* 时才兜底 process.stderr.write(下方 catch),不外泄到 agent loop。
|
|
247
247
|
*/
|
|
248
248
|
function logHookFailure(err: unknown): void {
|
|
@@ -252,7 +252,7 @@ function logHookFailure(err: unknown): void {
|
|
|
252
252
|
} catch (nestedErr) {
|
|
253
253
|
// best-effort:logger 抛错时的终极兜底 process.stderr.write——其内部吞错不会抛,仍不外泄到 agent loop。
|
|
254
254
|
try {
|
|
255
|
-
process.stderr.write(`[
|
|
255
|
+
process.stderr.write(`[taiji-system-prompt-extension] logHookFailure also failed: ${String(nestedErr)}\n`)
|
|
256
256
|
} catch (finalErr) {
|
|
257
257
|
/* 完全静默:两层兜底都失败时无处可写 */
|
|
258
258
|
void finalErr
|