@zhushanwen/pi-system-prompt 1.1.4 → 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 CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@zhushanwen/pi-system-prompt",
3
- "version": "1.1.4",
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
- "xyz-agent": {
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.4.1"
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 = '/xyz-test/data'
40
- const GLOBAL_DIR = '/xyz-test/global-agents'
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 = ['XYZ_AGENT_DATA_DIR', 'XYZ_GLOBAL_AGENTS_DIR', 'PI_CODING_AGENT_DIR'] as const
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.XYZ_AGENT_DATA_DIR = DATA_DIR
125
- process.env.XYZ_GLOBAL_AGENTS_DIR = GLOBAL_DIR
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). `XYZ_GLOBAL_AGENTS_DIR` overrides the global
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('xyz-system-prompt-extension')
33
+ const logger = getLogger('taiji-system-prompt-extension')
34
34
 
35
35
  const CONFIG_FILE = 'system-prompt.json'
36
36
 
@@ -72,33 +72,42 @@ 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.XYZ_AGENT_DATA_DIR` (explicit)
76
- * 2. `path.resolve(process.env.PI_CODING_AGENT_DIR ?? '', '..', '..')`
77
- * (PI_CODING_AGENT_DIR == <dataDir>/pi/agent, two levels up == dataDir)
75
+ * 1. `process.env.TAIJI_AGENT_DATA_DIR` (explicit)
76
+ * 2. `path.resolve(process.env.PI_CODING_AGENT_DIR ?? '', '..')`
77
+ * (PI_CODING_AGENT_DIR == <dataDir>/agent, one level up == dataDir)
78
+ *
79
+ * Layout trade-off (session-root-discovery plan B, 2026-09): only the NEW
80
+ * layout shape is handled — one level up. An OLD-layout value
81
+ * (`<dataDir>/pi/agent`, pre-migration) would resolve to `<dataDir>/pi`,
82
+ * accepted here on purpose: in every shipped scenario the runtime injects
83
+ * TAIJI_AGENT_DATA_DIR (priority 1 covers it), so priority 2 only serves
84
+ * standalone hosts already on the new layout. session-reader's
85
+ * discovery/env.ts strips both shapes for its diagnostics; this resolver
86
+ * deliberately stays single-shape (registered divergence, not a bug).
78
87
  *
79
88
  * Re-read on every handler invocation so env changes between turns/sessions
80
89
  * take effect without reloading the extension.
81
90
  */
82
91
  function resolveDataDir(): string {
83
- if (process.env.XYZ_AGENT_DATA_DIR) {
84
- return process.env.XYZ_AGENT_DATA_DIR
92
+ if (process.env.TAIJI_AGENT_DATA_DIR) {
93
+ return process.env.TAIJI_AGENT_DATA_DIR
85
94
  }
86
- return path.resolve(process.env.PI_CODING_AGENT_DIR ?? '', '..', '..')
95
+ return path.resolve(process.env.PI_CODING_AGENT_DIR ?? '', '..')
87
96
  }
88
97
 
89
98
  /**
90
99
  * Resolve the global agents directory.
91
100
  *
92
101
  * Priority:
93
- * 1. `process.env.XYZ_GLOBAL_AGENTS_DIR` (explicit override; tests / escape
102
+ * 1. `process.env.TAIJI_GLOBAL_AGENTS_DIR` (explicit override; tests / escape
94
103
  * hatch)
95
104
  * 2. `~/.agents` (the user-global agents dir that also hosts skills/templates)
96
105
  *
97
106
  * Re-read on every handler invocation so env changes take effect.
98
107
  */
99
108
  function resolveGlobalAgentsDir(): string {
100
- if (process.env.XYZ_GLOBAL_AGENTS_DIR) {
101
- return process.env.XYZ_GLOBAL_AGENTS_DIR
109
+ if (process.env.TAIJI_GLOBAL_AGENTS_DIR) {
110
+ return process.env.TAIJI_GLOBAL_AGENTS_DIR
102
111
  }
103
112
  return path.join(homedir(), '.agents')
104
113
  }
@@ -233,7 +242,7 @@ function buildSystemPrompt(event: BeforeAgentStartEvent): { systemPrompt: string
233
242
  * 落盘诊断,不泄露配置内容。
234
243
  *
235
244
  * 通道:extension-logger 的 error → appendEntry 写入 session JSONL(需 setPiHandle
236
- * 注入 pi handle 后生效);XYZ_AGENT_DEBUG=1 时另落文件日志。仅当 logger 自身抛错
245
+ * 注入 pi handle 后生效);TAIJI_AGENT_DEBUG=1 时另落文件日志。仅当 logger 自身抛错
237
246
  * 时才兜底 process.stderr.write(下方 catch),不外泄到 agent loop。
238
247
  */
239
248
  function logHookFailure(err: unknown): void {
@@ -243,7 +252,7 @@ function logHookFailure(err: unknown): void {
243
252
  } catch (nestedErr) {
244
253
  // best-effort:logger 抛错时的终极兜底 process.stderr.write——其内部吞错不会抛,仍不外泄到 agent loop。
245
254
  try {
246
- process.stderr.write(`[xyz-system-prompt-extension] logHookFailure also failed: ${String(nestedErr)}\n`)
255
+ process.stderr.write(`[taiji-system-prompt-extension] logHookFailure also failed: ${String(nestedErr)}\n`)
247
256
  } catch (finalErr) {
248
257
  /* 完全静默:两层兜底都失败时无处可写 */
249
258
  void finalErr