@iam-brain/opencode-codex-auth 0.1.5 → 0.1.6

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 (38) hide show
  1. package/README.md +15 -1
  2. package/dist/bin/persona-tool.d.ts +3 -0
  3. package/dist/bin/persona-tool.d.ts.map +1 -0
  4. package/dist/bin/persona-tool.js +13 -0
  5. package/dist/bin/persona-tool.js.map +1 -0
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +51 -0
  8. package/dist/index.js.map +1 -1
  9. package/dist/lib/config.d.ts +1 -0
  10. package/dist/lib/config.d.ts.map +1 -1
  11. package/dist/lib/config.js +1 -0
  12. package/dist/lib/config.js.map +1 -1
  13. package/dist/lib/installer-cli.d.ts.map +1 -1
  14. package/dist/lib/installer-cli.js +5 -1
  15. package/dist/lib/installer-cli.js.map +1 -1
  16. package/dist/lib/persona-tool-cli.d.ts +7 -0
  17. package/dist/lib/persona-tool-cli.d.ts.map +1 -0
  18. package/dist/lib/persona-tool-cli.js +152 -0
  19. package/dist/lib/persona-tool-cli.js.map +1 -0
  20. package/dist/lib/persona-tool.d.ts +29 -0
  21. package/dist/lib/persona-tool.d.ts.map +1 -0
  22. package/dist/lib/persona-tool.js +358 -0
  23. package/dist/lib/persona-tool.js.map +1 -0
  24. package/dist/lib/personalities.d.ts +3 -0
  25. package/dist/lib/personalities.d.ts.map +1 -1
  26. package/dist/lib/personalities.js +19 -19
  27. package/dist/lib/personalities.js.map +1 -1
  28. package/dist/lib/personality-command.d.ts +14 -0
  29. package/dist/lib/personality-command.d.ts.map +1 -0
  30. package/dist/lib/personality-command.js +71 -0
  31. package/dist/lib/personality-command.js.map +1 -0
  32. package/dist/lib/personality-create.d.ts +38 -0
  33. package/dist/lib/personality-create.d.ts.map +1 -0
  34. package/dist/lib/personality-create.js +92 -0
  35. package/dist/lib/personality-create.js.map +1 -0
  36. package/package.json +3 -2
  37. package/schemas/codex-accounts.schema.json +132 -0
  38. package/schemas/codex-config.schema.json +3 -0
