Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

feat: isolate email download path by workspace and agent (#15)

Generb71edfbb4e99
diff --git a/src/cli/commands/email.ts b/src/cli/commands/email.ts
index 2cea8420a..59630b481 100644
--- a/src/cli/commands/email.ts
+++ b/src/cli/commands/email.ts
@@ -26,7 +26,7 @@ interface EmailResponse {
}
const VALID_STATUSES = ["unread", "read", "archived"];
-const EMAIL_DIR = "/tmp/alook-emails";
+const EMAIL_BASE = "/tmp/alook-emails";
const MIME_BY_EXT: Record<string, string> = {
".pdf": "application/pdf",
@@ -101,7 +101,7 @@ export function emailCommand(): Command {
cmd
.command("pull")
- .description("Download and parse emails to /tmp/alook-emails/")
+ .description("Download and parse emails to /tmp/alook-emails/{workspaceId}/{agentId}/")
.requiredOption("--agent_id <id>", "Agent ID")
.option("--status <status>", "Filter by status (unread, read, archived)")
.option("--workspace <id>", "Workspace ID")
@@ -117,6 +117,8 @@ export function emailCommand(): Command {
process.exit(1);
}
+ const emailDir_base = join(EMAIL_BASE, workspaceId, opts.agent_id);
+
try {
let query = `/api/email?agentId=${opts.agent_id}`;
if (opts.status) query += `&status=${opts.status}`;
@@ -133,12 +135,12 @@ export function emailCommand(): Command {
return;
}
- mkdirSync(EMAIL_DIR, { recursive: true });
+ mkdirSync(emailDir_base, { recursive: true });
const downloadedPaths: string[] = [];
for (const email of emails) {
- const emailDir = join(EMAIL_DIR, email.id);
+ const emailDir = join(emailDir_base, email.id);
mkdirSync(emailDir, { recursive: true });
// Write metadata
@@ -215,7 +217,7 @@ export function emailCommand(): Command {
}
console.log(
- `Downloaded ${emails.length} email${emails.length === 1 ? "" : "s"} to ${EMAIL_DIR}/`,
+ `Downloaded ${emails.length} email${emails.length === 1 ? "" : "s"} to ${emailDir_base}/`,
);
for (const p of downloadedPaths) {
console.log(` ${p}`);
diff --git a/src/cli/daemon/execenv/context.test.ts b/src/cli/daemon/execenv/context.test.ts
index 3d62e6c8c..10d9e2e16 100644
--- a/src/cli/daemon/execenv/context.test.ts
+++ b/src/cli/daemon/execenv/context.test.ts
@@ -25,9 +25,9 @@ describe("buildInstructionContent email tool injection", () => {
});
const content = buildInstructionContent(task);
- expect(content).toContain("npx @alook/cli email pull --agent_id agent-123 --status unread");
- expect(content).toContain("npx @alook/cli email set --agent_id agent-123 --email_id <EMAIL_ID> --status read");
- expect(content).toContain("/tmp/alook-emails/");
+ expect(content).toContain("npx @alook/cli email pull --agent_id agent-123 --workspace ws1 --status unread");
+ expect(content).toContain("npx @alook/cli email set --agent_id agent-123 --workspace ws1 --email_id <EMAIL_ID> --status read");
+ expect(content).toContain("/tmp/alook-emails/ws1/agent-123/");
expect(content).toContain("metadata.json");
expect(content).toContain("'[email protected]' (default, Alook platform address)");
});
diff --git a/src/cli/daemon/execenv/context.ts b/src/cli/daemon/execenv/context.ts
index ba91a20ab..1157978f3 100644
--- a/src/cli/daemon/execenv/context.ts
+++ b/src/cli/daemon/execenv/context.ts
@@ -91,30 +91,30 @@ ${task.agent?.userEmail ? `Your owner's email address is '${task.agent.userEmail
### Emails
---
-Run 'npx @alook/cli email pull --agent_id ${task.agentId} --status unread' to download unread emails to '/tmp/alook-emails/'.
-Each email is saved to '/tmp/alook-emails/<emailId>/' with:
+Run 'npx @alook/cli email pull --agent_id ${task.agentId} --workspace ${task.workspaceId} --status unread' to download unread emails to '/tmp/alook-emails/${task.workspaceId}/${task.agentId}/'.
+Each email is saved to '/tmp/alook-emails/${task.workspaceId}/${task.agentId}/<emailId>/' with:
- 'metadata.json' — sender, recipient, subject, date, status, message_id, in_reply_to, references
- 'body.txt' — plain text body
- 'body.html' — HTML body (if available)
- 'attachments/' — extracted attachment files (if any)
---
Before starting to process an email, mark it as read:
-- Run 'npx @alook/cli email set --agent_id ${task.agentId} --email_id <EMAIL_ID> --status read'
+- Run 'npx @alook/cli email set --agent_id ${task.agentId} --workspace ${task.workspaceId} --email_id <EMAIL_ID> --status read'
---
#### Sending a new email
Write the HTML body to a file first, then send it. The body is forwarded as-is (HTML).
-- Run 'npx @alook/cli email send --agent_id ${task.agentId} --to <ADDRESS> --subject "<SUBJECT>" --body-file <PATH_TO_HTML>'
+- Run 'npx @alook/cli email send --agent_id ${task.agentId} --workspace ${task.workspaceId} --to <ADDRESS> --subject "<SUBJECT>" --body-file <PATH_TO_HTML>'
- To send from a specific mailbox, add '--from <YOUR_EMAIL_ADDRESS>'. Without '--from', the default Alook address is used.
- Attach files with '--attachment <PATH>' — repeat the flag for multiple attachments. Each file is uploaded before sending.
-- Example: 'npx @alook/cli email send --agent_id ${task.agentId} --to [email protected] --subject "Weekly report" --body-file /tmp/body.html --from [email protected] --attachment /tmp/report.pdf'
+- Example: 'npx @alook/cli email send --agent_id ${task.agentId} --workspace ${task.workspaceId} --to [email protected] --subject "Weekly report" --body-file /tmp/body.html --from [email protected] --attachment /tmp/report.pdf'
#### Replying to an email
To reply to an email, add '--in-reply-to <EMAIL_ID>' to the send command. This sets the correct email threading headers so the recipient's email client groups the reply into the same conversation thread.
- Use 'Re: <original subject>' as the subject.
- Quote the original email body in your reply (wrap it in a blockquote).
- The <EMAIL_ID> is the Alook email id from metadata.json (not the message_id header).
-- Example: 'npx @alook/cli email send --agent_id ${task.agentId} --to [email protected] --subject "Re: Bug report" --body-file /tmp/reply.html --in-reply-to <EMAIL_ID>'
+- Example: 'npx @alook/cli email send --agent_id ${task.agentId} --workspace ${task.workspaceId} --to [email protected] --subject "Re: Bug report" --body-file /tmp/reply.html --in-reply-to <EMAIL_ID>'
---
`;
}