negotium 0.1.21 → 0.1.22
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/dist/agent-helpers.js +183 -200
- package/dist/agent-helpers.js.map +8 -8
- package/dist/cron.js +231 -220
- package/dist/cron.js.map +10 -10
- package/dist/hosted-agent.js +233 -250
- package/dist/hosted-agent.js.map +9 -9
- package/dist/main.js +391 -395
- package/dist/main.js.map +12 -12
- package/dist/runtime/scripts/browser-webauthn-policy.mjs +37 -0
- package/dist/runtime/scripts/mcp-patchright-http.mjs +8 -3
- package/dist/runtime/src/agents/vault-tool-policy.ts +13 -4
- package/dist/runtime/src/platform/mcp-config.ts +2 -1
- package/dist/runtime/src/platform/playwright/manager.ts +18 -0
- package/dist/runtime/src/prompts/sessions/channel-system.md +1 -1
- package/dist/runtime/src/prompts/sessions/topic-system.md +1 -1
- package/dist/runtime/src/version.ts +1 -1
- package/dist/types/packages/core/src/agents/vault-tool-policy.d.ts +1 -1
- package/dist/types/packages/core/src/version.d.ts +1 -1
- package/package.json +1 -1
package/dist/hosted-agent.js
CHANGED
|
@@ -683,248 +683,6 @@ function isSensitivePath(filePath) {
|
|
|
683
683
|
return false;
|
|
684
684
|
}
|
|
685
685
|
|
|
686
|
-
// ../../packages/core/src/storage/vault.ts
|
|
687
|
-
import { chmodSync as chmodSync2, mkdirSync as mkdirSync5 } from "fs";
|
|
688
|
-
import { join as join5 } from "path";
|
|
689
|
-
|
|
690
|
-
// ../../packages/core/src/storage/sqlite.ts
|
|
691
|
-
var isBun = typeof process.versions.bun === "string";
|
|
692
|
-
var Database;
|
|
693
|
-
if (isBun) {
|
|
694
|
-
({ Database } = await import("bun:sqlite"));
|
|
695
|
-
} else {
|
|
696
|
-
const nodeSqliteSpecifier = ["node", "sqlite"].join(":");
|
|
697
|
-
const { DatabaseSync } = await import(nodeSqliteSpecifier);
|
|
698
|
-
|
|
699
|
-
class NodeDatabase {
|
|
700
|
-
#db;
|
|
701
|
-
constructor(path, options = {}) {
|
|
702
|
-
this.#db = options.readonly ? new DatabaseSync(path, { readOnly: true }) : new DatabaseSync(path);
|
|
703
|
-
}
|
|
704
|
-
query(sql) {
|
|
705
|
-
return this.#db.prepare(sql);
|
|
706
|
-
}
|
|
707
|
-
prepare(sql) {
|
|
708
|
-
return this.#db.prepare(sql);
|
|
709
|
-
}
|
|
710
|
-
exec(sql) {
|
|
711
|
-
this.#db.exec(sql);
|
|
712
|
-
}
|
|
713
|
-
run(sql, ...params) {
|
|
714
|
-
return this.#db.prepare(sql).run(...params);
|
|
715
|
-
}
|
|
716
|
-
transaction(fn) {
|
|
717
|
-
const run = (begin) => (...args) => {
|
|
718
|
-
this.#db.exec(begin);
|
|
719
|
-
try {
|
|
720
|
-
const result = fn(...args);
|
|
721
|
-
this.#db.exec("COMMIT");
|
|
722
|
-
return result;
|
|
723
|
-
} catch (err) {
|
|
724
|
-
this.#db.exec("ROLLBACK");
|
|
725
|
-
throw err;
|
|
726
|
-
}
|
|
727
|
-
};
|
|
728
|
-
const tx = run("BEGIN");
|
|
729
|
-
tx.deferred = run("BEGIN DEFERRED");
|
|
730
|
-
tx.immediate = run("BEGIN IMMEDIATE");
|
|
731
|
-
tx.exclusive = run("BEGIN EXCLUSIVE");
|
|
732
|
-
return tx;
|
|
733
|
-
}
|
|
734
|
-
close() {
|
|
735
|
-
this.#db.close();
|
|
736
|
-
}
|
|
737
|
-
}
|
|
738
|
-
Database = NodeDatabase;
|
|
739
|
-
}
|
|
740
|
-
|
|
741
|
-
// ../../packages/core/src/storage/vault-crypto.ts
|
|
742
|
-
import { createCipheriv, createDecipheriv, createHash, randomBytes as randomBytes2 } from "crypto";
|
|
743
|
-
var ENVELOPE_PREFIX = "otium-vault:v1:";
|
|
744
|
-
var IV_BYTES = 12;
|
|
745
|
-
var KEY_BYTES = 32;
|
|
746
|
-
function encryptionKey(masterKey = VAULT_MASTER_KEY) {
|
|
747
|
-
return createHash("sha256").update("otium-vault-value-v1\x00", "utf8").update(masterKey, "utf8").digest().subarray(0, KEY_BYTES);
|
|
748
|
-
}
|
|
749
|
-
function aad(userId, key) {
|
|
750
|
-
return Buffer.from(`${userId}\x00${key.toUpperCase()}`, "utf8");
|
|
751
|
-
}
|
|
752
|
-
function isEncryptedVaultValue(value) {
|
|
753
|
-
return value.startsWith(ENVELOPE_PREFIX);
|
|
754
|
-
}
|
|
755
|
-
function encryptVaultValue(userId, key, value, masterKey = VAULT_MASTER_KEY) {
|
|
756
|
-
const iv = randomBytes2(IV_BYTES);
|
|
757
|
-
const cipher = createCipheriv("aes-256-gcm", encryptionKey(masterKey), iv);
|
|
758
|
-
cipher.setAAD(aad(userId, key));
|
|
759
|
-
const ciphertext = Buffer.concat([cipher.update(value, "utf8"), cipher.final()]);
|
|
760
|
-
const tag = cipher.getAuthTag();
|
|
761
|
-
return `${ENVELOPE_PREFIX}${iv.toString("base64url")}.${ciphertext.toString("base64url")}.${tag.toString("base64url")}`;
|
|
762
|
-
}
|
|
763
|
-
function decryptVaultValue(userId, key, storedValue, masterKey = VAULT_MASTER_KEY) {
|
|
764
|
-
if (!isEncryptedVaultValue(storedValue)) {
|
|
765
|
-
return { value: storedValue, legacyPlaintext: true };
|
|
766
|
-
}
|
|
767
|
-
const encoded = storedValue.slice(ENVELOPE_PREFIX.length);
|
|
768
|
-
const [ivPart, ciphertextPart, tagPart, ...extra] = encoded.split(".");
|
|
769
|
-
if (!ivPart || ciphertextPart === undefined || !tagPart || extra.length > 0) {
|
|
770
|
-
throw new Error("Invalid encrypted vault value");
|
|
771
|
-
}
|
|
772
|
-
const iv = Buffer.from(ivPart, "base64url");
|
|
773
|
-
const ciphertext = Buffer.from(ciphertextPart, "base64url");
|
|
774
|
-
const tag = Buffer.from(tagPart, "base64url");
|
|
775
|
-
if (iv.length !== IV_BYTES || tag.length !== 16) {
|
|
776
|
-
throw new Error("Invalid encrypted vault value");
|
|
777
|
-
}
|
|
778
|
-
const decipher = createDecipheriv("aes-256-gcm", encryptionKey(masterKey), iv);
|
|
779
|
-
decipher.setAAD(aad(userId, key));
|
|
780
|
-
decipher.setAuthTag(tag);
|
|
781
|
-
const plaintext = Buffer.concat([decipher.update(ciphertext), decipher.final()]);
|
|
782
|
-
return { value: plaintext.toString("utf8"), legacyPlaintext: false };
|
|
783
|
-
}
|
|
784
|
-
|
|
785
|
-
// ../../packages/core/src/storage/vault.ts
|
|
786
|
-
var vaultDb;
|
|
787
|
-
var vaultMasterKey = VAULT_MASTER_KEY;
|
|
788
|
-
function initializeVaultDatabase(database) {
|
|
789
|
-
database.exec("PRAGMA journal_mode = WAL");
|
|
790
|
-
database.exec("PRAGMA busy_timeout = 5000");
|
|
791
|
-
database.exec(`
|
|
792
|
-
CREATE TABLE IF NOT EXISTS vault (
|
|
793
|
-
user_id TEXT NOT NULL,
|
|
794
|
-
key TEXT NOT NULL,
|
|
795
|
-
value TEXT NOT NULL,
|
|
796
|
-
description TEXT NOT NULL DEFAULT '',
|
|
797
|
-
PRIMARY KEY (user_id, key)
|
|
798
|
-
)
|
|
799
|
-
`);
|
|
800
|
-
{
|
|
801
|
-
const cols = database.prepare("PRAGMA table_info(vault)").all();
|
|
802
|
-
const uid = cols.find((c) => c.name === "user_id");
|
|
803
|
-
if (uid && uid.type.toUpperCase() === "INTEGER") {
|
|
804
|
-
database.exec("BEGIN");
|
|
805
|
-
database.exec(`
|
|
806
|
-
CREATE TABLE vault_migrated (
|
|
807
|
-
user_id TEXT NOT NULL,
|
|
808
|
-
key TEXT NOT NULL,
|
|
809
|
-
value TEXT NOT NULL,
|
|
810
|
-
description TEXT NOT NULL DEFAULT '',
|
|
811
|
-
PRIMARY KEY (user_id, key)
|
|
812
|
-
)
|
|
813
|
-
`);
|
|
814
|
-
database.exec("INSERT INTO vault_migrated SELECT CAST(user_id AS TEXT), key, value, description FROM vault");
|
|
815
|
-
database.exec("DROP TABLE vault");
|
|
816
|
-
database.exec("ALTER TABLE vault_migrated RENAME TO vault");
|
|
817
|
-
database.exec("COMMIT");
|
|
818
|
-
}
|
|
819
|
-
}
|
|
820
|
-
}
|
|
821
|
-
function openVaultDatabase(dataDir) {
|
|
822
|
-
const path = join5(dataDir, "vault.db");
|
|
823
|
-
mkdirSync5(dataDir, { recursive: true });
|
|
824
|
-
const database = new Database(path, { create: true });
|
|
825
|
-
chmodSync2(path, 384);
|
|
826
|
-
initializeVaultDatabase(database);
|
|
827
|
-
return database;
|
|
828
|
-
}
|
|
829
|
-
function activeVaultDatabase() {
|
|
830
|
-
if (!vaultDb)
|
|
831
|
-
vaultDb = openVaultDatabase(DATA_DIR);
|
|
832
|
-
return vaultDb;
|
|
833
|
-
}
|
|
834
|
-
var VAULT_VALUE_MAX_BYTES = 64 * 1024;
|
|
835
|
-
function normalizeVaultKey(key) {
|
|
836
|
-
return key.trim().toUpperCase();
|
|
837
|
-
}
|
|
838
|
-
function decryptRow(userId, key, storedValue) {
|
|
839
|
-
const database = activeVaultDatabase();
|
|
840
|
-
const decoded = decryptVaultValue(userId, key, storedValue, vaultMasterKey);
|
|
841
|
-
if (decoded.legacyPlaintext) {
|
|
842
|
-
database.prepare("UPDATE vault SET value = ? WHERE user_id = ? AND key = ? AND value = ?").run(encryptVaultValue(userId, key, decoded.value, vaultMasterKey), userId, key, storedValue);
|
|
843
|
-
}
|
|
844
|
-
return decoded.value;
|
|
845
|
-
}
|
|
846
|
-
function vaultListWithValues(userId) {
|
|
847
|
-
const rows = activeVaultDatabase().prepare("SELECT key, description, value FROM vault WHERE user_id = ? ORDER BY key").all(userId);
|
|
848
|
-
return rows.map((row) => ({
|
|
849
|
-
key: row.key,
|
|
850
|
-
description: row.description,
|
|
851
|
-
value: decryptRow(userId, row.key, row.value)
|
|
852
|
-
}));
|
|
853
|
-
}
|
|
854
|
-
function vaultList(userId) {
|
|
855
|
-
return activeVaultDatabase().prepare("SELECT key, description FROM vault WHERE user_id = ? ORDER BY key").all(userId);
|
|
856
|
-
}
|
|
857
|
-
function vaultSubstituteDetailed(userId, text) {
|
|
858
|
-
const entries = new Map(vaultListWithValues(userId).map((entry) => [entry.key, entry.value]));
|
|
859
|
-
const usedKeys = new Set;
|
|
860
|
-
const substituted = text.replace(/\{\{([^}]+)\}\}/g, (match, rawKey) => {
|
|
861
|
-
const key = normalizeVaultKey(rawKey);
|
|
862
|
-
const value = entries.get(key);
|
|
863
|
-
if (value === undefined)
|
|
864
|
-
return match;
|
|
865
|
-
usedKeys.add(key);
|
|
866
|
-
return value;
|
|
867
|
-
});
|
|
868
|
-
return { text: substituted, usedKeys: [...usedKeys] };
|
|
869
|
-
}
|
|
870
|
-
function valueReferencesVaultKey(userId, value) {
|
|
871
|
-
const keys = new Set(vaultList(userId).map((entry) => entry.key));
|
|
872
|
-
const visit = (candidate) => {
|
|
873
|
-
if (typeof candidate === "string") {
|
|
874
|
-
for (const match of candidate.matchAll(/\{\{([^}]+)\}\}/g)) {
|
|
875
|
-
if (keys.has(normalizeVaultKey(match[1] ?? "")))
|
|
876
|
-
return true;
|
|
877
|
-
}
|
|
878
|
-
return false;
|
|
879
|
-
}
|
|
880
|
-
if (Array.isArray(candidate))
|
|
881
|
-
return candidate.some(visit);
|
|
882
|
-
if (candidate && typeof candidate === "object") {
|
|
883
|
-
return Object.values(candidate).some(visit);
|
|
884
|
-
}
|
|
885
|
-
return false;
|
|
886
|
-
};
|
|
887
|
-
return visit(value);
|
|
888
|
-
}
|
|
889
|
-
function encodedSecretForms(value) {
|
|
890
|
-
const forms = new Set([
|
|
891
|
-
value,
|
|
892
|
-
encodeURIComponent(value),
|
|
893
|
-
Buffer.from(value, "utf8").toString("base64"),
|
|
894
|
-
Buffer.from(value, "utf8").toString("base64url"),
|
|
895
|
-
Buffer.from(value, "utf8").toString("hex")
|
|
896
|
-
]);
|
|
897
|
-
forms.delete("");
|
|
898
|
-
return [...forms].sort((a, b) => b.length - a.length);
|
|
899
|
-
}
|
|
900
|
-
function redactVaultSecrets(userId, text) {
|
|
901
|
-
const candidates = vaultListWithValues(userId).flatMap((entry) => encodedSecretForms(entry.value).map((form) => ({ form, key: entry.key }))).sort((a, b) => b.form.length - a.form.length || a.key.localeCompare(b.key));
|
|
902
|
-
if (candidates.length === 0)
|
|
903
|
-
return text;
|
|
904
|
-
const candidatesByFirstCharacter = new Map;
|
|
905
|
-
for (const candidate of candidates) {
|
|
906
|
-
const first = candidate.form[0];
|
|
907
|
-
if (!first)
|
|
908
|
-
continue;
|
|
909
|
-
const bucket = candidatesByFirstCharacter.get(first) ?? [];
|
|
910
|
-
bucket.push(candidate);
|
|
911
|
-
candidatesByFirstCharacter.set(first, bucket);
|
|
912
|
-
}
|
|
913
|
-
let redacted = "";
|
|
914
|
-
let offset = 0;
|
|
915
|
-
while (offset < text.length) {
|
|
916
|
-
const match = candidatesByFirstCharacter.get(text[offset] ?? "")?.find((candidate) => text.startsWith(candidate.form, offset));
|
|
917
|
-
if (!match) {
|
|
918
|
-
redacted += text[offset];
|
|
919
|
-
offset += 1;
|
|
920
|
-
continue;
|
|
921
|
-
}
|
|
922
|
-
redacted += `[REDACTED:${match.key}]`;
|
|
923
|
-
offset += match.form.length;
|
|
924
|
-
}
|
|
925
|
-
return redacted;
|
|
926
|
-
}
|
|
927
|
-
|
|
928
686
|
// ../../packages/core/src/agents/vault-tool-policy.ts
|
|
929
687
|
var SENSITIVE_RUNTIME_NAMES = [
|
|
930
688
|
"vault.db",
|
|
@@ -951,11 +709,14 @@ function createVaultToolPolicy(host) {
|
|
|
951
709
|
return false;
|
|
952
710
|
}
|
|
953
711
|
function shouldRedirectVaultTool(userId, toolName, input) {
|
|
954
|
-
return
|
|
712
|
+
return false;
|
|
955
713
|
}
|
|
956
714
|
return { isVaultBrokerTool, referencesRuntimeSecretStorage, shouldRedirectVaultTool };
|
|
957
715
|
}
|
|
958
|
-
var defaultVaultToolPolicy = createVaultToolPolicy({
|
|
716
|
+
var defaultVaultToolPolicy = createVaultToolPolicy({
|
|
717
|
+
isSensitivePath,
|
|
718
|
+
valueReferencesVaultKey: () => false
|
|
719
|
+
});
|
|
959
720
|
var isVaultBrokerTool = defaultVaultToolPolicy.isVaultBrokerTool;
|
|
960
721
|
var referencesRuntimeSecretStorage = defaultVaultToolPolicy.referencesRuntimeSecretStorage;
|
|
961
722
|
var shouldRedirectVaultTool = defaultVaultToolPolicy.shouldRedirectVaultTool;
|
|
@@ -1011,7 +772,7 @@ function peerSessionBridgeIpcEnv() {
|
|
|
1011
772
|
|
|
1012
773
|
// ../../packages/core/src/platform/background-bash/manager.ts
|
|
1013
774
|
import { execFileSync, spawn } from "child_process";
|
|
1014
|
-
import { randomBytes as
|
|
775
|
+
import { randomBytes as randomBytes2 } from "crypto";
|
|
1015
776
|
|
|
1016
777
|
// ../../packages/core/src/platform/delay.ts
|
|
1017
778
|
var delay = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
@@ -1039,8 +800,8 @@ function createBackgroundBashManager(options = {}) {
|
|
|
1039
800
|
const usedPorts = new Set;
|
|
1040
801
|
const spawning = new Map;
|
|
1041
802
|
const knownContexts = new Map;
|
|
1042
|
-
const runtimeCapability = options.capability ??
|
|
1043
|
-
const runtimeServerId = options.serverId ??
|
|
803
|
+
const runtimeCapability = options.capability ?? randomBytes2(32).toString("hex");
|
|
804
|
+
const runtimeServerId = options.serverId ?? randomBytes2(16).toString("hex");
|
|
1044
805
|
const serverFile = options.serverFile ?? BACKGROUND_BASH_SERVER;
|
|
1045
806
|
const basePort = options.basePort ?? BG_BASH_BASE_PORT;
|
|
1046
807
|
const maxPort = options.maxPort ?? BG_BASH_MAX_PORT;
|
|
@@ -1468,7 +1229,9 @@ var MCP_CATALOG = {
|
|
|
1468
1229
|
vault: {
|
|
1469
1230
|
...commonRuntimeMcpPolicy("vault"),
|
|
1470
1231
|
build({ userId, agent }) {
|
|
1471
|
-
const args = [`--user-id=${userId}
|
|
1232
|
+
const args = [`--user-id=${userId}`];
|
|
1233
|
+
if (agent !== "codex")
|
|
1234
|
+
args.push("--list-only=true");
|
|
1472
1235
|
return buildStdioMcpServer(agent, VAULT_SERVER, args);
|
|
1473
1236
|
}
|
|
1474
1237
|
}
|
|
@@ -1686,6 +1449,226 @@ function getMcpServersForQuery(opts) {
|
|
|
1686
1449
|
});
|
|
1687
1450
|
}
|
|
1688
1451
|
|
|
1452
|
+
// ../../packages/core/src/storage/vault.ts
|
|
1453
|
+
import { chmodSync as chmodSync2, mkdirSync as mkdirSync5 } from "fs";
|
|
1454
|
+
import { join as join5 } from "path";
|
|
1455
|
+
|
|
1456
|
+
// ../../packages/core/src/storage/sqlite.ts
|
|
1457
|
+
var isBun = typeof process.versions.bun === "string";
|
|
1458
|
+
var Database;
|
|
1459
|
+
if (isBun) {
|
|
1460
|
+
({ Database } = await import("bun:sqlite"));
|
|
1461
|
+
} else {
|
|
1462
|
+
const nodeSqliteSpecifier = ["node", "sqlite"].join(":");
|
|
1463
|
+
const { DatabaseSync } = await import(nodeSqliteSpecifier);
|
|
1464
|
+
|
|
1465
|
+
class NodeDatabase {
|
|
1466
|
+
#db;
|
|
1467
|
+
constructor(path, options = {}) {
|
|
1468
|
+
this.#db = options.readonly ? new DatabaseSync(path, { readOnly: true }) : new DatabaseSync(path);
|
|
1469
|
+
}
|
|
1470
|
+
query(sql) {
|
|
1471
|
+
return this.#db.prepare(sql);
|
|
1472
|
+
}
|
|
1473
|
+
prepare(sql) {
|
|
1474
|
+
return this.#db.prepare(sql);
|
|
1475
|
+
}
|
|
1476
|
+
exec(sql) {
|
|
1477
|
+
this.#db.exec(sql);
|
|
1478
|
+
}
|
|
1479
|
+
run(sql, ...params) {
|
|
1480
|
+
return this.#db.prepare(sql).run(...params);
|
|
1481
|
+
}
|
|
1482
|
+
transaction(fn) {
|
|
1483
|
+
const run = (begin) => (...args) => {
|
|
1484
|
+
this.#db.exec(begin);
|
|
1485
|
+
try {
|
|
1486
|
+
const result = fn(...args);
|
|
1487
|
+
this.#db.exec("COMMIT");
|
|
1488
|
+
return result;
|
|
1489
|
+
} catch (err) {
|
|
1490
|
+
this.#db.exec("ROLLBACK");
|
|
1491
|
+
throw err;
|
|
1492
|
+
}
|
|
1493
|
+
};
|
|
1494
|
+
const tx = run("BEGIN");
|
|
1495
|
+
tx.deferred = run("BEGIN DEFERRED");
|
|
1496
|
+
tx.immediate = run("BEGIN IMMEDIATE");
|
|
1497
|
+
tx.exclusive = run("BEGIN EXCLUSIVE");
|
|
1498
|
+
return tx;
|
|
1499
|
+
}
|
|
1500
|
+
close() {
|
|
1501
|
+
this.#db.close();
|
|
1502
|
+
}
|
|
1503
|
+
}
|
|
1504
|
+
Database = NodeDatabase;
|
|
1505
|
+
}
|
|
1506
|
+
|
|
1507
|
+
// ../../packages/core/src/storage/vault-crypto.ts
|
|
1508
|
+
import { createCipheriv, createDecipheriv, createHash, randomBytes as randomBytes3 } from "crypto";
|
|
1509
|
+
var ENVELOPE_PREFIX = "otium-vault:v1:";
|
|
1510
|
+
var IV_BYTES = 12;
|
|
1511
|
+
var KEY_BYTES = 32;
|
|
1512
|
+
function encryptionKey(masterKey = VAULT_MASTER_KEY) {
|
|
1513
|
+
return createHash("sha256").update("otium-vault-value-v1\x00", "utf8").update(masterKey, "utf8").digest().subarray(0, KEY_BYTES);
|
|
1514
|
+
}
|
|
1515
|
+
function aad(userId, key) {
|
|
1516
|
+
return Buffer.from(`${userId}\x00${key.toUpperCase()}`, "utf8");
|
|
1517
|
+
}
|
|
1518
|
+
function isEncryptedVaultValue(value) {
|
|
1519
|
+
return value.startsWith(ENVELOPE_PREFIX);
|
|
1520
|
+
}
|
|
1521
|
+
function encryptVaultValue(userId, key, value, masterKey = VAULT_MASTER_KEY) {
|
|
1522
|
+
const iv = randomBytes3(IV_BYTES);
|
|
1523
|
+
const cipher = createCipheriv("aes-256-gcm", encryptionKey(masterKey), iv);
|
|
1524
|
+
cipher.setAAD(aad(userId, key));
|
|
1525
|
+
const ciphertext = Buffer.concat([cipher.update(value, "utf8"), cipher.final()]);
|
|
1526
|
+
const tag = cipher.getAuthTag();
|
|
1527
|
+
return `${ENVELOPE_PREFIX}${iv.toString("base64url")}.${ciphertext.toString("base64url")}.${tag.toString("base64url")}`;
|
|
1528
|
+
}
|
|
1529
|
+
function decryptVaultValue(userId, key, storedValue, masterKey = VAULT_MASTER_KEY) {
|
|
1530
|
+
if (!isEncryptedVaultValue(storedValue)) {
|
|
1531
|
+
return { value: storedValue, legacyPlaintext: true };
|
|
1532
|
+
}
|
|
1533
|
+
const encoded = storedValue.slice(ENVELOPE_PREFIX.length);
|
|
1534
|
+
const [ivPart, ciphertextPart, tagPart, ...extra] = encoded.split(".");
|
|
1535
|
+
if (!ivPart || ciphertextPart === undefined || !tagPart || extra.length > 0) {
|
|
1536
|
+
throw new Error("Invalid encrypted vault value");
|
|
1537
|
+
}
|
|
1538
|
+
const iv = Buffer.from(ivPart, "base64url");
|
|
1539
|
+
const ciphertext = Buffer.from(ciphertextPart, "base64url");
|
|
1540
|
+
const tag = Buffer.from(tagPart, "base64url");
|
|
1541
|
+
if (iv.length !== IV_BYTES || tag.length !== 16) {
|
|
1542
|
+
throw new Error("Invalid encrypted vault value");
|
|
1543
|
+
}
|
|
1544
|
+
const decipher = createDecipheriv("aes-256-gcm", encryptionKey(masterKey), iv);
|
|
1545
|
+
decipher.setAAD(aad(userId, key));
|
|
1546
|
+
decipher.setAuthTag(tag);
|
|
1547
|
+
const plaintext = Buffer.concat([decipher.update(ciphertext), decipher.final()]);
|
|
1548
|
+
return { value: plaintext.toString("utf8"), legacyPlaintext: false };
|
|
1549
|
+
}
|
|
1550
|
+
|
|
1551
|
+
// ../../packages/core/src/storage/vault.ts
|
|
1552
|
+
var vaultDb;
|
|
1553
|
+
var vaultMasterKey = VAULT_MASTER_KEY;
|
|
1554
|
+
function initializeVaultDatabase(database) {
|
|
1555
|
+
database.exec("PRAGMA journal_mode = WAL");
|
|
1556
|
+
database.exec("PRAGMA busy_timeout = 5000");
|
|
1557
|
+
database.exec(`
|
|
1558
|
+
CREATE TABLE IF NOT EXISTS vault (
|
|
1559
|
+
user_id TEXT NOT NULL,
|
|
1560
|
+
key TEXT NOT NULL,
|
|
1561
|
+
value TEXT NOT NULL,
|
|
1562
|
+
description TEXT NOT NULL DEFAULT '',
|
|
1563
|
+
PRIMARY KEY (user_id, key)
|
|
1564
|
+
)
|
|
1565
|
+
`);
|
|
1566
|
+
{
|
|
1567
|
+
const cols = database.prepare("PRAGMA table_info(vault)").all();
|
|
1568
|
+
const uid = cols.find((c) => c.name === "user_id");
|
|
1569
|
+
if (uid && uid.type.toUpperCase() === "INTEGER") {
|
|
1570
|
+
database.exec("BEGIN");
|
|
1571
|
+
database.exec(`
|
|
1572
|
+
CREATE TABLE vault_migrated (
|
|
1573
|
+
user_id TEXT NOT NULL,
|
|
1574
|
+
key TEXT NOT NULL,
|
|
1575
|
+
value TEXT NOT NULL,
|
|
1576
|
+
description TEXT NOT NULL DEFAULT '',
|
|
1577
|
+
PRIMARY KEY (user_id, key)
|
|
1578
|
+
)
|
|
1579
|
+
`);
|
|
1580
|
+
database.exec("INSERT INTO vault_migrated SELECT CAST(user_id AS TEXT), key, value, description FROM vault");
|
|
1581
|
+
database.exec("DROP TABLE vault");
|
|
1582
|
+
database.exec("ALTER TABLE vault_migrated RENAME TO vault");
|
|
1583
|
+
database.exec("COMMIT");
|
|
1584
|
+
}
|
|
1585
|
+
}
|
|
1586
|
+
}
|
|
1587
|
+
function openVaultDatabase(dataDir) {
|
|
1588
|
+
const path = join5(dataDir, "vault.db");
|
|
1589
|
+
mkdirSync5(dataDir, { recursive: true });
|
|
1590
|
+
const database = new Database(path, { create: true });
|
|
1591
|
+
chmodSync2(path, 384);
|
|
1592
|
+
initializeVaultDatabase(database);
|
|
1593
|
+
return database;
|
|
1594
|
+
}
|
|
1595
|
+
function activeVaultDatabase() {
|
|
1596
|
+
if (!vaultDb)
|
|
1597
|
+
vaultDb = openVaultDatabase(DATA_DIR);
|
|
1598
|
+
return vaultDb;
|
|
1599
|
+
}
|
|
1600
|
+
var VAULT_VALUE_MAX_BYTES = 64 * 1024;
|
|
1601
|
+
function normalizeVaultKey(key) {
|
|
1602
|
+
return key.trim().toUpperCase();
|
|
1603
|
+
}
|
|
1604
|
+
function decryptRow(userId, key, storedValue) {
|
|
1605
|
+
const database = activeVaultDatabase();
|
|
1606
|
+
const decoded = decryptVaultValue(userId, key, storedValue, vaultMasterKey);
|
|
1607
|
+
if (decoded.legacyPlaintext) {
|
|
1608
|
+
database.prepare("UPDATE vault SET value = ? WHERE user_id = ? AND key = ? AND value = ?").run(encryptVaultValue(userId, key, decoded.value, vaultMasterKey), userId, key, storedValue);
|
|
1609
|
+
}
|
|
1610
|
+
return decoded.value;
|
|
1611
|
+
}
|
|
1612
|
+
function vaultListWithValues(userId) {
|
|
1613
|
+
const rows = activeVaultDatabase().prepare("SELECT key, description, value FROM vault WHERE user_id = ? ORDER BY key").all(userId);
|
|
1614
|
+
return rows.map((row) => ({
|
|
1615
|
+
key: row.key,
|
|
1616
|
+
description: row.description,
|
|
1617
|
+
value: decryptRow(userId, row.key, row.value)
|
|
1618
|
+
}));
|
|
1619
|
+
}
|
|
1620
|
+
function vaultSubstituteDetailed(userId, text) {
|
|
1621
|
+
const entries = new Map(vaultListWithValues(userId).map((entry) => [entry.key, entry.value]));
|
|
1622
|
+
const usedKeys = new Set;
|
|
1623
|
+
const substituted = text.replace(/\{\{([^}]+)\}\}/g, (match, rawKey) => {
|
|
1624
|
+
const key = normalizeVaultKey(rawKey);
|
|
1625
|
+
const value = entries.get(key);
|
|
1626
|
+
if (value === undefined)
|
|
1627
|
+
return match;
|
|
1628
|
+
usedKeys.add(key);
|
|
1629
|
+
return value;
|
|
1630
|
+
});
|
|
1631
|
+
return { text: substituted, usedKeys: [...usedKeys] };
|
|
1632
|
+
}
|
|
1633
|
+
function encodedSecretForms(value) {
|
|
1634
|
+
const forms = new Set([
|
|
1635
|
+
value,
|
|
1636
|
+
encodeURIComponent(value),
|
|
1637
|
+
Buffer.from(value, "utf8").toString("base64"),
|
|
1638
|
+
Buffer.from(value, "utf8").toString("base64url"),
|
|
1639
|
+
Buffer.from(value, "utf8").toString("hex")
|
|
1640
|
+
]);
|
|
1641
|
+
forms.delete("");
|
|
1642
|
+
return [...forms].sort((a, b) => b.length - a.length);
|
|
1643
|
+
}
|
|
1644
|
+
function redactVaultSecrets(userId, text) {
|
|
1645
|
+
const candidates = vaultListWithValues(userId).flatMap((entry) => encodedSecretForms(entry.value).map((form) => ({ form, key: entry.key }))).sort((a, b) => b.form.length - a.form.length || a.key.localeCompare(b.key));
|
|
1646
|
+
if (candidates.length === 0)
|
|
1647
|
+
return text;
|
|
1648
|
+
const candidatesByFirstCharacter = new Map;
|
|
1649
|
+
for (const candidate of candidates) {
|
|
1650
|
+
const first = candidate.form[0];
|
|
1651
|
+
if (!first)
|
|
1652
|
+
continue;
|
|
1653
|
+
const bucket = candidatesByFirstCharacter.get(first) ?? [];
|
|
1654
|
+
bucket.push(candidate);
|
|
1655
|
+
candidatesByFirstCharacter.set(first, bucket);
|
|
1656
|
+
}
|
|
1657
|
+
let redacted = "";
|
|
1658
|
+
let offset = 0;
|
|
1659
|
+
while (offset < text.length) {
|
|
1660
|
+
const match = candidatesByFirstCharacter.get(text[offset] ?? "")?.find((candidate) => text.startsWith(candidate.form, offset));
|
|
1661
|
+
if (!match) {
|
|
1662
|
+
redacted += text[offset];
|
|
1663
|
+
offset += 1;
|
|
1664
|
+
continue;
|
|
1665
|
+
}
|
|
1666
|
+
redacted += `[REDACTED:${match.key}]`;
|
|
1667
|
+
offset += match.form.length;
|
|
1668
|
+
}
|
|
1669
|
+
return redacted;
|
|
1670
|
+
}
|
|
1671
|
+
|
|
1689
1672
|
// ../../packages/core/src/agents/execution-host.ts
|
|
1690
1673
|
var defaultHost = {
|
|
1691
1674
|
getMcpServersForQuery,
|
|
@@ -2265,7 +2248,7 @@ import { createRequire } from "module";
|
|
|
2265
2248
|
import { dirname as dirname4, join as join6 } from "path";
|
|
2266
2249
|
|
|
2267
2250
|
// ../../packages/core/src/version.ts
|
|
2268
|
-
var NEGOTIUM_VERSION = "0.1.
|
|
2251
|
+
var NEGOTIUM_VERSION = "0.1.22";
|
|
2269
2252
|
|
|
2270
2253
|
// ../../packages/core/src/agents/codex-native-multi-agent.ts
|
|
2271
2254
|
var NEGOTIUM_MODEL_CATALOG = "negotium-model-catalog.json";
|
|
@@ -3415,4 +3398,4 @@ export {
|
|
|
3415
3398
|
buildClaudeDisallowedTools
|
|
3416
3399
|
};
|
|
3417
3400
|
|
|
3418
|
-
//# debugId=
|
|
3401
|
+
//# debugId=82F6D5167080007664756E2164756E21
|