@@ -0,0 +1,92 @@
1
+ import fs from "node:fs/promises";
2
+ import path from "node:path";
3
+ import { defaultConfigRoot, normalizePersonalityKey } from "./personalities";
4
+ const PERSONALITIES_DIR = "personalities";
5
+ const CORE_POLICY_LINES = [
6
+ "You are Codex, a coding agent in a terminal-first workflow.",
7
+ "You prioritize correctness, safety, and clear communication.",
8
+ "You never invent command output, tool results, or files you did not inspect.",
9
+ "You make small, reversible changes and validate behavior before claiming success.",
10
+ "You stay collaborative: concise when possible, detailed when needed."
11
+ ];
12
+ function normalizeText(value) {
13
+ if (typeof value !== "string")
14
+ return undefined;
15
+ const trimmed = value.trim();
16
+ return trimmed.length > 0 ? trimmed : undefined;
17
+ }
18
+ function section(title, body) {
19
+ if (!body)
20
+ return [];
21
+ return [`## ${title}`, body, ""];
22
+ }
23
+ export function renderPersonalityMarkdown(input) {
24
+ const inspiration = normalizeText(input.inspiration);
25
+ const tone = normalizeText(input.tone);
26
+ const collaborationStyle = normalizeText(input.collaborationStyle);
27
+ const codeStyle = normalizeText(input.codeStyle);
28
+ const constraints = normalizeText(input.constraints);
29
+ const examples = normalizeText(input.examples);
30
+ const lines = [
31
+ `# Personality: ${input.key}`,
32
+ "",
33
+ "## Core Assistant Contract",
34
+ ...CORE_POLICY_LINES.map((line) => `- ${line}`),
35
+ "",
36
+ "This section is required and should remain intact for any derived personality.",
37
+ ""
38
+ ];
39
+ lines.push(...section("Inspiration", inspiration));
40
+ lines.push(...section("Tone", tone));
41
+ lines.push(...section("Collaboration Style", collaborationStyle));
42
+ lines.push(...section("Coding Style", codeStyle));
43
+ lines.push(...section("Guardrails", constraints));
44
+ lines.push(...section("Examples", examples));
45
+ if (lines.at(-1) !== "")
46
+ lines.push("");
47
+ return lines.join("\n");
48
+ }
49
+ export function resolvePersonalityFilePath(input) {
50
+ const root = input.scope === "project"
51
+ ? path.join(input.projectRoot ?? process.cwd(), ".opencode")
52
+ : (input.configRoot ?? defaultConfigRoot());
53
+ return path.join(root, PERSONALITIES_DIR, `${input.key}.md`);
54
+ }
55
+ export async function createPersonalityFile(input) {
56
+ const key = normalizePersonalityKey(input.name);
57
+ if (!key) {
58
+ throw new Error("Invalid personality name. Use a safe key without path characters.");
59
+ }
60
+ const scope = input.scope === "project" ? "project" : "global";
61
+ const filePath = resolvePersonalityFilePath({
62
+ key,
63
+ scope,
64
+ projectRoot: input.projectRoot,
65
+ configRoot: input.configRoot
66
+ });
67
+ const content = renderPersonalityMarkdown({
68
+ key,
69
+ inspiration: input.inspiration,
70
+ tone: input.tone,
71
+ collaborationStyle: input.collaborationStyle,
72
+ codeStyle: input.codeStyle,
73
+ constraints: input.constraints,
74
+ examples: input.examples
75
+ });
76
+ const finalContent = input.markdown?.trim() ? `${input.markdown.trim()}\n` : `${content}\n`;
77
+ let created = true;
78
+ try {
79
+ await fs.stat(filePath);
80
+ if (input.overwrite !== true) {
81
+ return { key, filePath, scope, created: false };
82
+ }
83
+ created = false;
84
+ }
85
+ catch {
86
+ created = true;
87
+ }
88
+ await fs.mkdir(path.dirname(filePath), { recursive: true });
89
+ await fs.writeFile(filePath, finalContent, { encoding: "utf8", mode: 0o600 });
90
+ return { key, filePath, scope, created };
91
+ }
92
+ //# sourceMappingURL=personality-create.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"personality-create.js","sourceRoot":"","sources":["../../lib/personality-create.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,kBAAkB,CAAA;AACjC,OAAO,IAAI,MAAM,WAAW,CAAA;AAE5B,OAAO,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAA;AA0B5E,MAAM,iBAAiB,GAAG,eAAe,CAAA;AAEzC,MAAM,iBAAiB,GAAG;IACxB,6DAA6D;IAC7D,8DAA8D;IAC9D,8EAA8E;IAC9E,mFAAmF;IACnF,sEAAsE;CACvE,CAAA;AAED,SAAS,aAAa,CAAC,KAAyB;IAC9C,IAAI,OAAO,KAAK,K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IAC7E,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAE,CAAA;AAC1C,CAAC"}
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@iam-brain/opencode-codex-auth",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "Native Codex auth with multi-account rotation for OpenCode",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "type": "module",
8
8
  "bin": {
9
- "opencode-codex-auth": "./dist/bin/opencode-codex-auth.js"
9
+ "opencode-codex-auth": "./dist/bin/opencode-codex-auth.js",
10
+ "persona-tool": "./dist/bin/persona-tool.js"
10
11
  },
11
12
  "license": "MIT",
12
13
  "author": "iam-brain",
