@controlflow-ai/daemon 0.1.1 → 0.1.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.
Files changed (65) hide show
  1. package/README.md +66 -24
  2. package/package.json +16 -3
  3. package/src/agent-avatar.ts +30 -0
  4. package/src/agent-key.ts +28 -0
  5. package/src/agent-permissions.ts +359 -0
  6. package/src/agent-runtime.ts +810 -28
  7. package/src/agent-workspace.ts +183 -0
  8. package/src/app.ts +2183 -79
  9. package/src/args.ts +54 -7
  10. package/src/cli.ts +873 -14
  11. package/src/client.ts +482 -12
  12. package/src/coco.ts +9 -40
  13. package/src/codex.ts +33 -5
  14. package/src/config.ts +28 -4
  15. package/src/console.ts +460 -26
  16. package/src/daemon-client.ts +116 -3
  17. package/src/daemon.ts +958 -101
  18. package/src/db.ts +3216 -113
  19. package/src/delivery-ws.ts +269 -0
  20. package/src/format.ts +4 -1
  21. package/src/lark/app-registration.ts +141 -0
  22. package/src/lark/cli.ts +7 -137
  23. package/src/lark/credentials.ts +36 -3
  24. package/src/lark/event-router.ts +61 -5
  25. package/src/lark/inbound-events.ts +156 -3
  26. package/src/lark/server-integration.ts +659 -111
  27. package/src/lark/setup.ts +74 -5
  28. package/src/lark/ws-daemon.ts +136 -10
  29. package/src/local-api.ts +611 -14
  30. package/src/local-auth.ts +36 -3
  31. package/src/message-attachments.ts +71 -0
  32. package/src/messaging-cli.ts +741 -0
  33. package/src/messaging-status.ts +669 -0
  34. package/src/migrations/023_projects.ts +65 -0
  35. package/src/migrations/024_agents_model.ts +10 -0
  36. package/src/migrations/025_room_archive.ts +44 -0
  37. package/src/migrations/026_project_archive.ts +44 -0
  38. package/src/migrations/027_agent_permission_profiles.ts +16 -0
  39. package/src/migrations/028_lark_websocket_restart_state.ts +16 -0
  40. package/src/migrations/029_held_message_drafts.ts +32 -0
  41. package/src/migrations/030_agent_room_read_state.ts +25 -0
  42. package/src/migrations/031_room_tasks.ts +29 -0
  43. package/src/migrations/032_room_reminders.ts +29 -0
  44. package/src/migrations/033_room_saved_messages.ts +25 -0
  45. package/src/migrations/034_agent_activity_events.ts +27 -0
  46. package/src/migrations/035_agent_avatars.ts +17 -0
  47. package/src/migrations/036_project_agent_defaults.ts +21 -0
  48. package/src/migrations/037_message_attachments.ts +36 -0
  49. package/src/migrations/038_agent_activity_room_scope.ts +64 -0
  50. package/src/migrations/039_message_attachments_path.ts +34 -0
  51. package/src/migrations/040_message_attachments_file_schema.ts +80 -0
  52. package/src/migrations/041_room_system_events.ts +30 -0
  53. package/src/migrations/042_message_attachment_file_kind.ts +52 -0
  54. package/src/migrations/043_room_mode_skill_registry.ts +92 -0
  55. package/src/migrations/044_workflow_runtime.ts +69 -0
  56. package/src/migrations/045_skill_repository_ownership.ts +64 -0
  57. package/src/migrations.ts +70 -1
  58. package/src/neeko.ts +40 -4
  59. package/src/runtime-env.ts +179 -0
  60. package/src/runtime-registry.ts +83 -13
  61. package/src/server.ts +244 -4
  62. package/src/token-file.ts +13 -6
  63. package/src/types.ts +394 -0
  64. package/src/workflow-runtime.ts +275 -0
  65. package/src/web.ts +0 -904
package/src/codex.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { buildPalPrompt, runtimeCwd, type AgentRuntime, type AgentRuntimeRunInput } from './agent-runtime.js';
1
+ import { buildPalPrompt, runtimeLaunchRoot, runtimeCwd, type AgentRuntime, type AgentRuntimeRunInput } from './agent-runtime.js';
2
+ import { buildCodexPermissionArgs, buildRuntimeLaunchContext, effectivePermissionProfile, normalizeWritableRoot, writableRootsForProfile, type AgentPermissionProfile, type RuntimeLaunchContext } from './agent-permissions.js';
2
3
  export { runAgentRuntime } from './agent-runtime.js';
3
4
 
