@agentlogs/pi 0.0.1 → 0.0.3

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 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 z=W(b,j,{cwd:M,stdio:["pipe","pipe","pipe"]}),B="",K="";z.stdout.on("data",(A)=>{B+=A.toString()}),z.stderr.on("data",(A)=>{K+=A.toString()}),z.stdin.write(JSON.stringify(J)),z.stdin.end(),z.on("close",(A)=>{if(D("Hook process exited",{code:A,stdout:B.slice(0,500),stderr:K.slice(0,500)}),A===0&&B.trim())try{let U=JSON.parse(B.trim());q(U)}catch{q({modified:!1})}else q({modified:!1})}),z.on("error",(A)=>{D("Hook spawn error",{error:String(A)}),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;D("tool_call (git commit)",{toolName:b.toolName,toolCallId:b.toolCallId});let z=j.sessionManager.getSessionId(),B=j.sessionManager.getSessionFile(),K=await R({hook_event_name:"tool_call",session_id:z,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)D("tool_call: input modified",{modified:!0}),M.add(b.toolCallId)}),J.on("tool_result",async(b,j)=>{if(b.toolName!=="bash")return;let q=M.has(b.toolCallId),z=b.content?.map((A)=>A.type==="text"?A.text:"").join("").trim()??"",B=z.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:z},cwd:j.cwd},j.cwd).catch((A)=>D("tool_result hook error",{error:String(A)}))});let Q=(b,j)=>{let q=j.sessionManager.getSessionId(),z=j.sessionManager.getSessionFile(),B=j.sessionManager.getLeafId();if(!z){D(`${b}: no session file (ephemeral session)`);return}D(b,{sessionId:q,sessionFile:z,leafId:B}),R({hook_event_name:b,session_id:q,session_file:z,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};
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentlogs/pi",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "AgentLogs extension for Pi - automatically captures and uploads AI coding session transcripts",
5
5
  "keywords": [
6
6
  "agentlogs",
@@ -16,8 +16,7 @@
16
16
  "directory": "packages/pi"
17
17
  },
18
18
  "files": [
19
- "dist",
20
- "src"
19
+ "dist"
21
20
  ],
22
21
  "type": "module",
23
22
  "main": "src/index.ts",
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
- log("tool_call: input modified", { modified: true });
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