@@ -0,0 +1,132 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://schemas.iam-brain.dev/opencode-codex-auth/codex-accounts.schema.json",
4
+ "title": "OpenCode Codex Auth Accounts",
5
+ "description": "Schema for ~/.config/opencode/codex-accounts.json",
6
+ "type": "object",
7
+ "additionalProperties": false,
8
+ "properties": {
9
+ "openai": {
10
+ "type": "object",
11
+ "additionalProperties": false,
12
+ "properties": {
13
+ "type": {
14
+ "const": "oauth"
15
+ },
16
+ "strategy": {
17
+ "$ref": "#/$defs/rotationStrategy"
18
+ },
19
+ "accounts": {
20
+ "type": "array",
21
+ "items": {
22
+ "$ref": "#/$defs/accountRecord"
23
+ }
24
+ },
25
+ "activeIdentityKey": {
26
+ "type": "string",
27
+ "minLength": 1
28
+ },
29
+ "native": {
30
+ "$ref": "#/$defs/authDomain"
31
+ },
32
+ "codex": {
33
+ "$ref": "#/$defs/authDomain"
34
+ }
35
+ },
36
+ "required": ["type", "accounts"]
37
+ }
38
+ },
39
+ "$defs": {
40
+ "rotationStrategy": {
41
+ "type": "string",
42
+ "enum": ["sticky", "hybrid", "round_robin"]
43
+ },
44
+ "accountAuthType": {
45
+ "type": "string",
46
+ "enum": ["native", "codex"]
47
+ },
48
+ "accountRecord": {
49
+ "type": "object",
50
+ "additionalProperties": false,
51
+ "properties": {
52
+ "identityKey": {
53
+ "type": "string",
54
+ "minLength": 1
55
+ },
56
+ "accountId": {
57
+ "type": "string",
58
+ "minLength": 1
59
+ },
60
+ "email": {
61
+ "type": "string",
62
+ "minLength": 1
63
+ },
64
+ "plan": {
65
+ "type": "string",
66
+ "minLength": 1
67
+ },
68
+ "authTypes": {
69
+ "type": "array",
70
+ "items": {
71
+ "$ref": "#/$defs/accountAuthType"
72
+ },
73
+ "uniqueItems": true
74
+ },
75
+ "enabled": {
76
+ "type": "boolean"
77
+ },
78
+ "access": {
79
+ "type": "string",
80
+ "minLength": 1
81
+ },
82
+ "refresh": {
83
+ "type": "string",
84
+ "minLength": 1
85
+ },
86
+ "expires": {
87
+ "type": "number"
88
+ },
89
+ "refreshLeaseUntil": {
90
+ "type": "number"
91
+ },
92
+ "cooldownUntil": {
93
+ "type": "number"
94
+ },
95
+ "lastUsed": {
96
+ "type": "number"
97
+ }
98
+ }
99
+ },
100
+ "authDomain": {
101
+ "type": "object",
102
+ "additionalProperties": false,
103
+ "properties": {
104
+ "strategy": {
105
+ "$ref": "#/$defs/rotationStrategy"
106
+ },
107
+ "accounts": {
108
+ "type": "array",
109
+ "items": {
110
+ "$ref": "#/$defs/accountRecord"
111
+ }
112
+ },
113
+ "activeIdentityKey": {
114
+ "type": "string",
115
+ "minLength": 1
116
+ }
117
+ },
118
+ "required": ["accounts"]
119
+ }
120
+ },
121
+ "examples": [
122
+ {
123
+ "openai": {
124
+ "type": "oauth",
125
+ "strategy": "sticky",
126
+ "accounts": [],
127
+ "native": { "accounts": [] },
128
+ "codex": { "accounts": [] }
129
+ }
130
+ }
131
+ ]
132
+ }
@@ -6,6 +6,9 @@
6
6
  "type": "object",
7
7
  "additionalProperties": false,
8
8
  "properties": {
9
+ "$schema": {
10
+ "type": "string"
11
+ },
9
12
  "debug": {
10
13
  "type": "boolean"
11
14
  },