@commonlyai/cli 0.1.368 → 0.1.369
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/package.json +1 -1
- package/src/lib/adapters/opencode.js +45 -0
package/package.json
CHANGED
|
@@ -686,6 +686,44 @@ const substitutePublicPlaceholders = (value, ctx) => {
|
|
|
686
686
|
// rewrite below may carry one.
|
|
687
687
|
const OPENCODE_SUBSTITUTION_RE = /\{(?:env|file):/;
|
|
688
688
|
|
|
689
|
+
// F484: the same rule for the whole config, since OpenCode substitutes all of
|
|
690
|
+
// its text, keys included: a stdio entry's command, environment or cwd, and the
|
|
691
|
+
// provider's baseURL and models, are operator-written too. A stdio command part
|
|
692
|
+
// spelling `{file:<credential>}` also passed the argv credential check, which
|
|
693
|
+
// runs before OpenCode expands it. The only substitutions allowed are the two
|
|
694
|
+
// this adapter writes, each at its own place: the bearer header of a remote
|
|
695
|
+
// entry recorded in `bearerFileServers`, and the selected provider's apiKey.
|
|
696
|
+
// Anything else refuses the spawn; the error names where, never the value.
|
|
697
|
+
const assertOwnSubstitutionsOnly = (config, {
|
|
698
|
+
credentialFile = null, bearerFileServers = [], providerId = null, keyFile = null,
|
|
699
|
+
} = {}) => {
|
|
700
|
+
const bearer = credentialFile ? `Bearer {file:${credentialFile}}` : null;
|
|
701
|
+
const apiKey = keyFile ? `{file:${keyFile}}` : null;
|
|
702
|
+
const own = (path, value) => (
|
|
703
|
+
(bearer !== null && value === bearer && path.length === 4 && path[0] === 'mcp'
|
|
704
|
+
&& bearerFileServers.includes(path[1]) && path[2] === 'headers'
|
|
705
|
+
&& String(path[3]).toLowerCase() === 'authorization')
|
|
706
|
+
|| (apiKey !== null && value === apiKey && path.length === 4 && path[0] === 'provider'
|
|
707
|
+
&& providerId !== null && path[1] === providerId && path[2] === 'options' && path[3] === 'apiKey')
|
|
708
|
+
);
|
|
709
|
+
const refuse = (path) => {
|
|
710
|
+
throw new Error(`OpenCode config refused: an OpenCode substitution ({env: or {file:) at ${path.join('.')}; `
|
|
711
|
+
+ 'only the adapter\'s own credential and provider key spellings may carry one');
|
|
712
|
+
};
|
|
713
|
+
const walk = (node, path) => {
|
|
714
|
+
if (typeof node === 'string') {
|
|
715
|
+
if (OPENCODE_SUBSTITUTION_RE.test(node) && !own(path, node)) refuse(path);
|
|
716
|
+
return;
|
|
717
|
+
}
|
|
718
|
+
if (!node || typeof node !== 'object') return;
|
|
719
|
+
for (const [key, value] of Object.entries(node)) {
|
|
720
|
+
if (OPENCODE_SUBSTITUTION_RE.test(key)) refuse([...path, key]);
|
|
721
|
+
walk(value, [...path, key]);
|
|
722
|
+
}
|
|
723
|
+
};
|
|
724
|
+
walk(config, []);
|
|
725
|
+
};
|
|
726
|
+
|
|
689
727
|
const isSafeMcpName = (name) => typeof name === 'string'
|
|
690
728
|
&& /^[A-Za-z0-9_-]+$/.test(name);
|
|
691
729
|
|
|
@@ -1584,6 +1622,12 @@ export default {
|
|
|
1584
1622
|
} : {}),
|
|
1585
1623
|
...(Object.keys(mcp).length ? { mcp } : {}),
|
|
1586
1624
|
};
|
|
1625
|
+
assertOwnSubstitutionsOnly(config, {
|
|
1626
|
+
credentialFile: credential?.path || null,
|
|
1627
|
+
bearerFileServers,
|
|
1628
|
+
providerId: provider?.id ?? null,
|
|
1629
|
+
keyFile: provider ? (providerProxy?.tokenFile || providerKeyFile) : null,
|
|
1630
|
+
});
|
|
1587
1631
|
await writeFile(configPath, `${JSON.stringify(config, null, 2)}\n`, {
|
|
1588
1632
|
encoding: 'utf8', mode: 0o600,
|
|
1589
1633
|
});
|
|
@@ -1756,6 +1800,7 @@ export {
|
|
|
1756
1800
|
DISABLED_ENV,
|
|
1757
1801
|
TESTED_OPENCODE_VERSIONS,
|
|
1758
1802
|
buildArgs,
|
|
1803
|
+
assertOwnSubstitutionsOnly,
|
|
1759
1804
|
buildMcpConfig,
|
|
1760
1805
|
buildProviderConfig,
|
|
1761
1806
|
makeEventParser,
|