@posthog/agent 2.3.168 → 2.3.171

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.
@@ -0,0 +1,127 @@
1
+ import * as fs from "node:fs";
2
+ import * as os from "node:os";
3
+ import * as path from "node:path";
4
+
5
+ /**
6
+ * Codex settings parsed from ~/.codex/config.toml and project-level config.
7
+ *
8
+ * Mirrors the shape of ClaudeCodeSettings so both adapters have a
9
+ * consistent settings interface.
10
+ */
11
+ export interface CodexSettings {
12
+ model?: string;
13
+ personality?: string;
14
+ modelReasoningEffort?: string;
15
+ trustLevel?: string;
16
+ }
17
+
18
+ /**
19
+ * SettingsManager for Codex sessions.
20
+ *
21
+ * Reads from ~/.codex/config.toml (user-level) and respects
22
+ * per-project trust configuration. Has the same public interface
23
+ * as Claude's SettingsManager so both can satisfy BaseSession.
24
+ */
25
+ export class CodexSettingsManager {
26
+ private cwd: string;
27
+ private settings: CodexSettings = {};
28
+ private initialized = false;
29
+
30
+ constructor(cwd: string) {
31
+ this.cwd = cwd;
32
+ }
33
+
34
+ async initialize(): Promise<void> {
35
+ if (this.initialized) {
36
+ return;
37
+ }
38
+ await this.loadSettings();
39
+ this.initialized = true;
40
+ }
41
+
42
+ private getConfigPath(): string {
43
+ return path.join(os.homedir(), ".codex", "config.toml");
44
+ }
45
+
46
+ private async loadSettings(): Promise<void> {
47
+ const configPath = this.getConfigPath();
48
+ try {
49
+ const content = await fs.promises.readFile(configPath, "utf-8");
50
+ this.settings = parseCodexToml(content, this.cwd);
51
+ } catch {
52
+ this.settings = {};
53
+ }
54
+ }
55
+
56
+ getSettings(): CodexSettings {
57
+ return this.settings;
58
+ }
59
+
60
+ getCwd(): string {
61
+ return this.cwd;
62
+ }
63
+
64
+ async setCwd(cwd: string): Promise<void> {
65
+ if (this.cwd === cwd) {
66
+ return;
67
+ }
68
+ this.dispose();
69
+ this.cwd = cwd;
70
+ this.initialized = false;
71
+ await this.initialize();
72
+ }
73
+
74
+ dispose(): void {
75
+ this.initialized = false;
76
+ }
77
+ }
78
+
79
+ /**
80
+ * Minimal TOML parser for codex config.toml.
81
+ * Handles flat key=value pairs and [projects."path"] sections.
82
+ * Does NOT handle full TOML spec — only what codex config uses.
83
+ */
84
+ function parseCodexToml(content: string, cwd: string): CodexSettings {
85
+ const settings: CodexSettings = {};
86
+ let currentSection = "";
87
+
88
+ for (const line of content.split("\n")) {
89
+ const trimmed = line.trim();
90
+ if (!trimmed || trimmed.startsWith("#")) continue;
91
+
92
+ // Section header: [projects."/some/path"] or [section]
93
+ const sectionMatch = trimmed.match(/^\[(.+)\]$/);
94
+ if (sectionMatch) {
95
+ currentSection = sectionMatch[1] ?? "";
96
+ continue;
97
+ }
98
+
99
+ // Key = value
100
+ const kvMatch = trimmed.match(/^(\w+)\s*=\s*(.+)$/);
101
+ if (!kvMatch) continue;
102
+
103
+ const key = kvMatch[1];
104
+ let value = kvMatch[2]?.trim() ?? "";
105
+
106
+ // Strip quotes
107
+ if (
108
+ (value.startsWith('"') && value.endsWith('"')) ||
109
+ (value.startsWith("'") && value.endsWith("'"))
110
+ ) {
111
+ value = value.slice(1, -1);
112
+ }
113
+
114
+ if (!currentSection) {
115
+ // Top-level keys
116
+ if (key === "model") settings.model = value;
117
+ if (key === "personality") settings.personality = value;
118
+ if (key === "model_reasoning_effort")
119
+ settings.modelReasoningEffort = value;
120
+ } else if (currentSection === `projects."${cwd}"`) {
121
+ // Project-specific keys
122
+ if (key === "trust_level") settings.trustLevel = value;
123
+ }
124
+ }
125
+
126
+ return settings;
127
+ }
@@ -10,6 +10,7 @@ export interface CodexProcessOptions {
10
10
  apiBaseUrl?: string;
11
11
  apiKey?: string;
12
12
  model?: string;
13
+ instructions?: string;
13
14
  binaryPath?: string;
14
15
  logger?: Logger;
15
16
  processCallbacks?: ProcessSpawnedCallback;
@@ -42,6 +43,13 @@ function buildConfigArgs(options: CodexProcessOptions): string[] {
42
43
  args.push("-c", `model="${options.model}"`);
43
44
  }
44
45
 
46
+ if (options.instructions) {
47
+ const escaped = options.instructions
48
+ .replace(/\\/g, "\\\\")
49
+ .replace(/"/g, '\\"');
50
+ args.push("-c", `instructions="${escaped}"`);
51
+ }
52
+
45
53
  return args;
46
54
  }
47
55
 
package/src/agent.ts CHANGED
@@ -131,6 +131,7 @@ export class Agent {
131
131
  apiKey: gatewayConfig.apiKey,
132
132
  binaryPath: options.codexBinaryPath,
133
133
  model: sanitizedModel,
134
+ instructions: options.instructions,
134
135
  }
135
136
  : undefined,
136
137
  });
package/src/types.ts CHANGED
@@ -112,6 +112,7 @@ export interface TaskExecutionOptions {
112
112
  model?: string;
113
113
  gatewayUrl?: string;
114
114
  codexBinaryPath?: string;
115
+ instructions?: string;
115
116
  processCallbacks?: ProcessSpawnedCallback;
116
117
  }
117
118