4
5
  function extractThreadId(stdout: string): string | null {
@@ -17,19 +18,46 @@ function extractThreadId(stdout: string): string | null {
17
18
  return null;
18
19
  }
19
20
 
20
- export function makeCodexRuntime(_agentUuid: string): AgentRuntime {
21
+ function tomlString(value: string): string {
22
+ return JSON.stringify(value);
23
+ }
24
+
25
+ function codexResumeConfigArgs(profile: AgentPermissionProfile, context: RuntimeLaunchContext): string[] {
26
+ if (profile.filesystemMode === 'full-access') {
27
+ return ['-c', 'sandbox_mode="danger-full-access"'];
28
+ }
29
+
30
+ const writableRoots = writableRootsForProfile(profile, context)
31
+ .filter((root) => normalizeWritableRoot(root) !== normalizeWritableRoot(context.runtimeRoot));
32
+ const args = [
33
+ '-c',
34
+ 'sandbox_mode="workspace-write"',
35
+ '-c',
36
+ 'sandbox_workspace_write.network_access=true',
37
+ ];
38
+ if (writableRoots.length > 0) {
39
+ args.push('-c', `sandbox_workspace_write.writable_roots=[${writableRoots.map(tomlString).join(',')}]`);
40
+ }
41
+ return args;
42
+ }
43
+
44
+ export function makeCodexRuntime(_agentUuid: string, model?: string | null): AgentRuntime {
45
+ const modelArgs = model?.trim() ? ['--model', model.trim()] : [];
21
46
  return {
22
47
  name: 'codex',
23
- capabilities: { protocol: 'json-stream', resume: 'runtime-session-id', busyDeliveryMode: 'queue', supportsMcp: false },
48
+ capabilities: { protocol: 'json-stream', resume: 'runtime-session-id', busyDeliveryMode: 'queue', supportsMcp: false, supportsSteer: false },
24
49
  command: 'codex',
25
50
  buildPrompt: buildPalPrompt,
26
51
  buildCwd: runtimeCwd,
27
52
  buildArgs(input: AgentRuntimeRunInput): string[] {
28
53
  const prompt = buildPalPrompt(input);
54
+ const context = input.launchContext ?? buildRuntimeLaunchContext(input);
55
+ const permissionProfile = effectivePermissionProfile(input);
56
+ const permissionArgs = buildCodexPermissionArgs(permissionProfile, context);
29
57
  if (input.runtimeSessionId) {
30
- return ['exec', 'resume', '--json', '--dangerously-bypass-approvals-and-sandbox', ...input.extraArgs, input.runtimeSessionId, prompt];
58
+ return ['exec', 'resume', '--json', '--skip-git-repo-check', ...codexResumeConfigArgs(permissionProfile, context), ...modelArgs, ...input.extraArgs, input.runtimeSessionId, prompt];
31
59
  }
32
- return ['exec', '--json', '--dangerously-bypass-approvals-and-sandbox', '--cd', runtimeCwd(input), ...input.extraArgs, prompt];
60
+ return ['exec', '--json', ...permissionArgs, '--skip-git-repo-check', '--cd', runtimeLaunchRoot(input), ...modelArgs, ...input.extraArgs, prompt];
33
61
  },
34
62
  parseOutput({ stdout, stderr, input }) {
35
63
  return {
package/src/config.ts CHANGED
@@ -96,11 +96,35 @@ export function privatePalCliBinDir(): string {
96
96
  return join(homeDir(), 'bin');
97
97
  }
98
98
 
99
- export function ensurePrivatePalCliBin(): string {
99
+ export interface EnsurePrivatePalCliBinOptions {
100
+ platform?: NodeJS.Platform;
101
+ }
102
+
103
+ function cmdQuoted(path: string): string {
104
+ return `"${path.replace(/"/g, '""')}"`;
105
+ }
106
+
107
+ function psQuoted(path: string): string {
108
+ return `'${path.replace(/'/g, "''")}'`;
109
+ }
110
+
111
+ export function privatePalCliExecutableName(platform: NodeJS.Platform = process.platform): string {
112
+ return platform === 'win32' ? 'pal.cmd' : 'pal';
113
+ }
114
+
115
+ export function ensurePrivatePalCliBin(options: EnsurePrivatePalCliBinOptions = {}): string {
116
+ const platform = options.platform ?? process.platform;
100
117
  const binDir = privatePalCliBinDir();
101
118
  ensureDir(binDir);
102
- const linkPath = join(binDir, 'pal');
103
- rmSync(linkPath, { force: true });
104
- symlinkSync(repoCliPath(), linkPath);
119
+ const cliPath = repoCliPath();
120
+ for (const name of ['pal', 'pal.cmd', 'pal.ps1']) {
121
+ rmSync(join(binDir, name), { force: true });
122
+ }
123
+ if (platform === 'win32') {
124
+ writeFileSync(join(binDir, 'pal.cmd'), `@echo off\r\nbun ${cmdQuoted(cliPath)} %*\r\n`);
125
+ writeFileSync(join(binDir, 'pal.ps1'), `& bun ${psQuoted(cliPath)} @args\r\n`);
126
+ } else {
127
+ symlinkSync(cliPath, join(binDir, 'pal'));
128
+ }
105
129
  return binDir;
106
130
  }