@ouro.bot/cli 0.1.0-alpha.1068 → 0.1.0-alpha.1069
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/changelog.json +6 -0
- package/deploy/unraid/sanctuary.ouro/bundle-meta.json +1 -1
- package/deploy/unraid/sanctuary.xml +1 -1
- package/dist/heart/daemon/agentic-repair.js +5 -4
- package/dist/heart/daemon/cli-defaults.js +6 -6
- package/dist/heart/daemon/cli-exec.js +15 -5
- package/dist/heart/daemon/cli-parse.js +1 -2
- package/dist/heart/daemon/daemon-cli.js +2 -2
- package/dist/heart/daemon/daemon-entry.js +6 -5
- package/dist/heart/daemon/daemon.js +5 -4
- package/dist/heart/daemon/sanctuary-scheduler-origin.js +2 -2
- package/dist/heart/failure-reports.js +7 -1
- package/dist/heart/frontend-session-service.js +63 -4
- package/dist/heart/shepherd/operations.js +3 -1
- package/dist/heart/versioning/update-checker.js +6 -34
- package/dist/heart/versioning/update-hooks.js +7 -1
- package/dist/repertoire/tool-arguments.js +3 -5
- package/dist/senses/shepherd/surface.js +5 -3
- package/dist/senses/telegram-identity-key.js +143 -0
- package/dist/senses/telegram.js +8 -100
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
package/changelog.json
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"_note": "This changelog is maintained as part of the PR/version-bump workflow. Agent-curated, not auto-generated. Agents read this file directly via read_file to understand what changed between versions.",
|
|
3
3
|
"versions": [
|
|
4
|
+
{
|
|
5
|
+
"version": "0.1.0-alpha.1069",
|
|
6
|
+
"changes": [
|
|
7
|
+
"Lean module graph: ouro --version loads 236 modules instead of 881, an agentless daemon 247 instead of 860"
|
|
8
|
+
]
|
|
9
|
+
},
|
|
4
10
|
{
|
|
5
11
|
"version": "0.1.0-alpha.1068",
|
|
6
12
|
"changes": [
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<?xml version="1.0"?>
|
|
2
2
|
<Container version="2">
|
|
3
3
|
<Name>ouro-butler</Name>
|
|
4
|
-
<Repository>ghcr.io/ourostack/ouroboros-butler:0.1.0-alpha.
|
|
4
|
+
<Repository>ghcr.io/ourostack/ouroboros-butler:0.1.0-alpha.1069</Repository>
|
|
5
5
|
<Registry>https://github.com/ourostack/ouroboros/pkgs/container/ouroboros-butler</Registry>
|
|
6
6
|
<Network>host</Network>
|
|
7
7
|
<Shell>sh</Shell>
|
|
@@ -50,7 +50,6 @@ const path = __importStar(require("path"));
|
|
|
50
50
|
const runtime_1 = require("../../nerves/runtime");
|
|
51
51
|
const interactive_repair_1 = require("./interactive-repair");
|
|
52
52
|
const identity_1 = require("../identity");
|
|
53
|
-
const provider_ping_1 = require("../provider-ping");
|
|
54
53
|
const readiness_repair_1 = require("./readiness-repair");
|
|
55
54
|
function buildSystemPrompt(degraded) {
|
|
56
55
|
const agentList = degraded
|
|
@@ -109,12 +108,14 @@ function discoveredProviderModel(provider) {
|
|
|
109
108
|
const model = provider.providerConfig.model?.trim();
|
|
110
109
|
return model ? model : undefined;
|
|
111
110
|
}
|
|
112
|
-
function createAgenticDiagnosisProviderRuntime(provider) {
|
|
111
|
+
async function createAgenticDiagnosisProviderRuntime(provider) {
|
|
112
|
+
// The provider SDKs load only when a diagnosis actually runs.
|
|
113
|
+
const { createProviderRuntimeForConfig } = await Promise.resolve().then(() => __importStar(require("../provider-ping")));
|
|
113
114
|
const config = {
|
|
114
115
|
...provider.providerConfig,
|
|
115
116
|
...provider.credentials,
|
|
116
117
|
};
|
|
117
|
-
return
|
|
118
|
+
return createProviderRuntimeForConfig(provider.provider, config, {
|
|
118
119
|
model: discoveredProviderModel(provider),
|
|
119
120
|
});
|
|
120
121
|
}
|
|
@@ -144,7 +145,7 @@ function buildSystemPromptWithRepairGuide(degraded, repairGuide) {
|
|
|
144
145
|
}
|
|
145
146
|
async function tryAgenticDiagnosis(degraded, provider, deps) {
|
|
146
147
|
const logsTail = deps.readDaemonLogsTail();
|
|
147
|
-
const runtime = deps.createProviderRuntime(provider);
|
|
148
|
+
const runtime = await deps.createProviderRuntime(provider);
|
|
148
149
|
// Layer 3: prepend RepairGuide bundle content when present. Loader
|
|
149
150
|
// returns null on missing bundle / I/O error — caller silently falls back
|
|
150
151
|
// to today's pre-RepairGuide prompt.
|
|
@@ -63,7 +63,6 @@ const skill_management_installer_1 = require("./skill-management-installer");
|
|
|
63
63
|
const hatch_flow_1 = require("../hatch/hatch-flow");
|
|
64
64
|
const specialist_orchestrator_1 = require("../hatch/specialist-orchestrator");
|
|
65
65
|
const specialist_prompt_1 = require("../hatch/specialist-prompt");
|
|
66
|
-
const specialist_tools_1 = require("../hatch/specialist-tools");
|
|
67
66
|
const runtime_mode_1 = require("./runtime-mode");
|
|
68
67
|
const agent_discovery_1 = require("./agent-discovery");
|
|
69
68
|
const bundle_manifest_1 = require("../../mind/bundle-manifest");
|
|
@@ -730,10 +729,11 @@ async function defaultRunSerpentGuide() {
|
|
|
730
729
|
provider: providerRaw,
|
|
731
730
|
model: providerConfig.model ?? "",
|
|
732
731
|
});
|
|
733
|
-
// Build specialist tools
|
|
734
|
-
const
|
|
732
|
+
// Build specialist tools (loaded here: they import the agent tool registry)
|
|
733
|
+
const { getSpecialistTools, createSpecialistExecTool, parseAdoptionResult } = await Promise.resolve().then(() => __importStar(require("../hatch/specialist-tools")));
|
|
734
|
+
const specialistTools = getSpecialistTools();
|
|
735
735
|
let lastAdoptionError = null;
|
|
736
|
-
const specialistExecTool =
|
|
736
|
+
const specialistExecTool = createSpecialistExecTool({
|
|
737
737
|
tempDir,
|
|
738
738
|
credentials: selectedCredentialPayload,
|
|
739
739
|
provider: providerRaw,
|
|
@@ -752,7 +752,7 @@ async function defaultRunSerpentGuide() {
|
|
|
752
752
|
exitOnToolCall: "complete_adoption",
|
|
753
753
|
// A failed adoption goes back to the guide, which explains it and can retry.
|
|
754
754
|
exitOnToolResult: (toolResult) => {
|
|
755
|
-
const outcome =
|
|
755
|
+
const outcome = parseAdoptionResult(toolResult);
|
|
756
756
|
lastAdoptionError = outcome.ok ? null : outcome.error;
|
|
757
757
|
return outcome.ok;
|
|
758
758
|
},
|
|
@@ -766,7 +766,7 @@ async function defaultRunSerpentGuide() {
|
|
|
766
766
|
],
|
|
767
767
|
});
|
|
768
768
|
if (result.exitReason === "tool_exit" && result.toolResult) {
|
|
769
|
-
const outcome =
|
|
769
|
+
const outcome = parseAdoptionResult(result.toolResult);
|
|
770
770
|
if (outcome.ok)
|
|
771
771
|
return outcome.agentName;
|
|
772
772
|
lastAdoptionError = outcome.error;
|
|
@@ -38,7 +38,11 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
38
38
|
return result;
|
|
39
39
|
};
|
|
40
40
|
})();
|
|
41
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
42
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
43
|
+
};
|
|
41
44
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
exports.pingGithubCopilotModel = void 0;
|
|
42
46
|
exports.runMcpServeCliLifecycle = runMcpServeCliLifecycle;
|
|
43
47
|
exports.summarizeDaemonStartupFailure = summarizeDaemonStartupFailure;
|
|
44
48
|
exports.writeSyncProbeSummary = writeSyncProbeSummary;
|
|
@@ -60,7 +64,10 @@ const crypto_1 = require("crypto");
|
|
|
60
64
|
const fs = __importStar(require("fs"));
|
|
61
65
|
const os = __importStar(require("os"));
|
|
62
66
|
const path = __importStar(require("path"));
|
|
63
|
-
|
|
67
|
+
// semver's index loads the whole package; these load one function each.
|
|
68
|
+
const gt_1 = __importDefault(require("semver/functions/gt"));
|
|
69
|
+
const valid_1 = __importDefault(require("semver/functions/valid"));
|
|
70
|
+
const semver = { gt: gt_1.default, valid: valid_1.default };
|
|
64
71
|
const identity_1 = require("../identity");
|
|
65
72
|
const runtime_1 = require("../../nerves/runtime");
|
|
66
73
|
const friends_1 = require("@ouro.bot/friends");
|
|
@@ -124,7 +131,6 @@ const daemon_bootstrap_startup_1 = require("./daemon-bootstrap-startup");
|
|
|
124
131
|
const stale_bundle_prune_1 = require("./stale-bundle-prune");
|
|
125
132
|
const up_progress_1 = require("./up-progress");
|
|
126
133
|
const provider_ping_progress_1 = require("./provider-ping-progress");
|
|
127
|
-
const provider_ping_1 = require("../provider-ping");
|
|
128
134
|
const provider_readiness_cache_1 = require("../provider-readiness-cache");
|
|
129
135
|
const agent_discovery_1 = require("./agent-discovery");
|
|
130
136
|
const agent_home_1 = require("./agent-home");
|
|
@@ -138,6 +144,10 @@ const vault_items_1 = require("./vault-items");
|
|
|
138
144
|
const mcp_canary_1 = require("./mcp-canary");
|
|
139
145
|
const portable_git_1 = require("./portable-git");
|
|
140
146
|
const bluebubbles_cli_integration_1 = require("./bluebubbles-cli-integration");
|
|
147
|
+
const pingProvider = async (...args) => (await Promise.resolve().then(() => __importStar(require("../provider-ping")))).pingProvider(...args);
|
|
148
|
+
/** Loads the provider SDKs only when a model is actually pinged. */
|
|
149
|
+
const pingGithubCopilotModel = async (...args) => (await Promise.resolve().then(() => __importStar(require("../provider-ping")))).pingGithubCopilotModel(...args);
|
|
150
|
+
exports.pingGithubCopilotModel = pingGithubCopilotModel;
|
|
141
151
|
// ── ensureDaemonRunning ──
|
|
142
152
|
const DEFAULT_DAEMON_STARTUP_TIMEOUT_MS = 60_000;
|
|
143
153
|
const DEFAULT_DAEMON_STARTUP_POLL_INTERVAL_MS = 500;
|
|
@@ -5608,7 +5618,7 @@ async function executeProviderUse(command, deps, options = {}) {
|
|
|
5608
5618
|
}
|
|
5609
5619
|
progress?.completePhase(`reading ${command.provider} credentials`, "found");
|
|
5610
5620
|
progress?.startPhase(`checking ${command.provider} / ${command.model}`);
|
|
5611
|
-
const pingResult = await
|
|
5621
|
+
const pingResult = await pingProvider(command.provider, credentialPingConfig(credential.record), {
|
|
5612
5622
|
model: command.model,
|
|
5613
5623
|
attemptPolicy: { baseDelayMs: 0 },
|
|
5614
5624
|
sleep: deps.sleep,
|
|
@@ -5669,7 +5679,7 @@ async function executeProviderCheck(command, deps) {
|
|
|
5669
5679
|
}
|
|
5670
5680
|
progress.completePhase(`reading ${binding.provider} credentials`, "found");
|
|
5671
5681
|
progress.startPhase(`checking ${binding.provider} / ${binding.model}`);
|
|
5672
|
-
const pingResult = await
|
|
5682
|
+
const pingResult = await pingProvider(binding.provider, credentialPingConfig(credential.record), {
|
|
5673
5683
|
model: binding.model,
|
|
5674
5684
|
attemptPolicy: { baseDelayMs: 0 },
|
|
5675
5685
|
sleep: deps.sleep,
|
|
@@ -6132,7 +6142,7 @@ async function executeLegacyConfigModel(command, deps) {
|
|
|
6132
6142
|
// Catalog validation failed; the live ping below gives the actionable result.
|
|
6133
6143
|
}
|
|
6134
6144
|
progress?.startPhase(`checking ${command.modelName}`);
|
|
6135
|
-
const pingResult = await (0,
|
|
6145
|
+
const pingResult = await (0, exports.pingGithubCopilotModel)(baseUrl, githubToken, command.modelName, fetchFn);
|
|
6136
6146
|
progress?.completePhase(`checking ${command.modelName}`, pingResult.ok ? "ok" : "failed");
|
|
6137
6147
|
if (!pingResult.ok) {
|
|
6138
6148
|
const message = `model '${command.modelName}' ping failed: ${pingResult.error}\nrun \`ouro config models --agent ${command.agent}\` to see available models.`;
|
|
@@ -52,7 +52,6 @@ const fs = __importStar(require("fs"));
|
|
|
52
52
|
const path = __importStar(require("path"));
|
|
53
53
|
const friends_1 = require("@ouro.bot/friends");
|
|
54
54
|
const cli_help_1 = require("./cli-help");
|
|
55
|
-
const surface_1 = require("../../senses/shepherd/surface");
|
|
56
55
|
const operations_1 = require("../shepherd/operations");
|
|
57
56
|
const local_audio_control_1 = require("../../senses/voice/local-audio-control");
|
|
58
57
|
const cli_desk_1 = require("./cli-desk");
|
|
@@ -3416,7 +3415,7 @@ function parseOuroCommand(args) {
|
|
|
3416
3415
|
}
|
|
3417
3416
|
const agent = values.get("--agent");
|
|
3418
3417
|
const session = values.get("--session");
|
|
3419
|
-
if (!agent || !/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(agent) || (session !== undefined && !
|
|
3418
|
+
if (!agent || !/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(agent) || (session !== undefined && !operations_1.SHEPHERD_UUID.test(session)))
|
|
3420
3419
|
throw new Error(usage);
|
|
3421
3420
|
return { kind: "shepherd.chat", agent, ...(session ? { session } : {}), ...(values.has("--web") ? { web: true } : {}) };
|
|
3422
3421
|
}
|
|
@@ -24,8 +24,8 @@ Object.defineProperty(exports, "runOuroCli", { enumerable: true, get: function (
|
|
|
24
24
|
Object.defineProperty(exports, "ensureDaemonRunning", { enumerable: true, get: function () { return cli_exec_1.ensureDaemonRunning; } });
|
|
25
25
|
Object.defineProperty(exports, "listGithubCopilotModels", { enumerable: true, get: function () { return cli_exec_1.listGithubCopilotModels; } });
|
|
26
26
|
Object.defineProperty(exports, "summarizeDaemonStartupFailure", { enumerable: true, get: function () { return cli_exec_1.summarizeDaemonStartupFailure; } });
|
|
27
|
-
var
|
|
28
|
-
Object.defineProperty(exports, "pingGithubCopilotModel", { enumerable: true, get: function () { return
|
|
27
|
+
var cli_exec_2 = require("./cli-exec");
|
|
28
|
+
Object.defineProperty(exports, "pingGithubCopilotModel", { enumerable: true, get: function () { return cli_exec_2.pingGithubCopilotModel; } });
|
|
29
29
|
// ── Defaults ──
|
|
30
30
|
var cli_defaults_1 = require("./cli-defaults");
|
|
31
31
|
Object.defineProperty(exports, "createDefaultOuroCliDeps", { enumerable: true, get: function () { return cli_defaults_1.createDefaultOuroCliDeps; } });
|
|
@@ -81,11 +81,10 @@ const machine_identity_1 = require("../machine-identity");
|
|
|
81
81
|
const container_credential_bootstrap_1 = require("./container-credential-bootstrap");
|
|
82
82
|
const daemon_bootstrap_startup_1 = require("./daemon-bootstrap-startup");
|
|
83
83
|
const sanctuary_package_management_1 = require("./sanctuary-package-management");
|
|
84
|
-
const sanctuary_health_runner_1 = require("../../senses/sanctuary-health-runner");
|
|
85
84
|
const sanctuary_acceptance_marker_1 = require("./sanctuary-acceptance-marker");
|
|
86
85
|
const sanctuary_scheduler_liveness_1 = require("./sanctuary-scheduler-liveness");
|
|
87
86
|
const sanctuary_scheduler_origin_1 = require("./sanctuary-scheduler-origin");
|
|
88
|
-
const
|
|
87
|
+
const telegram_identity_key_1 = require("../../senses/telegram-identity-key");
|
|
89
88
|
const sync_health_1 = require("../sync-health");
|
|
90
89
|
const sync_1 = require("../sync");
|
|
91
90
|
const presence_daemon_1 = require("./presence-daemon");
|
|
@@ -519,7 +518,7 @@ const daemon = new daemon_1.OuroDaemon({
|
|
|
519
518
|
const marker = (0, sanctuary_acceptance_marker_1.readSanctuaryAcceptanceMarker)("sanctuary");
|
|
520
519
|
return (0, sanctuary_scheduler_origin_1.verifySanctuarySchedulerFireCommand)(command, {
|
|
521
520
|
childPid: supercronicSupervisor.authenticatedSnapshot("habit:sanctuary").childPid,
|
|
522
|
-
identityKey: (0,
|
|
521
|
+
identityKey: (0, telegram_identity_key_1.readOrCreateTelegramIdentityKey)(path.join((0, identity_1.getAgentBundlesRoot)(), "sanctuary.ouro")),
|
|
523
522
|
scenarioHandleDigest: marker?.label === "unit-16f-cron-fingerprint" ? marker.scenarioHandleDigest : null, now: () => new Date(),
|
|
524
523
|
readFile: (target) => fs.readFileSync(target, "utf8"), readLink: (target) => fs.readlinkSync(target),
|
|
525
524
|
});
|
|
@@ -534,7 +533,9 @@ const daemon = new daemon_1.OuroDaemon({
|
|
|
534
533
|
const before = schedulerScenario ? (0, sanctuary_scheduler_liveness_1.readSanctuaryHealthCursor)(agentRoot) : null;
|
|
535
534
|
let providerInvocationCount = 0;
|
|
536
535
|
let privateTurnCount = 0;
|
|
537
|
-
|
|
536
|
+
// Loaded here, not at startup: it imports Sanctuary's tool registry.
|
|
537
|
+
const { runSanctuaryHealthHabit } = await Promise.resolve().then(() => __importStar(require("../../senses/sanctuary-health-runner")));
|
|
538
|
+
const result = await runSanctuaryHealthHabit(agent, {
|
|
538
539
|
submitEvidence: async (input) => {
|
|
539
540
|
const response = await daemon.handleCommand({ kind: "external.event.submit", ...input });
|
|
540
541
|
if (!response.ok)
|
|
@@ -562,7 +563,7 @@ const daemon = new daemon_1.OuroDaemon({
|
|
|
562
563
|
providerInvocationCount,
|
|
563
564
|
privateTurnCount,
|
|
564
565
|
schedulerOrigin,
|
|
565
|
-
identityKey: (0,
|
|
566
|
+
identityKey: (0, telegram_identity_key_1.readOrCreateTelegramIdentityKey)(agentRoot),
|
|
566
567
|
});
|
|
567
568
|
}
|
|
568
569
|
return result;
|
|
@@ -87,7 +87,6 @@ const turn_execution_lease_1 = require("../turn-execution-lease");
|
|
|
87
87
|
const frontend_session_service_1 = require("../frontend-session-service");
|
|
88
88
|
const frontend_socket_1 = require("../frontend-socket");
|
|
89
89
|
const frontend_journal_1 = require("../frontend-journal");
|
|
90
|
-
const frontend_approval_runtime_1 = require("../frontend-approval-runtime");
|
|
91
90
|
const PIDFILE_PATH = path.join(os.homedir(), ".ouro-cli", "daemon.pids");
|
|
92
91
|
/**
|
|
93
92
|
* Defense-in-depth: detect if we're running under vitest. The pidfile lives
|
|
@@ -671,10 +670,12 @@ class OuroDaemon {
|
|
|
671
670
|
const frontendAgentRoot = (agent) => path.join(this.bundlesRoot, `${agent}.ouro`);
|
|
672
671
|
this.frontendSessionService = options.frontendSessionService ?? new frontend_session_service_1.FrontendSessionService({
|
|
673
672
|
journal: new frontend_journal_1.FrontendJournalStore({ agentRoot: frontendAgentRoot }),
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
673
|
+
/* v8 ignore start -- production wiring: frontend authority tests cover the runtime and the lazy wrapper @preserve */
|
|
674
|
+
authority: (0, frontend_session_service_1.lazyFrontendAuthority)(() => {
|
|
675
|
+
const { createFrontendApprovalRuntime, settleFrontendApproval } = require("../frontend-approval-runtime");
|
|
676
|
+
return createFrontendApprovalRuntime({ agentRoot: frontendAgentRoot, settleApproval: settleFrontendApproval });
|
|
677
677
|
}),
|
|
678
|
+
/* v8 ignore stop */
|
|
678
679
|
});
|
|
679
680
|
this.frontendSocketServerFactory = options.frontendSocketServerFactory ?? frontend_socket_1.startFrontendSocketServer;
|
|
680
681
|
this.privateRuntimePolicyDeps = options.privateRuntimePolicyDeps ?? {};
|
|
@@ -40,7 +40,7 @@ const node_crypto_1 = require("node:crypto");
|
|
|
40
40
|
const fs = __importStar(require("node:fs"));
|
|
41
41
|
const identity_1 = require("../identity");
|
|
42
42
|
const runtime_1 = require("../../nerves/runtime");
|
|
43
|
-
const
|
|
43
|
+
const telegram_identity_key_1 = require("../../senses/telegram-identity-key");
|
|
44
44
|
const sanctuary_acceptance_marker_1 = require("./sanctuary-acceptance-marker");
|
|
45
45
|
const CRONTAB_PATH = "/home/ouro/.ouro-cli/scheduler/sanctuary.crontab";
|
|
46
46
|
const SUPERCRONIC = "/usr/local/bin/supercronic";
|
|
@@ -80,7 +80,7 @@ function defaultSanctuarySchedulerOriginDeps(agentRoot = (0, identity_1.getAgent
|
|
|
80
80
|
return {
|
|
81
81
|
platform: process.platform, pid: process.pid, ppid: process.ppid, now: () => new Date(),
|
|
82
82
|
readFile: (target) => fs.readFileSync(target, "utf8"), readLink: (target) => fs.readlinkSync(target),
|
|
83
|
-
identityKey: () => (0,
|
|
83
|
+
identityKey: () => (0, telegram_identity_key_1.readOrCreateTelegramIdentityKey)(agentRoot), marker: markerReader, randomId: () => (0, node_crypto_1.randomUUID)(),
|
|
84
84
|
};
|
|
85
85
|
}
|
|
86
86
|
function createSanctuarySchedulerFireCommand(command, deps = defaultSanctuarySchedulerOriginDeps()) {
|
|
@@ -32,6 +32,9 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
32
32
|
return result;
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
35
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
39
|
exports.CLOSED_REPORT_RETENTION_MS = exports.REPORTS_PER_ORIGIN_DAY = exports.REPORTS_PER_ORIGIN_HOUR = exports.REPORTS_PER_DAY = exports.REPORTS_PER_HOUR = void 0;
|
|
37
40
|
exports.reportsDir = reportsDir;
|
|
@@ -48,7 +51,10 @@ exports.confirmResolvedReports = confirmResolvedReports;
|
|
|
48
51
|
const node_crypto_1 = require("node:crypto");
|
|
49
52
|
const fs = __importStar(require("node:fs"));
|
|
50
53
|
const path = __importStar(require("node:path"));
|
|
51
|
-
|
|
54
|
+
// semver's index loads the whole package; these load one function each.
|
|
55
|
+
const gte_1 = __importDefault(require("semver/functions/gte"));
|
|
56
|
+
const valid_1 = __importDefault(require("semver/functions/valid"));
|
|
57
|
+
const semver = { gte: gte_1.default, valid: valid_1.default };
|
|
52
58
|
const a2a_client_1 = require("@ouro.bot/friends/a2a-client");
|
|
53
59
|
const escalation_grants_1 = require("../a2a/escalation-grants");
|
|
54
60
|
const outbox_store_1 = require("../a2a/outbox-store");
|
|
@@ -1,13 +1,70 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
36
|
exports.FrontendSessionService = exports.FrontendTurnConflictError = exports.FrontendSessionConflictError = void 0;
|
|
4
|
-
|
|
37
|
+
exports.lazyFrontendAuthority = lazyFrontendAuthority;
|
|
5
38
|
const runtime_1 = require("../nerves/runtime");
|
|
6
|
-
const surface_1 = require("../senses/shepherd/surface");
|
|
7
39
|
const frontend_turn_errors_1 = require("./frontend-turn-errors");
|
|
8
40
|
var frontend_turn_errors_2 = require("./frontend-turn-errors");
|
|
9
41
|
Object.defineProperty(exports, "FrontendSessionConflictError", { enumerable: true, get: function () { return frontend_turn_errors_2.FrontendSessionConflictError; } });
|
|
10
42
|
Object.defineProperty(exports, "FrontendTurnConflictError", { enumerable: true, get: function () { return frontend_turn_errors_2.FrontendTurnConflictError; } });
|
|
43
|
+
/**
|
|
44
|
+
* An authority runtime created on first use. Its pending approvals live only
|
|
45
|
+
* in memory, so before anything has used it there is nothing pending, nothing
|
|
46
|
+
* to resolve and nothing to cancel, exactly as a fresh runtime would answer.
|
|
47
|
+
* The daemon passes one so that serving no frontend turn never loads the
|
|
48
|
+
* approval runtime and the turn engine it imports.
|
|
49
|
+
*/
|
|
50
|
+
function lazyFrontendAuthority(create) {
|
|
51
|
+
let runtime = null;
|
|
52
|
+
const get = () => {
|
|
53
|
+
if (!runtime) {
|
|
54
|
+
runtime = create();
|
|
55
|
+
(0, runtime_1.emitNervesEvent)({ component: "heart", event: "heart.frontend_authority_loaded", message: "frontend approval runtime loaded on first use" });
|
|
56
|
+
}
|
|
57
|
+
return runtime;
|
|
58
|
+
};
|
|
59
|
+
return {
|
|
60
|
+
approvalCoordinatorFactory: (input) => get().approvalCoordinatorFactory(input),
|
|
61
|
+
resumeApproval: (input) => get().resumeApproval(input),
|
|
62
|
+
resolvePermission: (requestId, optionId) => runtime?.resolvePermission(requestId, optionId) ?? false,
|
|
63
|
+
cancelTurn: (turnId) => { runtime?.cancelTurn(turnId); },
|
|
64
|
+
pendingPermissions: (ref) => runtime?.pendingPermissions(ref) ?? [],
|
|
65
|
+
close: () => { runtime?.close(); },
|
|
66
|
+
};
|
|
67
|
+
}
|
|
11
68
|
const JOURNALED_FRONTEND_EVENTS = new Set([
|
|
12
69
|
"assistant_delivery",
|
|
13
70
|
"tool_started",
|
|
@@ -32,10 +89,12 @@ class FrontendSessionService {
|
|
|
32
89
|
closed = false;
|
|
33
90
|
shepherdTargets;
|
|
34
91
|
constructor(options = {}) {
|
|
35
|
-
|
|
92
|
+
// The turn engine and Shepherd load on first use: a daemon that serves no
|
|
93
|
+
// frontend turn never loads the model SDKs and tool registry they import.
|
|
94
|
+
this.runner = options.runner ?? (async (turn) => (await Promise.resolve().then(() => __importStar(require("../senses/shared-turn")))).runSenseTurn(turn));
|
|
36
95
|
this.journal = options.journal ?? null;
|
|
37
96
|
this.authority = options.authority ?? null;
|
|
38
|
-
this.shepherdTargets = options.shepherdTargets ??
|
|
97
|
+
this.shepherdTargets = options.shepherdTargets ?? (async (agent, friendId, composerTty) => (await Promise.resolve().then(() => __importStar(require("../senses/shepherd/surface")))).authorizedShepherdTargets(agent, friendId, composerTty));
|
|
39
98
|
}
|
|
40
99
|
listShepherdTargets(agent, friendId, composerTty) {
|
|
41
100
|
if (composerTty !== undefined && !/^\/dev\/[A-Za-z0-9/_-]{1,120}$/.test(composerTty))
|
|
@@ -33,9 +33,11 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.SHEPHERD_ADMIN_USAGE = void 0;
|
|
36
|
+
exports.SHEPHERD_ADMIN_USAGE = exports.SHEPHERD_UUID = void 0;
|
|
37
37
|
exports.parseShepherdOperation = parseShepherdOperation;
|
|
38
38
|
const path = __importStar(require("node:path"));
|
|
39
|
+
/** A Shepherd session id: a stable UUID. */
|
|
40
|
+
exports.SHEPHERD_UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
39
41
|
exports.SHEPHERD_ADMIN_USAGE = "Usage: ouro shepherd status|inspect|pause|resume|mandate grant|mandate revoke|reconcile|maintenance --agent <name> [operation options]; ouro shepherd chat --agent <name> [--session <UUID>] [--web]";
|
|
40
42
|
const nonempty = (value) => !!value && value === value.trim() && value.length <= 2000 && !/[\x00-\x1f\x7f-\x9f]/.test(value);
|
|
41
43
|
const absolute = (value) => path.isAbsolute(value) && path.normalize(value) === value;
|
|
@@ -1,43 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
35
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
6
|
exports.CLI_UPDATE_DIST_TAG = exports.CLI_UPDATE_CHECK_TIMEOUT_MS = void 0;
|
|
37
7
|
exports.checkForUpdate = checkForUpdate;
|
|
38
8
|
exports.startUpdateChecker = startUpdateChecker;
|
|
39
9
|
exports.stopUpdateChecker = stopUpdateChecker;
|
|
40
|
-
|
|
10
|
+
// semver's index loads the whole package; these load one function each.
|
|
11
|
+
const gt_1 = __importDefault(require("semver/functions/gt"));
|
|
12
|
+
const semver = { gt: gt_1.default };
|
|
41
13
|
const runtime_1 = require("../../nerves/runtime");
|
|
42
14
|
const DEFAULT_INTERVAL_MS = 30 * 60 * 1000; // 30 minutes
|
|
43
15
|
exports.CLI_UPDATE_CHECK_TIMEOUT_MS = 3_000;
|
|
@@ -32,6 +32,9 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
32
32
|
return result;
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
35
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
39
|
exports.registerUpdateHook = registerUpdateHook;
|
|
37
40
|
exports.getRegisteredHooks = getRegisteredHooks;
|
|
@@ -39,7 +42,10 @@ exports.clearRegisteredHooks = clearRegisteredHooks;
|
|
|
39
42
|
exports.applyPendingUpdates = applyPendingUpdates;
|
|
40
43
|
const fs = __importStar(require("fs"));
|
|
41
44
|
const path = __importStar(require("path"));
|
|
42
|
-
|
|
45
|
+
// semver's index loads the whole package; these load one function each.
|
|
46
|
+
const gte_1 = __importDefault(require("semver/functions/gte"));
|
|
47
|
+
const valid_1 = __importDefault(require("semver/functions/valid"));
|
|
48
|
+
const semver = { gte: gte_1.default, valid: valid_1.default };
|
|
43
49
|
const runtime_1 = require("../../nerves/runtime");
|
|
44
50
|
const _hooks = [];
|
|
45
51
|
function registerUpdateHook(hook) {
|
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.assertRelationshipToolOwner = assertRelationshipToolOwner;
|
|
7
4
|
exports.digestJson = digestJson;
|
|
@@ -9,7 +6,6 @@ exports.freezeToolValue = freezeToolValue;
|
|
|
9
6
|
exports.validateAdvertisedToolArguments = validateAdvertisedToolArguments;
|
|
10
7
|
const node_crypto_1 = require("node:crypto");
|
|
11
8
|
const node_path_1 = require("node:path");
|
|
12
|
-
const ajv_1 = __importDefault(require("ajv"));
|
|
13
9
|
const runtime_1 = require("../nerves/runtime");
|
|
14
10
|
function assertRelationshipToolOwner(ctx) {
|
|
15
11
|
if (ctx?.relationshipAuthorization && (typeof ctx.agentName !== "string" || ctx.agentName.length === 0
|
|
@@ -131,7 +127,9 @@ function validateAdvertisedToolArguments(rawArguments, schema) {
|
|
|
131
127
|
let validator = validators.get(schema);
|
|
132
128
|
try {
|
|
133
129
|
// Each snapshot owns its compiler registry; only the weak cache is shared.
|
|
134
|
-
|
|
130
|
+
// ajv (about 70 modules) loads with the first schema compiled, not with every process that imports this file.
|
|
131
|
+
const Ajv = require("ajv").default;
|
|
132
|
+
validator ??= new Ajv({
|
|
135
133
|
strict: true,
|
|
136
134
|
allErrors: true,
|
|
137
135
|
coerceTypes: false,
|
|
@@ -48,7 +48,9 @@ const shepherd_config_1 = require("../../heart/shepherd-config");
|
|
|
48
48
|
const tools_shepherd_1 = require("../../repertoire/tools-shepherd");
|
|
49
49
|
const host_1 = require("./host");
|
|
50
50
|
const runtime_1 = require("../../nerves/runtime");
|
|
51
|
-
|
|
51
|
+
var operations_1 = require("../../heart/shepherd/operations");
|
|
52
|
+
Object.defineProperty(exports, "SHEPHERD_UUID", { enumerable: true, get: function () { return operations_1.SHEPHERD_UUID; } });
|
|
53
|
+
const operations_2 = require("../../heart/shepherd/operations");
|
|
52
54
|
/** Resolve the CLI's local identity, but forbid the resolver's first-encounter creation/promotion. */
|
|
53
55
|
async function resolveExistingLocalOwner(store, username = (0, friends_1.machineOwnerUsername)()) {
|
|
54
56
|
if (!username)
|
|
@@ -93,7 +95,7 @@ function machineShepherdHost(agent) {
|
|
|
93
95
|
return (0, host_1.createShepherdHost)(connection.connection, { agentName: agent });
|
|
94
96
|
}
|
|
95
97
|
async function listShepherdTargets(host, composerTty) {
|
|
96
|
-
return (await host.list()).filter(session => session.agent &&
|
|
98
|
+
return (await host.list()).filter(session => session.agent && operations_2.SHEPHERD_UUID.test(session.id)
|
|
97
99
|
&& (!composerTty || (session.tty && session.tty.replace(/^\/dev\//, "") !== composerTty.replace(/^\/dev\//, "")))).map(session => Object.freeze({
|
|
98
100
|
id: session.id,
|
|
99
101
|
host: "cmux",
|
|
@@ -106,7 +108,7 @@ async function listShepherdTargets(host, composerTty) {
|
|
|
106
108
|
}));
|
|
107
109
|
}
|
|
108
110
|
async function validateShepherdTarget(host, id) {
|
|
109
|
-
if (!
|
|
111
|
+
if (!operations_2.SHEPHERD_UUID.test(id))
|
|
110
112
|
throw new Error("Shepherd session must be a stable UUID");
|
|
111
113
|
const matches = (await listShepherdTargets(host)).filter(target => target.id.toLowerCase() === id.toLowerCase());
|
|
112
114
|
if (matches.length !== 1)
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.canonicalTelegramIdentityKey = canonicalTelegramIdentityKey;
|
|
37
|
+
exports.openSecureTelegramDirectory = openSecureTelegramDirectory;
|
|
38
|
+
exports.readOrCreateTelegramIdentityKey = readOrCreateTelegramIdentityKey;
|
|
39
|
+
const node_crypto_1 = require("node:crypto");
|
|
40
|
+
const node_fs_1 = require("node:fs");
|
|
41
|
+
const path = __importStar(require("node:path"));
|
|
42
|
+
const runtime_1 = require("../nerves/runtime");
|
|
43
|
+
// The Telegram sense's opaque identity key, apart from the sense itself so the
|
|
44
|
+
// daemon can read it without loading the sense and the turn engine it imports.
|
|
45
|
+
const TELEGRAM_IDENTITY_KEY = /^[A-Za-z0-9_-]{43}$/u;
|
|
46
|
+
function canonicalTelegramIdentityKey(value) {
|
|
47
|
+
const key = value.trim();
|
|
48
|
+
if (!TELEGRAM_IDENTITY_KEY.test(key) || Buffer.from(key, "base64url").length !== 32) {
|
|
49
|
+
throw new Error("Telegram opaque identity key is invalid");
|
|
50
|
+
}
|
|
51
|
+
return key;
|
|
52
|
+
}
|
|
53
|
+
function errorCode(error) {
|
|
54
|
+
return error && typeof error === "object" && "code" in error && typeof error.code === "string" ? error.code : undefined;
|
|
55
|
+
}
|
|
56
|
+
function openSecureTelegramDirectory(directory, afterOpen) {
|
|
57
|
+
try {
|
|
58
|
+
const existing = (0, node_fs_1.lstatSync)(directory);
|
|
59
|
+
if (existing.isSymbolicLink())
|
|
60
|
+
throw new Error("Telegram state directory must not be a symbolic link");
|
|
61
|
+
if (!existing.isDirectory())
|
|
62
|
+
throw new Error("Telegram state directory is not a directory");
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
if (errorCode(error) !== "ENOENT")
|
|
66
|
+
throw error;
|
|
67
|
+
(0, node_fs_1.mkdirSync)(directory, { recursive: true, mode: 0o700 });
|
|
68
|
+
}
|
|
69
|
+
const handle = (0, node_fs_1.openSync)(directory, node_fs_1.constants.O_RDONLY | node_fs_1.constants.O_DIRECTORY | node_fs_1.constants.O_NOFOLLOW);
|
|
70
|
+
try {
|
|
71
|
+
(0, node_fs_1.fchmodSync)(handle, 0o700);
|
|
72
|
+
afterOpen?.(handle);
|
|
73
|
+
const metadata = (0, node_fs_1.fstatSync)(handle);
|
|
74
|
+
if (!metadata.isDirectory() || (metadata.mode & 0o777) !== 0o700) {
|
|
75
|
+
throw new Error("Telegram state directory permissions are invalid");
|
|
76
|
+
}
|
|
77
|
+
return handle;
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
(0, node_fs_1.closeSync)(handle);
|
|
81
|
+
throw error;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function readOrCreateTelegramIdentityKey(agentRoot, hooks = {}) {
|
|
85
|
+
const directory = path.join(agentRoot, "state", "senses", "telegram");
|
|
86
|
+
const keyPath = path.join(directory, "identity.key");
|
|
87
|
+
const directoryHandle = openSecureTelegramDirectory(directory, hooks.afterOpenDirectory);
|
|
88
|
+
const readKey = () => {
|
|
89
|
+
const handle = (0, node_fs_1.openSync)(keyPath, node_fs_1.constants.O_RDONLY | node_fs_1.constants.O_NOFOLLOW);
|
|
90
|
+
try {
|
|
91
|
+
const metadata = (0, node_fs_1.fstatSync)(handle);
|
|
92
|
+
if (!metadata.isFile() || (metadata.mode & 0o777) !== 0o600)
|
|
93
|
+
throw new Error("Telegram opaque identity key permissions are invalid");
|
|
94
|
+
return canonicalTelegramIdentityKey((0, node_fs_1.readFileSync)(handle, "utf8"));
|
|
95
|
+
}
|
|
96
|
+
finally {
|
|
97
|
+
(0, node_fs_1.closeSync)(handle);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
try {
|
|
101
|
+
try {
|
|
102
|
+
return readKey();
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
if (errorCode(error) !== "ENOENT")
|
|
106
|
+
throw error;
|
|
107
|
+
}
|
|
108
|
+
const key = (0, node_crypto_1.randomBytes)(32).toString("base64url");
|
|
109
|
+
hooks.beforeCreate?.(keyPath);
|
|
110
|
+
const temporaryPath = path.join(directory, `.identity.key.${(0, node_crypto_1.randomBytes)(12).toString("base64url")}.tmp`);
|
|
111
|
+
let temporaryHandle;
|
|
112
|
+
try {
|
|
113
|
+
temporaryHandle = (0, node_fs_1.openSync)(temporaryPath, node_fs_1.constants.O_CREAT | node_fs_1.constants.O_EXCL | node_fs_1.constants.O_WRONLY | node_fs_1.constants.O_NOFOLLOW, 0o600);
|
|
114
|
+
hooks.afterCreateTemporary?.(temporaryPath, keyPath);
|
|
115
|
+
(0, node_fs_1.writeFileSync)(temporaryHandle, `${key}\n`);
|
|
116
|
+
(0, node_fs_1.fsyncSync)(temporaryHandle);
|
|
117
|
+
(0, node_fs_1.closeSync)(temporaryHandle);
|
|
118
|
+
temporaryHandle = undefined;
|
|
119
|
+
hooks.beforePublish?.(temporaryPath, keyPath);
|
|
120
|
+
try {
|
|
121
|
+
(0, node_fs_1.linkSync)(temporaryPath, keyPath);
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
if (errorCode(error) !== "EEXIST")
|
|
125
|
+
throw error;
|
|
126
|
+
return readKey();
|
|
127
|
+
}
|
|
128
|
+
(0, node_fs_1.fsyncSync)(directoryHandle);
|
|
129
|
+
(0, runtime_1.emitNervesEvent)({ component: "senses", event: "senses.telegram_identity_key_created", message: "created the Telegram opaque identity key", meta: { agentRoot } });
|
|
130
|
+
return key;
|
|
131
|
+
}
|
|
132
|
+
finally {
|
|
133
|
+
if (temporaryHandle !== undefined)
|
|
134
|
+
(0, node_fs_1.closeSync)(temporaryHandle);
|
|
135
|
+
if ((0, node_fs_1.existsSync)(temporaryPath))
|
|
136
|
+
(0, node_fs_1.unlinkSync)(temporaryPath);
|
|
137
|
+
(0, node_fs_1.fsyncSync)(directoryHandle);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
finally {
|
|
141
|
+
(0, node_fs_1.closeSync)(directoryHandle);
|
|
142
|
+
}
|
|
143
|
+
}
|
package/dist/senses/telegram.js
CHANGED
|
@@ -33,6 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.readOrCreateTelegramIdentityKey = void 0;
|
|
36
37
|
exports.createSabQueueProtectiveStateVerifier = createSabQueueProtectiveStateVerifier;
|
|
37
38
|
exports.telegramAcceptanceAuditOwnerDigest = telegramAcceptanceAuditOwnerDigest;
|
|
38
39
|
exports.sanctuaryTelegramTurnReceiptDigest = sanctuaryTelegramTurnReceiptDigest;
|
|
@@ -42,7 +43,6 @@ exports.sanctuaryTelegramUnauthorizedDropMac = sanctuaryTelegramUnauthorizedDrop
|
|
|
42
43
|
exports.sanctuaryTelegramApprovalEvidenceMac = sanctuaryTelegramApprovalEvidenceMac;
|
|
43
44
|
exports.telegramBotIdFromToken = telegramBotIdFromToken;
|
|
44
45
|
exports.ownerDisplayName = ownerDisplayName;
|
|
45
|
-
exports.readOrCreateTelegramIdentityKey = readOrCreateTelegramIdentityKey;
|
|
46
46
|
exports.opaqueTelegramSubject = opaqueTelegramSubject;
|
|
47
47
|
exports.migrateTelegramFriendIdentity = migrateTelegramFriendIdentity;
|
|
48
48
|
exports.migrateTelegramSessionIdentity = migrateTelegramSessionIdentity;
|
|
@@ -74,6 +74,9 @@ const sanctuary_sab_1 = require("./sanctuary-sab");
|
|
|
74
74
|
const sanctuary_download_credit_presentation_1 = require("./sanctuary-download-credit-presentation");
|
|
75
75
|
const shared_turn_1 = require("./shared-turn");
|
|
76
76
|
const config_1 = require("../heart/config");
|
|
77
|
+
const telegram_identity_key_1 = require("./telegram-identity-key");
|
|
78
|
+
var telegram_identity_key_2 = require("./telegram-identity-key");
|
|
79
|
+
Object.defineProperty(exports, "readOrCreateTelegramIdentityKey", { enumerable: true, get: function () { return telegram_identity_key_2.readOrCreateTelegramIdentityKey; } });
|
|
77
80
|
const telegram_client_1 = require("./telegram-client");
|
|
78
81
|
const sanctuary_authority_resident_1 = require("./sanctuary-authority-resident");
|
|
79
82
|
const root_host_approval_runtime_1 = require("./root-host-approval-runtime");
|
|
@@ -128,7 +131,6 @@ function createSabQueueProtectiveStateVerifier(options = {}) {
|
|
|
128
131
|
}
|
|
129
132
|
const APPROVAL_EXPIRY_RECONCILE_INTERVAL_MS = 1_000;
|
|
130
133
|
const TELEGRAM_SUBJECT_DOMAIN = "ouroboros.telegram.subject.v1";
|
|
131
|
-
const TELEGRAM_IDENTITY_KEY = /^[A-Za-z0-9_-]{43}$/u;
|
|
132
134
|
const TELEGRAM_SUBJECT = /^tg_[A-Za-z0-9_-]{43}$/u;
|
|
133
135
|
const TELEGRAM_SUBJECT_INDEX = "identity-subjects.json";
|
|
134
136
|
const TELEGRAM_ACCEPTANCE_AUDIT_EVENTS = new Set([
|
|
@@ -411,108 +413,14 @@ function telegramBotIdFromToken(token) {
|
|
|
411
413
|
throw new Error("Telegram bot token does not expose a canonical numeric bot id");
|
|
412
414
|
return match[1];
|
|
413
415
|
}
|
|
414
|
-
function canonicalTelegramIdentityKey(value) {
|
|
415
|
-
const key = value.trim();
|
|
416
|
-
if (!TELEGRAM_IDENTITY_KEY.test(key) || Buffer.from(key, "base64url").length !== 32) {
|
|
417
|
-
throw new Error("Telegram opaque identity key is invalid");
|
|
418
|
-
}
|
|
419
|
-
return key;
|
|
420
|
-
}
|
|
421
416
|
function errorCode(error) {
|
|
422
417
|
return error && typeof error === "object" && "code" in error && typeof error.code === "string" ? error.code : undefined;
|
|
423
418
|
}
|
|
424
|
-
function openSecureTelegramDirectory(directory, afterOpen) {
|
|
425
|
-
try {
|
|
426
|
-
const existing = (0, node_fs_1.lstatSync)(directory);
|
|
427
|
-
if (existing.isSymbolicLink())
|
|
428
|
-
throw new Error("Telegram state directory must not be a symbolic link");
|
|
429
|
-
if (!existing.isDirectory())
|
|
430
|
-
throw new Error("Telegram state directory is not a directory");
|
|
431
|
-
}
|
|
432
|
-
catch (error) {
|
|
433
|
-
if (errorCode(error) !== "ENOENT")
|
|
434
|
-
throw error;
|
|
435
|
-
(0, node_fs_1.mkdirSync)(directory, { recursive: true, mode: 0o700 });
|
|
436
|
-
}
|
|
437
|
-
const handle = (0, node_fs_1.openSync)(directory, node_fs_1.constants.O_RDONLY | node_fs_1.constants.O_DIRECTORY | node_fs_1.constants.O_NOFOLLOW);
|
|
438
|
-
try {
|
|
439
|
-
(0, node_fs_1.fchmodSync)(handle, 0o700);
|
|
440
|
-
afterOpen?.(handle);
|
|
441
|
-
const metadata = (0, node_fs_1.fstatSync)(handle);
|
|
442
|
-
if (!metadata.isDirectory() || (metadata.mode & 0o777) !== 0o700) {
|
|
443
|
-
throw new Error("Telegram state directory permissions are invalid");
|
|
444
|
-
}
|
|
445
|
-
return handle;
|
|
446
|
-
}
|
|
447
|
-
catch (error) {
|
|
448
|
-
(0, node_fs_1.closeSync)(handle);
|
|
449
|
-
throw error;
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
419
|
/** The admitted owner's display name comes from the household's own house config. */
|
|
453
420
|
function ownerDisplayName(agentName) {
|
|
454
421
|
const { ownerName } = (0, sanctuary_house_1.readSanctuaryHouse)((0, identity_1.getAgentRoot)(agentName));
|
|
455
422
|
return ownerName === sanctuary_house_1.DEFAULT_SANCTUARY_HOUSE.ownerName ? "Owner" : ownerName;
|
|
456
423
|
}
|
|
457
|
-
function readOrCreateTelegramIdentityKey(agentRoot, hooks = {}) {
|
|
458
|
-
const directory = path.join(agentRoot, "state", "senses", "telegram");
|
|
459
|
-
const keyPath = path.join(directory, "identity.key");
|
|
460
|
-
const directoryHandle = openSecureTelegramDirectory(directory, hooks.afterOpenDirectory);
|
|
461
|
-
const readKey = () => {
|
|
462
|
-
const handle = (0, node_fs_1.openSync)(keyPath, node_fs_1.constants.O_RDONLY | node_fs_1.constants.O_NOFOLLOW);
|
|
463
|
-
try {
|
|
464
|
-
const metadata = (0, node_fs_1.fstatSync)(handle);
|
|
465
|
-
if (!metadata.isFile() || (metadata.mode & 0o777) !== 0o600)
|
|
466
|
-
throw new Error("Telegram opaque identity key permissions are invalid");
|
|
467
|
-
return canonicalTelegramIdentityKey((0, node_fs_1.readFileSync)(handle, "utf8"));
|
|
468
|
-
}
|
|
469
|
-
finally {
|
|
470
|
-
(0, node_fs_1.closeSync)(handle);
|
|
471
|
-
}
|
|
472
|
-
};
|
|
473
|
-
try {
|
|
474
|
-
try {
|
|
475
|
-
return readKey();
|
|
476
|
-
}
|
|
477
|
-
catch (error) {
|
|
478
|
-
if (errorCode(error) !== "ENOENT")
|
|
479
|
-
throw error;
|
|
480
|
-
}
|
|
481
|
-
const key = (0, node_crypto_1.randomBytes)(32).toString("base64url");
|
|
482
|
-
hooks.beforeCreate?.(keyPath);
|
|
483
|
-
const temporaryPath = path.join(directory, `.identity.key.${(0, node_crypto_1.randomBytes)(12).toString("base64url")}.tmp`);
|
|
484
|
-
let temporaryHandle;
|
|
485
|
-
try {
|
|
486
|
-
temporaryHandle = (0, node_fs_1.openSync)(temporaryPath, node_fs_1.constants.O_CREAT | node_fs_1.constants.O_EXCL | node_fs_1.constants.O_WRONLY | node_fs_1.constants.O_NOFOLLOW, 0o600);
|
|
487
|
-
hooks.afterCreateTemporary?.(temporaryPath, keyPath);
|
|
488
|
-
(0, node_fs_1.writeFileSync)(temporaryHandle, `${key}\n`);
|
|
489
|
-
(0, node_fs_1.fsyncSync)(temporaryHandle);
|
|
490
|
-
(0, node_fs_1.closeSync)(temporaryHandle);
|
|
491
|
-
temporaryHandle = undefined;
|
|
492
|
-
hooks.beforePublish?.(temporaryPath, keyPath);
|
|
493
|
-
try {
|
|
494
|
-
(0, node_fs_1.linkSync)(temporaryPath, keyPath);
|
|
495
|
-
}
|
|
496
|
-
catch (error) {
|
|
497
|
-
if (errorCode(error) !== "EEXIST")
|
|
498
|
-
throw error;
|
|
499
|
-
return readKey();
|
|
500
|
-
}
|
|
501
|
-
(0, node_fs_1.fsyncSync)(directoryHandle);
|
|
502
|
-
return key;
|
|
503
|
-
}
|
|
504
|
-
finally {
|
|
505
|
-
if (temporaryHandle !== undefined)
|
|
506
|
-
(0, node_fs_1.closeSync)(temporaryHandle);
|
|
507
|
-
if ((0, node_fs_1.existsSync)(temporaryPath))
|
|
508
|
-
(0, node_fs_1.unlinkSync)(temporaryPath);
|
|
509
|
-
(0, node_fs_1.fsyncSync)(directoryHandle);
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
finally {
|
|
513
|
-
(0, node_fs_1.closeSync)(directoryHandle);
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
424
|
function opaqueTelegramSubject(identityKey, botToken, authorizedUserId, authorizedChatId) {
|
|
517
425
|
const payload = [
|
|
518
426
|
TELEGRAM_SUBJECT_DOMAIN,
|
|
@@ -610,7 +518,7 @@ function discoverTelegramFilesystemSubjects(agentRoot) {
|
|
|
610
518
|
function writeTelegramSubjectIndex(agentRoot, subject, legacySubjects, hooks = {}) {
|
|
611
519
|
const directory = path.join(agentRoot, "state", "senses", "telegram");
|
|
612
520
|
const indexPath = path.join(directory, TELEGRAM_SUBJECT_INDEX);
|
|
613
|
-
const directoryHandle = openSecureTelegramDirectory(directory);
|
|
521
|
+
const directoryHandle = (0, telegram_identity_key_1.openSecureTelegramDirectory)(directory);
|
|
614
522
|
const temporaryPath = path.join(directory, `.identity-subjects.${(0, node_crypto_1.randomBytes)(12).toString("base64url")}.tmp`);
|
|
615
523
|
let temporaryHandle;
|
|
616
524
|
try {
|
|
@@ -723,8 +631,8 @@ function createTelegramSenseApp(options) {
|
|
|
723
631
|
const authorizedChatId = canonicalTelegramId(options.credentials.authorizedChatId, "authorized chat id");
|
|
724
632
|
const agentRoot = options._agentRoot ?? (0, identity_1.getAgentRoot)(options.agentName);
|
|
725
633
|
const identityKey = options.identityKey === undefined
|
|
726
|
-
? readOrCreateTelegramIdentityKey(agentRoot)
|
|
727
|
-
: canonicalTelegramIdentityKey(options.identityKey);
|
|
634
|
+
? (0, telegram_identity_key_1.readOrCreateTelegramIdentityKey)(agentRoot)
|
|
635
|
+
: (0, telegram_identity_key_1.canonicalTelegramIdentityKey)(options.identityKey);
|
|
728
636
|
const subject = opaqueTelegramSubject(identityKey, botId ?? botToken, authorizedUserId, authorizedChatId);
|
|
729
637
|
const transportPrivateValues = [botToken ?? "", authorizedUserId, authorizedChatId];
|
|
730
638
|
const transportError = (error) => redactTelegramPrivateValues(error, transportPrivateValues);
|
|
@@ -2090,7 +1998,7 @@ async function createProductionTelegramRelationshipComposition(agentName, creden
|
|
|
2090
1998
|
const ownerChatId = canonicalTelegramId(credentials.authorizedChatId, "authorized chat id");
|
|
2091
1999
|
if (ownerUserId !== ownerChatId)
|
|
2092
2000
|
throw new Error("Telegram owner relationship requires a private user-bound chat");
|
|
2093
|
-
const ownerSessionKey = `telegram:${opaqueTelegramSubject(readOrCreateTelegramIdentityKey(agentRoot), botId, ownerUserId, ownerChatId)}`;
|
|
2001
|
+
const ownerSessionKey = `telegram:${opaqueTelegramSubject((0, telegram_identity_key_1.readOrCreateTelegramIdentityKey)(agentRoot), botId, ownerUserId, ownerChatId)}`;
|
|
2094
2002
|
const store = new friends_1.FileFriendStore(path.join(agentRoot, "friends"));
|
|
2095
2003
|
const sameBotTelegramBindings = (friend) => friend.externalIds.filter((external) => external.provider === "telegram-user" && external.tenantId === botId);
|
|
2096
2004
|
const exactTelegramIdentity = (friend, userId) => {
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ouro.bot/cli",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.1069",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@ouro.bot/cli",
|
|
9
|
-
"version": "0.1.0-alpha.
|
|
9
|
+
"version": "0.1.0-alpha.1069",
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"@anthropic-ai/sdk": "^0.78.0",
|
|
12
12
|
"@ouro.bot/friends": "0.1.0-alpha.18",
|