@sunerpy/opencode-kiro-auth 0.7.0 → 0.8.0
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/README.md +12 -4
- package/dist/plugin/config/loader.js +49 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -101,6 +101,13 @@ mapping) lives in `~/.config/opencode/kiro.json`. See
|
|
|
101
101
|
[docs/CONFIGURATION.md](docs/CONFIGURATION.md) for the full example and every
|
|
102
102
|
option.
|
|
103
103
|
|
|
104
|
+
New default keys are backfilled into an existing `kiro.json` automatically when
|
|
105
|
+
the plugin loads (additive only — your existing values are never changed). For
|
|
106
|
+
multi-account or long-idle setups, enable
|
|
107
|
+
[token keep-alive](docs/CONFIGURATION.md#token-keep-alive)
|
|
108
|
+
(`token_keepalive_enabled: true`) to keep idle accounts' tokens fresh while
|
|
109
|
+
OpenCode is running.
|
|
110
|
+
|
|
104
111
|
## Multiple accounts & rotation
|
|
105
112
|
|
|
106
113
|
You can register more than one Kiro account and let the plugin spread
|
|
@@ -113,10 +120,11 @@ requests across them for combined quota and automatic failover.
|
|
|
113
120
|
AWS identity is stored separately in `kiro.db`. Re-running login for the
|
|
114
121
|
same identity updates it in place; logging in with a different identity
|
|
115
122
|
adds a new account.
|
|
116
|
-
2. Auto-sync from Kiro CLI: with `auto_sync_kiro_cli: true` (
|
|
117
|
-
the plugin imports credentials from your local `kiro-cli`
|
|
118
|
-
|
|
119
|
-
|
|
123
|
+
2. Auto-sync from Kiro CLI: with `auto_sync_kiro_cli: true` (opt-in, default
|
|
124
|
+
`false`), the plugin imports credentials from your local `kiro-cli`
|
|
125
|
+
database. Note `kiro-cli` stores only one token per auth method, so it
|
|
126
|
+
cannot represent multiple accounts — manual `opencode auth login` per
|
|
127
|
+
account (option 1) is the supported multi-account path.
|
|
120
128
|
|
|
121
129
|
**Rotation strategy** — set `account_selection_strategy` in
|
|
122
130
|
`~/.config/opencode/kiro.json`:
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, unlinkSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import { homedir } from 'node:os';
|
|
3
3
|
import { dirname, join } from 'node:path';
|
|
4
4
|
import * as logger from '../logger.js';
|
|
@@ -30,6 +30,53 @@ function ensureUserConfigTemplate() {
|
|
|
30
30
|
export function getProjectConfigPath(directory) {
|
|
31
31
|
return join(directory, '.opencode', 'kiro.json');
|
|
32
32
|
}
|
|
33
|
+
// Additively write any DEFAULT_CONFIG key missing from an existing user
|
|
34
|
+
// kiro.json so new-version keys become visible/toggleable. Additive-only,
|
|
35
|
+
// parse-safe, atomic, idempotent, user-config-only. See plan config-backfill.md.
|
|
36
|
+
function backfillUserConfig(path) {
|
|
37
|
+
if (!existsSync(path)) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
let raw;
|
|
41
|
+
try {
|
|
42
|
+
raw = JSON.parse(readFileSync(path, 'utf-8'));
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (typeof raw !== 'object' || raw === null || Array.isArray(raw)) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const obj = raw;
|
|
51
|
+
const defaultKeys = Object.keys(DEFAULT_CONFIG);
|
|
52
|
+
const missing = defaultKeys.filter((key) => !(key in obj));
|
|
53
|
+
if (missing.length === 0) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const next = { ...obj };
|
|
57
|
+
for (const key of missing) {
|
|
58
|
+
next[key] = DEFAULT_CONFIG[key];
|
|
59
|
+
}
|
|
60
|
+
const tmp = `${path}.tmp-${process.pid}-${Date.now()}`;
|
|
61
|
+
try {
|
|
62
|
+
writeFileSync(tmp, `${JSON.stringify(next, null, 2)}\n`, 'utf-8');
|
|
63
|
+
try {
|
|
64
|
+
renameSync(tmp, path);
|
|
65
|
+
}
|
|
66
|
+
catch (renameError) {
|
|
67
|
+
try {
|
|
68
|
+
if (existsSync(tmp))
|
|
69
|
+
unlinkSync(tmp);
|
|
70
|
+
}
|
|
71
|
+
catch { }
|
|
72
|
+
throw renameError;
|
|
73
|
+
}
|
|
74
|
+
logger.log(`Backfilled ${missing.length} new config key(s) into ${path}: ${missing.join(', ')}`);
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
logger.warn(`Config backfill failed for ${path}: ${String(error)}`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
33
80
|
function loadConfigFile(path) {
|
|
34
81
|
try {
|
|
35
82
|
if (!existsSync(path)) {
|
|
@@ -109,6 +156,7 @@ function applyEnvOverrides(config) {
|
|
|
109
156
|
}
|
|
110
157
|
export function loadConfig(directory) {
|
|
111
158
|
ensureUserConfigTemplate();
|
|
159
|
+
backfillUserConfig(getUserConfigPath());
|
|
112
160
|
let config = { ...DEFAULT_CONFIG };
|
|
113
161
|
const userConfigPath = getUserConfigPath();
|
|
114
162
|
const userConfig = loadConfigFile(userConfigPath);
|