pi-gsd 1.9.2 → 1.11.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.
@@ -81,6 +81,53 @@ const syncReferenceToCore = (cwd: string, ref: string[]): void => {
81
81
  };
82
82
 
83
83
  export default function (pi: ExtensionAPI) {
84
+ // ── before_agent_start: inject @file contents into the prompt ────────────
85
+ // Replaces @.pi/gsd/... references with actual file contents so the LLM
86
+ // gets the full context in the first message. No tool calls, no token
87
+ // waste, provider-agnostic.
88
+ pi.on("before_agent_start", async (event, ctx) => {
89
+ const prompt = event.prompt;
90
+ if (!prompt) return undefined;
91
+
92
+ // Match @.pi/gsd/... and @.planning/... file references
93
+ const fileRefPattern = /@(\.pi\/gsd\/[^\s]+|\.planning\/[^\s]+)/g;
94
+ const refs = [...prompt.matchAll(fileRefPattern)];
95
+ if (refs.length === 0) return undefined;
96
+
97
+ const injected: string[] = [];
98
+ const failed: string[] = [];
99
+ for (const match of refs) {
100
+ const relPath = match[1];
101
+ const absPath = join(ctx.cwd, relPath);
102
+ try {
103
+ if (existsSync(absPath)) {
104
+ const content = readFileSync(absPath, "utf8");
105
+ injected.push(`<!-- @${relPath} -->\n${content}\n<!-- /@${relPath} -->`);
106
+ } else {
107
+ failed.push(relPath);
108
+ }
109
+ } catch {
110
+ failed.push(relPath);
111
+ }
112
+ }
113
+
114
+ if (failed.length > 0) {
115
+ ctx.ui.notify(
116
+ `❌ GSD context injection failed — missing files:\n${failed.map((f) => ` • ${f}`).join("\n")}\n\nCheck that .pi/gsd/ symlink exists and points to the harness.`,
117
+ "error",
118
+ );
119
+ return { abort: true };
120
+ }
121
+
122
+ return {
123
+ message: {
124
+ customType: "pi-gsd-context",
125
+ content: injected.join("\n\n"),
126
+ display: false,
127
+ },
128
+ };
129
+ });
130
+
84
131
  // ── session_start: GSD update check ──────────────────────────────────────
85
132
  pi.on("session_start", async (_event, ctx) => {
86
133
  // Ensure harness files are reachable via .pi/gsd/ symlink