@agentlogs/pi 0.0.1 → 0.0.2
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/dist/index.js +1 -1
- package/package.json +1 -1
- package/src/index.ts +12 -5
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{appendFileSync as V}from"node:fs";import{spawn as W}from"node:child_process";var X="/tmp/agentlogs-pi.log";function D(J,M){return}async function R(J,M){let Q=process.env.AGENTLOGS_CLI_PATH,b,j;if(Q){let q=Q.split(" ");b=q[0],j=[...q.slice(1),"pi","hook"]}else b="npx",j=["-y","agentlogs@latest","pi","hook"];return D("Running hook",{command:b,args:j,payload:J.hook_event_name}),new Promise((q)=>{let
|
|
1
|
+
import{appendFileSync as V}from"node:fs";import{spawn as W}from"node:child_process";var X="/tmp/agentlogs-pi.log";function D(J,M){return}async function R(J,M){let Q=process.env.AGENTLOGS_CLI_PATH,b,j;if(Q){let q=Q.split(" ");b=q[0],j=[...q.slice(1),"pi","hook"]}else b="npx",j=["-y","agentlogs@latest","pi","hook"];return D("Running hook",{command:b,args:j,payload:J.hook_event_name}),new Promise((q)=>{let A=W(b,j,{cwd:M,stdio:["pipe","pipe","pipe"]}),B="",K="";A.stdout.on("data",(z)=>{B+=z.toString()}),A.stderr.on("data",(z)=>{K+=z.toString()}),A.stdin.write(JSON.stringify(J)),A.stdin.end(),A.on("close",(z)=>{if(D("Hook process exited",{code:z,stdout:B.slice(0,500),stderr:K.slice(0,500)}),z===0&&B.trim())try{let U=JSON.parse(B.trim());q(U)}catch{q({modified:!1})}else q({modified:!1})}),A.on("error",(z)=>{D("Hook spawn error",{error:String(z)}),q({modified:!1})})})}function Y(J){D("Extension initialized");let M=new Set;J.on("tool_call",async(b,j)=>{if(b.toolName!=="bash")return;let q=b.input?.command;if(typeof q!=="string"||!/\bgit\s+commit\b/.test(q))return;if(q.includes("agentlogs.ai/s/"))return;D("tool_call (git commit)",{toolName:b.toolName,toolCallId:b.toolCallId,originalCommand:q});let A=j.sessionManager.getSessionId(),B=j.sessionManager.getSessionFile(),K=await R({hook_event_name:"tool_call",session_id:A,tool_call_id:b.toolCallId,tool:b.toolName,tool_input:b.input,cwd:j.cwd,session_file:B},j.cwd);if(K.modified&&K.updatedInput){let z=K.updatedInput.command;if(typeof z==="string")b.input.command=z,D("tool_call: mutated input",{updatedCommand:z});M.add(b.toolCallId)}}),J.on("tool_result",async(b,j)=>{if(b.toolName!=="bash")return;let q=M.has(b.toolCallId),A=b.content?.map((z)=>z.type==="text"?z.text:"").join("").trim()??"",B=A.includes("agentlogs.ai/s/");if(!q&&!B)return;M.delete(b.toolCallId),D("tool_result (git commit)",{toolName:b.toolName,toolCallId:b.toolCallId,hasLink:B,wasIntercepted:q});let K=j.sessionManager.getSessionId();R({hook_event_name:"tool_result",session_id:K,tool_call_id:b.toolCallId,tool:b.toolName,tool_output:{content:A},cwd:j.cwd},j.cwd).catch((z)=>D("tool_result hook error",{error:String(z)}))});let Q=(b,j)=>{let q=j.sessionManager.getSessionId(),A=j.sessionManager.getSessionFile(),B=j.sessionManager.getLeafId();if(!A){D(`${b}: no session file (ephemeral session)`);return}D(b,{sessionId:q,sessionFile:A,leafId:B}),R({hook_event_name:b,session_id:q,session_file:A,leaf_id:B??void 0,cwd:j.cwd},j.cwd).catch((K)=>D(`${b} hook error`,{error:String(K)}))};J.on("agent_end",async(b,j)=>{Q("agent_end",j)}),J.on("session_shutdown",async(b,j)=>{Q("session_shutdown",j)})}export{Y as default,Y as agentLogsExtension};
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -180,9 +180,15 @@ export default function agentLogsExtension(pi: ExtensionAPI) {
|
|
|
180
180
|
return;
|
|
181
181
|
}
|
|
182
182
|
|
|
183
|
+
// Skip if already has a transcript link
|
|
184
|
+
if (command.includes("agentlogs.ai/s/")) {
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
|
|
183
188
|
log("tool_call (git commit)", {
|
|
184
189
|
toolName: event.toolName,
|
|
185
190
|
toolCallId: event.toolCallId,
|
|
191
|
+
originalCommand: command,
|
|
186
192
|
});
|
|
187
193
|
|
|
188
194
|
const sessionId = ctx.sessionManager.getSessionId();
|
|
@@ -202,13 +208,14 @@ export default function agentLogsExtension(pi: ExtensionAPI) {
|
|
|
202
208
|
);
|
|
203
209
|
|
|
204
210
|
if (response.modified && response.updatedInput) {
|
|
205
|
-
|
|
211
|
+
const updatedCommand = response.updatedInput.command;
|
|
212
|
+
if (typeof updatedCommand === "string") {
|
|
213
|
+
// Try mutating the input directly
|
|
214
|
+
(event.input as Record<string, unknown>).command = updatedCommand;
|
|
215
|
+
log("tool_call: mutated input", { updatedCommand });
|
|
216
|
+
}
|
|
206
217
|
// Track this tool call ID so we know to process the result
|
|
207
218
|
interceptedToolCallIds.add(event.toolCallId);
|
|
208
|
-
|
|
209
|
-
// Note: Pi doesn't support modifying tool input from extensions
|
|
210
|
-
// The CLI will need to handle this differently (pre-upload the transcript)
|
|
211
|
-
// For now, we just track that we saw this commit
|
|
212
219
|
}
|
|
213
220
|
});
|
|
214
221
|
|