@apralabs/apra-fleet 0.4.4 → 0.4.5
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 +49 -4
- package/dist/agents/backlog-groomer.md +5 -0
- package/dist/agents/ci-watcher.md +5 -0
- package/dist/agents/deployer.md +20 -2
- package/dist/agents/doer.md +38 -2
- package/dist/agents/harvester.md +12 -9
- package/dist/agents/integ-test-runner.md +5 -0
- package/dist/agents/kb-reconciler.md +6 -0
- package/dist/agents/plan-reviewer.md +5 -0
- package/dist/agents/planner.md +5 -0
- package/dist/agents/regression-test-runner.md +5 -0
- package/dist/agents/reviewer.md +67 -15
- package/dist/agents/schemas/deployer-output.json +5 -0
- package/dist/agents/schemas/doer-output.json +78 -2
- package/dist/agents/schemas/reviewer-output.json +104 -2
- package/dist/cli/auth.js +5 -1
- package/dist/cli/beads-pin.js +6 -7
- package/dist/cli/claude-mod.d.ts +75 -0
- package/dist/cli/claude-mod.js +288 -0
- package/dist/cli/dolt-install.d.ts +1 -1
- package/dist/cli/dolt-install.js +5 -1
- package/dist/cli/fleet-se-guard.d.ts +8 -0
- package/dist/cli/fleet-se-guard.js +19 -3
- package/dist/cli/install-guard.d.ts +9 -0
- package/dist/cli/install-guard.js +24 -0
- package/dist/cli/install.d.ts +12 -0
- package/dist/cli/install.js +180 -20
- package/dist/cli/kb-profile.d.ts +16 -0
- package/dist/cli/kb-profile.js +81 -0
- package/dist/cli/start.js +3 -0
- package/dist/cli/uninstall.js +13 -3
- package/dist/cli/update.d.ts +4 -0
- package/dist/cli/update.js +19 -3
- package/dist/commands/kb-server.d.ts +10 -1
- package/dist/commands/kb-server.js +285 -11
- package/dist/index.js +22 -1
- package/dist/os/git-executable.d.ts +57 -0
- package/dist/os/git-executable.js +85 -0
- package/dist/os/go-concurrency.d.ts +44 -0
- package/dist/os/go-concurrency.js +53 -0
- package/dist/os/index.d.ts +1 -0
- package/dist/os/index.js +1 -0
- package/dist/os/linux.d.ts +2 -0
- package/dist/os/linux.js +10 -1
- package/dist/os/os-commands.d.ts +25 -0
- package/dist/os/os-commands.js +2 -0
- package/dist/os/windows-executable.d.ts +53 -0
- package/dist/os/windows-executable.js +185 -0
- package/dist/os/windows-gitbash.d.ts +23 -14
- package/dist/os/windows-gitbash.js +40 -16
- package/dist/os/windows.d.ts +2 -0
- package/dist/os/windows.js +37 -6
- package/dist/paths.d.ts +10 -1
- package/dist/paths.js +19 -2
- package/dist/services/agy-project.d.ts +7 -1
- package/dist/services/agy-project.js +7 -2
- package/dist/services/auth-socket.d.ts +18 -0
- package/dist/services/auth-socket.js +30 -4
- package/dist/services/credential-store.d.ts +33 -0
- package/dist/services/credential-store.js +79 -2
- package/dist/services/http-transport.d.ts +29 -0
- package/dist/services/http-transport.js +166 -37
- package/dist/services/kb-tool-profile.d.ts +36 -0
- package/dist/services/kb-tool-profile.js +88 -0
- package/dist/services/knowledge/bible-blob-id.js +10 -1
- package/dist/services/knowledge/bible-import.d.ts +108 -0
- package/dist/services/knowledge/bible-import.js +137 -4
- package/dist/services/knowledge/file-hash.js +6 -5
- package/dist/services/knowledge/http-provider.d.ts +303 -20
- package/dist/services/knowledge/http-provider.js +795 -125
- package/dist/services/knowledge/kb-config.d.ts +65 -1
- package/dist/services/knowledge/kb-config.js +143 -3
- package/dist/services/knowledge/kb-http-auth-state.d.ts +26 -0
- package/dist/services/knowledge/kb-http-auth-state.js +40 -0
- package/dist/services/knowledge/kb-providers.d.ts +9 -2
- package/dist/services/knowledge/kb-providers.js +67 -37
- package/dist/services/knowledge/kb-removed-scope-keys.js +1 -1
- package/dist/services/knowledge/kb-self.d.ts +122 -9
- package/dist/services/knowledge/kb-self.js +196 -36
- package/dist/services/knowledge/member-bible-view.js +16 -3
- package/dist/services/knowledge/path-validation.d.ts +7 -0
- package/dist/services/knowledge/path-validation.js +11 -0
- package/dist/services/knowledge/project-slug.js +3 -2
- package/dist/services/knowledge/repository-header.d.ts +77 -0
- package/dist/services/knowledge/repository-header.js +233 -0
- package/dist/services/knowledge/require-sqlite-project.d.ts +1 -1
- package/dist/services/knowledge/require-sqlite-project.js +1 -1
- package/dist/services/knowledge/sqlite-provider.d.ts +169 -0
- package/dist/services/knowledge/sqlite-provider.js +416 -4
- package/dist/services/knowledge/types.d.ts +15 -2
- package/dist/services/member-busy.d.ts +12 -0
- package/dist/services/member-busy.js +20 -0
- package/dist/services/member-config-io.d.ts +3 -2
- package/dist/services/member-config-io.js +7 -4
- package/dist/services/member-fleet-install.js +1 -0
- package/dist/services/member-tool-allowlist.d.ts +1 -1
- package/dist/services/member-tool-allowlist.js +8 -4
- package/dist/services/port-holder.js +2 -1
- package/dist/services/service-manager/types.d.ts +17 -1
- package/dist/services/service-manager/windows.d.ts +7 -2
- package/dist/services/service-manager/windows.js +28 -11
- package/dist/services/service-notice.d.ts +7 -0
- package/dist/services/service-notice.js +19 -0
- package/dist/services/session-registry.d.ts +13 -0
- package/dist/services/session-registry.js +13 -0
- package/dist/services/session-roots.d.ts +67 -0
- package/dist/services/session-roots.js +126 -0
- package/dist/services/statusline.d.ts +21 -0
- package/dist/services/statusline.js +97 -1
- package/dist/services/supervisor-service-cleanup.js +2 -1
- package/dist/services/tool-registry.js +108 -20
- package/dist/services/tool-scope.d.ts +34 -1
- package/dist/services/tool-scope.js +27 -2
- package/dist/services/vcs/azure-devops.js +10 -0
- package/dist/services/vcs/bitbucket.d.ts +22 -1
- package/dist/services/vcs/bitbucket.js +163 -17
- package/dist/services/vcs/types.d.ts +25 -2
- package/dist/services/watch/project-resolver.js +2 -1
- package/dist/skills/pm/cost.md +5 -1
- package/dist/skills/pm/index.md +9 -9
- package/dist/skills/pm/sprint.md +2 -1
- package/dist/tools/check-status.d.ts +51 -0
- package/dist/tools/check-status.js +124 -12
- package/dist/tools/code-intelligence-freshness.js +1 -1
- package/dist/tools/code-intelligence-gitnexus.d.ts +19 -0
- package/dist/tools/code-intelligence-gitnexus.js +166 -9
- package/dist/tools/code-intelligence-readiness.d.ts +58 -1
- package/dist/tools/code-intelligence-readiness.js +93 -8
- package/dist/tools/code-intelligence-reindex.d.ts +25 -1
- package/dist/tools/code-intelligence-reindex.js +76 -4
- package/dist/tools/code-intelligence.d.ts +1 -1
- package/dist/tools/code-intelligence.js +1 -1
- package/dist/tools/execute-command.js +14 -8
- package/dist/tools/execute-prompt.js +6 -2
- package/dist/tools/fleet-snapshot.d.ts +21 -0
- package/dist/tools/fleet-snapshot.js +78 -0
- package/dist/tools/kb-bible-commit.d.ts +25 -11
- package/dist/tools/kb-bible-commit.js +142 -33
- package/dist/tools/kb-capture.d.ts +2 -2
- package/dist/tools/kb-context.js +47 -27
- package/dist/tools/kb-demote.d.ts +27 -0
- package/dist/tools/kb-demote.js +37 -0
- package/dist/tools/kb-export.d.ts +35 -3
- package/dist/tools/kb-export.js +56 -13
- package/dist/tools/kb-feedback.d.ts +2 -0
- package/dist/tools/kb-feedback.js +17 -7
- package/dist/tools/kb-harvest.js +28 -9
- package/dist/tools/kb-import.d.ts +18 -2
- package/dist/tools/kb-import.js +24 -9
- package/dist/tools/kb-invalidate.d.ts +11 -3
- package/dist/tools/kb-invalidate.js +80 -7
- package/dist/tools/kb-list.js +38 -10
- package/dist/tools/kb-promote.js +6 -4
- package/dist/tools/kb-query.d.ts +3 -0
- package/dist/tools/kb-query.js +181 -37
- package/dist/tools/kb-session-prime.d.ts +4 -4
- package/dist/tools/kb-session-prime.js +89 -9
- package/dist/tools/kb-setup.d.ts +20 -0
- package/dist/tools/kb-setup.js +149 -11
- package/dist/tools/list-members.js +1 -1
- package/dist/tools/member-detail.js +7 -3
- package/dist/tools/provision-vcs-auth.d.ts +28 -3
- package/dist/tools/provision-vcs-auth.js +53 -7
- package/dist/tools/receive-files.js +7 -4
- package/dist/tools/send-files.js +5 -4
- package/dist/tools/send-message.d.ts +3 -0
- package/dist/tools/send-message.js +15 -2
- package/dist/tools/stop-prompt.js +3 -1
- package/dist/tools/vcs-credential-exec.d.ts +45 -3
- package/dist/tools/vcs-credential-exec.js +90 -11
- package/dist/utils/process-utils.js +5 -1
- package/dist/utils/redact-known-secrets.d.ts +17 -0
- package/dist/utils/redact-known-secrets.js +70 -0
- package/dist/utils/skill-matrix.js +1 -1
- package/dist/utils/vcs-provider-detect.js +2 -2
- package/dist/workflows/auto-sprint.js +245 -9
- package/package.json +10 -7
- package/packages/apra-fleet-client/package.json +1 -1
- package/packages/apra-fleet-client/src/client/api.mjs +172 -19
- package/packages/apra-fleet-client/src/client/reconnecting-transport.mjs +35 -2
- package/packages/apra-fleet-client/src/client/transport.mjs +6 -0
- package/packages/apra-fleet-se/apra-pm/agents/backlog-groomer.md +5 -0
- package/packages/apra-fleet-se/apra-pm/agents/ci-watcher.md +5 -0
- package/packages/apra-fleet-se/apra-pm/agents/deployer.md +20 -2
- package/packages/apra-fleet-se/apra-pm/agents/doer.md +38 -2
- package/packages/apra-fleet-se/apra-pm/agents/harvester.md +12 -9
- package/packages/apra-fleet-se/apra-pm/agents/integ-test-runner.md +5 -0
- package/packages/apra-fleet-se/apra-pm/agents/kb-reconciler.md +6 -0
- package/packages/apra-fleet-se/apra-pm/agents/plan-reviewer.md +5 -0
- package/packages/apra-fleet-se/apra-pm/agents/planner.md +5 -0
- package/packages/apra-fleet-se/apra-pm/agents/regression-test-runner.md +5 -0
- package/packages/apra-fleet-se/apra-pm/agents/reviewer.md +67 -15
- package/packages/apra-fleet-se/apra-pm/agents/schemas/deployer-output.json +5 -0
- package/packages/apra-fleet-se/apra-pm/agents/schemas/doer-output.json +78 -2
- package/packages/apra-fleet-se/apra-pm/agents/schemas/reviewer-output.json +104 -2
- package/packages/apra-fleet-se/apra-pm/skills/pm/cost.md +5 -1
- package/packages/apra-fleet-se/apra-pm/skills/pm/index.md +9 -9
- package/packages/apra-fleet-se/apra-pm/skills/pm/sprint.md +2 -1
- package/packages/apra-fleet-se/bin/cli.mjs +104 -31
- package/packages/apra-fleet-se/bin/serve.mjs +46 -8
- package/packages/apra-fleet-se/fleet-sprint/abort.mjs +184 -32
- package/packages/apra-fleet-se/fleet-sprint/bd-sync-command.mjs +69 -0
- package/packages/apra-fleet-se/fleet-sprint/beads-children.mjs +21 -0
- package/packages/apra-fleet-se/fleet-sprint/beads-lock-probe.mjs +176 -0
- package/packages/apra-fleet-se/fleet-sprint/beads-reachability.mjs +126 -0
- package/packages/apra-fleet-se/fleet-sprint/beads-scope.mjs +158 -1
- package/packages/apra-fleet-se/fleet-sprint/contracts.mjs +82 -2
- package/packages/apra-fleet-se/fleet-sprint/coordination.mjs +23 -6
- package/packages/apra-fleet-se/fleet-sprint/decision-notify.mjs +338 -0
- package/packages/apra-fleet-se/fleet-sprint/decision-wait.mjs +731 -0
- package/packages/apra-fleet-se/fleet-sprint/decisions.mjs +372 -0
- package/packages/apra-fleet-se/fleet-sprint/dispatch-role.mjs +44 -11
- package/packages/apra-fleet-se/fleet-sprint/docs/README.md +4 -1
- package/packages/apra-fleet-se/fleet-sprint/dolt-settle.mjs +9 -3
- package/packages/apra-fleet-se/fleet-sprint/dolt-sync.mjs +314 -19
- package/packages/apra-fleet-se/fleet-sprint/errors.mjs +72 -4
- package/packages/apra-fleet-se/fleet-sprint/git-sync.mjs +7 -1
- package/packages/apra-fleet-se/fleet-sprint/git-topology.mjs +112 -1
- package/packages/apra-fleet-se/fleet-sprint/guarded-modules.mjs +36 -2
- package/packages/apra-fleet-se/fleet-sprint/kb.mjs +736 -101
- package/packages/apra-fleet-se/fleet-sprint/member-init-probe.mjs +1 -1
- package/packages/apra-fleet-se/fleet-sprint/member-provisioning.mjs +7 -1
- package/packages/apra-fleet-se/fleet-sprint/phases/deploy.mjs +49 -2
- package/packages/apra-fleet-se/fleet-sprint/phases/develop.mjs +206 -3
- package/packages/apra-fleet-se/fleet-sprint/phases/final-review.mjs +61 -3
- package/packages/apra-fleet-se/fleet-sprint/phases/harvest.mjs +81 -31
- package/packages/apra-fleet-se/fleet-sprint/phases/plan.mjs +7 -3
- package/packages/apra-fleet-se/fleet-sprint/phases/publish-pr.mjs +39 -14
- package/packages/apra-fleet-se/fleet-sprint/phases/re-review.mjs +17 -1
- package/packages/apra-fleet-se/fleet-sprint/phases/review.mjs +18 -3
- package/packages/apra-fleet-se/fleet-sprint/pr-body.mjs +14 -1
- package/packages/apra-fleet-se/fleet-sprint/prompts.mjs +32 -5
- package/packages/apra-fleet-se/fleet-sprint/runner.js +824 -98
- package/packages/apra-fleet-se/fleet-sprint/se-os-commands.mjs +4 -2
- package/packages/apra-fleet-se/fleet-sprint/se-posix.mjs +54 -1
- package/packages/apra-fleet-se/fleet-sprint/se-windows.mjs +29 -2
- package/packages/apra-fleet-se/fleet-sprint/set-aside.mjs +288 -0
- package/packages/apra-fleet-se/fleet-sprint/skills/fleet-supervisor/SKILL.md +3 -2
- package/packages/apra-fleet-se/fleet-sprint/sprint-args.mjs +20 -0
- package/packages/apra-fleet-se/fleet-sprint/sprint-report.mjs +21 -0
- package/packages/apra-fleet-se/fleet-sprint/sprint-state.mjs +9 -0
- package/packages/apra-fleet-se/fleet-sprint/vcs-auth.mjs +605 -32
- package/packages/apra-fleet-se/fleet-sprint/vcs-providers/bitbucket.mjs +811 -17
- package/packages/apra-fleet-se/fleet-sprint/vcs-providers/index.mjs +89 -1
- package/packages/apra-fleet-se/fleet-sprint/viewer-extensions.mjs +225 -2
- package/packages/apra-fleet-se/fleet-sprint/worklists.mjs +59 -3
- package/packages/apra-fleet-se/src/supervisor/api.mjs +148 -8
- package/packages/apra-fleet-se/src/supervisor/dashboard.mjs +6 -3
- package/packages/apra-fleet-se/src/supervisor/dolt-mutex.mjs +30 -10
- package/packages/apra-fleet-se/src/supervisor/fleet-members.mjs +17 -4
- package/packages/apra-fleet-se/src/supervisor/history.mjs +8 -1
- package/packages/apra-fleet-se/src/supervisor/id-allocator.mjs +92 -2
- package/packages/apra-fleet-se/src/supervisor/proxy.mjs +26 -1
- package/packages/apra-fleet-se/src/supervisor/server.mjs +151 -8
- package/packages/apra-fleet-se/src/supervisor/spawner.mjs +11 -9
- package/packages/apra-fleet-se/src/supervisor/watchdog.mjs +7 -1
- package/packages/apra-fleet-workflow/package.json +2 -1
- package/packages/apra-fleet-workflow/src/viewer/index.mjs +86 -5
- package/packages/apra-fleet-workflow/src/viewer/request-guard.mjs +222 -0
- package/packages/apra-fleet-workflow/src/workflow/index.mjs +34 -2
- package/plugins/claude-code/fleet-status/.claude-plugin/plugin.json +7 -0
- package/plugins/claude-code/fleet-status/hooks/hooks.json +1 -0
- package/plugins/claude-code/fleet-status/hooks/register.tsx +906 -0
- package/plugins/claude-code/fleet-status/types/index.d.ts +88 -0
- package/skills/fleet/auth-bitbucket.md +47 -20
- package/skills/fleet/onboarding.md +1 -1
- package/skills/fleet/skill-matrix.md +3 -3
- package/version.json +1 -1
package/dist/cli/uninstall.js
CHANGED
|
@@ -9,6 +9,7 @@ import { getServiceManager } from '../services/service-manager/index.js';
|
|
|
9
9
|
import { cleanupSupervisorService, } from '../services/supervisor-service-cleanup.js';
|
|
10
10
|
import { BIN_DIR, HOOKS_DIR, SCRIPTS_DIR, FLEET_BASE, NODE_MODULES_DIR, SCHEMAS_DIR, WORKFLOWS_DIR, getProviderInstallConfig, readConfig, writeConfig, readInstallConfig, PROVIDER_STANDARD_MODELS } from './config.js';
|
|
11
11
|
import { BUILTIN_WORKFLOW_NAMES } from './workflow-assets.js';
|
|
12
|
+
import { claudePluginsDir, isApraFleetStatusLine, uninstallClaudeMod } from './claude-mod.js';
|
|
12
13
|
function run(cmd, opts) {
|
|
13
14
|
const shellOpt = process.platform === 'win32' ? { shell: 'cmd.exe' } : {};
|
|
14
15
|
execSync(cmd, { stdio: 'inherit', windowsHide: true, ...shellOpt, ...opts });
|
|
@@ -127,7 +128,7 @@ function cleanupSettings(paths, dryRun) {
|
|
|
127
128
|
}
|
|
128
129
|
}
|
|
129
130
|
// 4. StatusLine
|
|
130
|
-
if (settings.statusLine
|
|
131
|
+
if (isApraFleetStatusLine(settings.statusLine)) {
|
|
131
132
|
console.log(` - Removing statusLine configuration`);
|
|
132
133
|
if (!dryRun)
|
|
133
134
|
delete settings.statusLine;
|
|
@@ -212,11 +213,13 @@ function cleanupWorkflows(dryRun) {
|
|
|
212
213
|
* Real run: lists what actually exists AFTER cleanup (a failed delete still
|
|
213
214
|
* shows up). Dry-run: subtracts the entries the plan removes.
|
|
214
215
|
*/
|
|
215
|
-
function printKeptSection(dryRun, keptUserWorkflows, keptSupervisorRegs) {
|
|
216
|
+
function printKeptSection(dryRun, keptUserWorkflows, keptSupervisorRegs, claudeModPlanned) {
|
|
216
217
|
const plannedRemovals = new Set();
|
|
217
218
|
if (dryRun) {
|
|
218
219
|
for (const p of [BIN_DIR, HOOKS_DIR, SCRIPTS_DIR, NODE_MODULES_DIR, SCHEMAS_DIR])
|
|
219
220
|
plannedRemovals.add(path.basename(p));
|
|
221
|
+
if (claudeModPlanned)
|
|
222
|
+
plannedRemovals.add(path.basename(claudePluginsDir()));
|
|
220
223
|
if (keptUserWorkflows.length === 0)
|
|
221
224
|
plannedRemovals.add(path.basename(WORKFLOWS_DIR));
|
|
222
225
|
}
|
|
@@ -378,6 +381,7 @@ Options:
|
|
|
378
381
|
}
|
|
379
382
|
}
|
|
380
383
|
let anythingRemoved = false;
|
|
384
|
+
let claudeModPlanned = false;
|
|
381
385
|
for (const llm of providersToClean) {
|
|
382
386
|
const paths = getProviderInstallConfig(llm);
|
|
383
387
|
console.log(`Cleaning up ${paths.name}...`);
|
|
@@ -391,6 +395,12 @@ Options:
|
|
|
391
395
|
}
|
|
392
396
|
catch { /* already removed or not found */ }
|
|
393
397
|
}
|
|
398
|
+
// fleet-status Claude Code mod: before cleanupSettings, since the
|
|
399
|
+
// claude CLI edits the same settings file.
|
|
400
|
+
if (uninstallClaudeMod(paths, dryRun)) {
|
|
401
|
+
anythingRemoved = true;
|
|
402
|
+
claudeModPlanned = true;
|
|
403
|
+
}
|
|
394
404
|
}
|
|
395
405
|
if (cleanupSettings(paths, dryRun))
|
|
396
406
|
anythingRemoved = true;
|
|
@@ -504,7 +514,7 @@ Options:
|
|
|
504
514
|
}
|
|
505
515
|
}
|
|
506
516
|
if (isFullUninstall) {
|
|
507
|
-
printKeptSection(dryRun, keptUserWorkflows, supervisorCleanup.kept);
|
|
517
|
+
printKeptSection(dryRun, keptUserWorkflows, supervisorCleanup.kept, claudeModPlanned);
|
|
508
518
|
}
|
|
509
519
|
// One final status line: "Uninstall complete." only when nothing failed;
|
|
510
520
|
// a failed supervisor removal ends with "Uninstall incomplete" + exit 1.
|
package/dist/cli/update.d.ts
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
|
+
/** Release installer published by ci.yml for each `process.platform/process.arch`. */
|
|
2
|
+
export declare const INSTALLER_ASSETS: Record<string, string>;
|
|
3
|
+
/** The installer asset for this host's OS AND CPU arch, or null when none is published. */
|
|
4
|
+
export declare function installerAssetName(platform: string, arch: string): string | null;
|
|
1
5
|
export declare function runUpdate(): Promise<void>;
|
|
2
6
|
//# sourceMappingURL=update.d.ts.map
|
package/dist/cli/update.js
CHANGED
|
@@ -10,6 +10,18 @@ import { isSea, isNpmGlobalInstall, fleetSeGuardEnabled, currentFleetSeProbes }
|
|
|
10
10
|
import { selfInvocationLines } from './install-guard.js';
|
|
11
11
|
import { detectRunningFleetSe, fleetSeRefusalText, IGNORE_RUNNING_SPRINTS_FLAG } from './fleet-se-guard.js';
|
|
12
12
|
import { showPendingServiceNotice } from '../services/service-notice.js';
|
|
13
|
+
/** Release installer published by ci.yml for each `process.platform/process.arch`. */
|
|
14
|
+
export const INSTALLER_ASSETS = {
|
|
15
|
+
'linux/x64': 'apra-fleet-installer-linux-x64',
|
|
16
|
+
'linux/arm64': 'apra-fleet-installer-linux-arm64',
|
|
17
|
+
'darwin/arm64': 'apra-fleet-installer-darwin-arm64',
|
|
18
|
+
'darwin/x64': 'apra-fleet-installer-darwin-x64',
|
|
19
|
+
'win32/x64': 'apra-fleet-installer-win-x64.exe',
|
|
20
|
+
};
|
|
21
|
+
/** The installer asset for this host's OS AND CPU arch, or null when none is published. */
|
|
22
|
+
export function installerAssetName(platform, arch) {
|
|
23
|
+
return INSTALLER_ASSETS[`${platform}/${arch}`] ?? null;
|
|
24
|
+
}
|
|
13
25
|
export async function runUpdate() {
|
|
14
26
|
// Guidance the previous (detached) install could not show.
|
|
15
27
|
showPendingServiceNotice();
|
|
@@ -55,11 +67,15 @@ export async function runUpdate() {
|
|
|
55
67
|
console.log(`apra-fleet ${serverVersion} is up to date.`);
|
|
56
68
|
return;
|
|
57
69
|
}
|
|
58
|
-
const
|
|
59
|
-
|
|
70
|
+
const assetName = installerAssetName(process.platform, process.arch);
|
|
71
|
+
if (!assetName) {
|
|
72
|
+
console.error(`Error: no apra-fleet installer is published for ${process.platform}/${process.arch} ` +
|
|
73
|
+
`(published: ${Object.keys(INSTALLER_ASSETS).join(', ')}). Install from source instead.`);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
60
76
|
const asset = data.assets?.find(a => a.name === assetName);
|
|
61
77
|
if (!asset) {
|
|
62
|
-
console.error(`Error: Could not find installer
|
|
78
|
+
console.error(`Error: Could not find installer ${assetName} in release ${tagName}`);
|
|
63
79
|
return;
|
|
64
80
|
}
|
|
65
81
|
console.log(`Updating to ${tagName} -- restarting...`);
|
|
@@ -2,10 +2,19 @@ import http from 'node:http';
|
|
|
2
2
|
export declare class KbServerHttpProviderRefusedError extends Error {
|
|
3
3
|
constructor(message: string);
|
|
4
4
|
}
|
|
5
|
-
|
|
5
|
+
/** Header every HttpKbProvider request carries: the project slug it is for. */
|
|
6
|
+
export declare const KB_PROJECT_HEADER = "x-kb-project";
|
|
7
|
+
/** What GET /api/kb/capabilities answers: every contract route (the server always serves a local SQLite KB). */
|
|
8
|
+
export declare const KB_SERVER_CAPABILITIES: Readonly<{
|
|
9
|
+
contract: "v1";
|
|
10
|
+
routes: readonly string[];
|
|
11
|
+
branch_aware: false;
|
|
12
|
+
}>;
|
|
13
|
+
export declare function startKbServer(port: number, generateToken: boolean, dbPath?: string, tokenFile?: string): Promise<http.Server>;
|
|
6
14
|
export declare function parseKbServerArgs(argv: string[]): {
|
|
7
15
|
port: number;
|
|
8
16
|
generateToken: boolean;
|
|
9
17
|
dbPath?: string;
|
|
18
|
+
tokenFile?: string;
|
|
10
19
|
};
|
|
11
20
|
//# sourceMappingURL=kb-server.d.ts.map
|
|
@@ -6,9 +6,11 @@ import { FLEET_DIR } from '../paths.js';
|
|
|
6
6
|
import { createKbProviders } from '../services/knowledge/kb-providers.js';
|
|
7
7
|
import { KB_CONFIG_PATH } from '../services/knowledge/kb-config.js';
|
|
8
8
|
import { HttpKbProvider } from '../services/knowledge/http-provider.js';
|
|
9
|
-
import { validateFilePaths } from '../services/knowledge/path-validation.js';
|
|
9
|
+
import { validateFilePaths, isAbsoluteOrTraversing } from '../services/knowledge/path-validation.js';
|
|
10
10
|
import { encryptPassword, decryptPassword } from '../utils/crypto.js';
|
|
11
|
+
import { validateAuthor } from '../tools/kb-feedback.js';
|
|
11
12
|
import { KbCaptureRejected } from '../services/knowledge/types.js';
|
|
13
|
+
import { requireSqliteProject } from '../services/knowledge/require-sqlite-project.js';
|
|
12
14
|
// my-beads-db-0cd.15 (reopened): startKbServer is an exported library function
|
|
13
15
|
// that tests/knowledge/kb-server.test.ts imports and calls IN-PROCESS. The
|
|
14
16
|
// http-provider refusal used to call process.exit(1) directly, which would
|
|
@@ -25,6 +27,22 @@ export class KbServerHttpProviderRefusedError extends Error {
|
|
|
25
27
|
}
|
|
26
28
|
}
|
|
27
29
|
const MAX_BODY_SIZE = 1_048_576; // 1MB
|
|
30
|
+
/** Header every HttpKbProvider request carries: the project slug it is for. */
|
|
31
|
+
export const KB_PROJECT_HEADER = 'x-kb-project';
|
|
32
|
+
/** What GET /api/kb/capabilities answers: every contract route (the server always serves a local SQLite KB). */
|
|
33
|
+
export const KB_SERVER_CAPABILITIES = Object.freeze({
|
|
34
|
+
contract: 'v1',
|
|
35
|
+
routes: Object.freeze(['capture', 'query', 'promote', 'context', 'prime', 'invalidate', 'feedback', 'list', 'demote']),
|
|
36
|
+
branch_aware: false,
|
|
37
|
+
});
|
|
38
|
+
/** A demote refusal's taxonomy code at the start of SqliteProvider.demote's message (answered 422). */
|
|
39
|
+
const DEMOTE_REFUSAL_CODE = /^(E-DEMOTE-[A-Z-]+):/;
|
|
40
|
+
/**
|
|
41
|
+
* How SqliteProvider.promote's refusals of the promote ladder begin
|
|
42
|
+
* (superseded, user-directive, unresolved basis; trivial reason). Only these
|
|
43
|
+
* are 422 PROMOTE_REFUSED; any other promote error is a server fault (500).
|
|
44
|
+
*/
|
|
45
|
+
const PROMOTE_REFUSAL_PREFIXES = ['Cannot promote ', 'kb_promote requires a reason'];
|
|
28
46
|
const RATE_LIMIT_WINDOW_MS = 60_000;
|
|
29
47
|
const RATE_LIMIT_MAX = 100;
|
|
30
48
|
const TOKEN_DIR = path.join(FLEET_DIR, 'knowledge');
|
|
@@ -87,15 +105,55 @@ function readBody(req) {
|
|
|
87
105
|
req.on('error', reject);
|
|
88
106
|
});
|
|
89
107
|
}
|
|
108
|
+
/**
|
|
109
|
+
* A query parameter carrying a JSON array of strings: undefined when absent,
|
|
110
|
+
* null when present but not such an array (the caller answers 400).
|
|
111
|
+
*/
|
|
112
|
+
function stringArrayParam(url, name) {
|
|
113
|
+
const raw = url.searchParams.get(name);
|
|
114
|
+
if (!raw)
|
|
115
|
+
return undefined;
|
|
116
|
+
let parsed;
|
|
117
|
+
try {
|
|
118
|
+
parsed = JSON.parse(raw);
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
return Array.isArray(parsed) && parsed.every(t => typeof t === 'string') ? parsed : null;
|
|
124
|
+
}
|
|
90
125
|
function getClientIp(req) {
|
|
91
126
|
return req.socket.remoteAddress || '0.0.0.0';
|
|
92
127
|
}
|
|
93
|
-
|
|
128
|
+
const TOKEN_FILE_POLL_MS = 250;
|
|
129
|
+
function readTokenFile(tokenFile) {
|
|
130
|
+
let raw;
|
|
131
|
+
try {
|
|
132
|
+
raw = fs.readFileSync(tokenFile, 'utf-8');
|
|
133
|
+
}
|
|
134
|
+
catch {
|
|
135
|
+
throw new Error(`cannot read token file ${tokenFile}`);
|
|
136
|
+
}
|
|
137
|
+
const token = raw.trim();
|
|
138
|
+
if (!token)
|
|
139
|
+
throw new Error(`token file ${tokenFile} is empty`);
|
|
140
|
+
return token;
|
|
141
|
+
}
|
|
142
|
+
export async function startKbServer(port, generateToken, dbPath, tokenFile) {
|
|
143
|
+
if (tokenFile && generateToken) {
|
|
144
|
+
throw new Error('--generate-token cannot be combined with --token-file: the token comes from the file');
|
|
145
|
+
}
|
|
146
|
+
// Fail before any side effect when the token file is unusable.
|
|
147
|
+
let serverToken;
|
|
148
|
+
if (tokenFile) {
|
|
149
|
+
serverToken = readTokenFile(tokenFile);
|
|
150
|
+
}
|
|
94
151
|
if (generateToken) {
|
|
95
152
|
const token = generateNewToken();
|
|
96
153
|
process.stderr.write(`KB server token: ${token}\n`);
|
|
97
154
|
}
|
|
98
|
-
|
|
155
|
+
if (!tokenFile)
|
|
156
|
+
serverToken = getOrCreateToken();
|
|
99
157
|
const providers = await createKbProviders();
|
|
100
158
|
// KB server is a server, not a client: it must never silently become a
|
|
101
159
|
// self-proxying HttpKbProvider just because the local KB config selects
|
|
@@ -107,9 +165,8 @@ export async function startKbServer(port, generateToken, dbPath) {
|
|
|
107
165
|
// and never self-proxies -- the hazard this refusal exists for cannot arise.
|
|
108
166
|
// The check therefore reads the CONFIG-selected provider, before the --db
|
|
109
167
|
// override replaces it, and only refuses when there is no --db. Either way
|
|
110
|
-
// the HttpKbProvider createKbProviders() already built is disposed first
|
|
111
|
-
//
|
|
112
|
-
// dispose() removes, so dropping it undisposed would leak one per start.
|
|
168
|
+
// the HttpKbProvider createKbProviders() already built is disposed first, as
|
|
169
|
+
// every retired provider is.
|
|
113
170
|
if (providers.project instanceof HttpKbProvider) {
|
|
114
171
|
providers.project.dispose();
|
|
115
172
|
if (!dbPath) {
|
|
@@ -120,6 +177,15 @@ export async function startKbServer(port, generateToken, dbPath) {
|
|
|
120
177
|
`explicit local database.`);
|
|
121
178
|
}
|
|
122
179
|
}
|
|
180
|
+
// The --db override is built here, not taken from the shared provider cache,
|
|
181
|
+
// so this server owns it and must close it on shutdown: an open sqlite
|
|
182
|
+
// handle keeps the file locked (Windows refuses to delete it).
|
|
183
|
+
let ownedProvider;
|
|
184
|
+
const releaseOwnedProvider = () => {
|
|
185
|
+
const p = ownedProvider;
|
|
186
|
+
ownedProvider = undefined;
|
|
187
|
+
p?.close();
|
|
188
|
+
};
|
|
123
189
|
if (dbPath) {
|
|
124
190
|
const { SqliteProvider } = await import('../services/knowledge/sqlite-provider.js');
|
|
125
191
|
// Anchor capture basis checks at process.cwd(), the same repo root
|
|
@@ -128,9 +194,14 @@ export async function startKbServer(port, generateToken, dbPath) {
|
|
|
128
194
|
const overrideProvider = new SqliteProvider(dbPath, process.cwd());
|
|
129
195
|
await overrideProvider.init();
|
|
130
196
|
providers.project = overrideProvider;
|
|
197
|
+
ownedProvider = overrideProvider;
|
|
131
198
|
}
|
|
132
|
-
|
|
133
|
-
|
|
199
|
+
// Always a SqliteProvider here: an http config is refused above unless --db
|
|
200
|
+
// replaced it, and the project provider is otherwise SQLite.
|
|
201
|
+
const provider = requireSqliteProject(providers.project, 'kb serve');
|
|
202
|
+
const serverProject = providers.projectSlug;
|
|
203
|
+
process.stderr.write('[kb-server] project=' + serverProject + '\n');
|
|
204
|
+
let lastTokenWarning;
|
|
134
205
|
const server = http.createServer(async (req, res) => {
|
|
135
206
|
const ip = getClientIp(req);
|
|
136
207
|
const url = new URL(req.url || '/', `http://${req.headers.host || 'localhost'}`);
|
|
@@ -154,6 +225,25 @@ export async function startKbServer(port, generateToken, dbPath) {
|
|
|
154
225
|
if (token !== serverToken) {
|
|
155
226
|
return jsonResponse(res, 401, { error: 'Invalid token', code: 'UNAUTHORIZED' });
|
|
156
227
|
}
|
|
228
|
+
// One server serves one project. A request for another project (or one
|
|
229
|
+
// that names none) is refused on every route, so a client pointed at the
|
|
230
|
+
// wrong server never reads or writes another repo's KB.
|
|
231
|
+
const clientProject = req.headers[KB_PROJECT_HEADER];
|
|
232
|
+
if (clientProject !== serverProject) {
|
|
233
|
+
const named = typeof clientProject === 'string' ? clientProject : '(none)';
|
|
234
|
+
return jsonResponse(res, 409, {
|
|
235
|
+
error: `KB project mismatch: this server serves "${serverProject}", the request is for "${named}"`,
|
|
236
|
+
code: 'PROJECT_MISMATCH',
|
|
237
|
+
server_project: serverProject,
|
|
238
|
+
client_project: named,
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
// GET /api/kb/capabilities -- same auth and project check as every route.
|
|
242
|
+
// Lists every contract route, and keeps one KB per project
|
|
243
|
+
// with no per-branch truth (X-Repository-Branch is not used).
|
|
244
|
+
if (pathname === '/api/kb/capabilities' && method === 'GET') {
|
|
245
|
+
return jsonResponse(res, 200, KB_SERVER_CAPABILITIES);
|
|
246
|
+
}
|
|
157
247
|
try {
|
|
158
248
|
// POST /api/kb/capture
|
|
159
249
|
if (pathname === '/api/kb/capture' && method === 'POST') {
|
|
@@ -174,9 +264,128 @@ export async function startKbServer(port, generateToken, dbPath) {
|
|
|
174
264
|
?.split(',')
|
|
175
265
|
.filter((c) => c === 'CONFIRMED' || c === 'INFERRED' || c === 'UNVERIFIED');
|
|
176
266
|
const exclude_disputed = url.searchParams.get('exclude_disputed') === 'true';
|
|
177
|
-
|
|
267
|
+
// tag: exact-match tag filter (HttpKbProvider uses it for the member
|
|
268
|
+
// own-scope lookup, tag=member:<uuid>); a tag alone lists every entry
|
|
269
|
+
// carrying it. include_stale / include_superseded as in kb_query.
|
|
270
|
+
const tag = url.searchParams.get('tag') || undefined;
|
|
271
|
+
const include_stale = url.searchParams.get('include_stale') === 'true';
|
|
272
|
+
const include_superseded = url.searchParams.get('include_superseded') === 'true';
|
|
273
|
+
// flagged_only: list only contradiction-flagged entries (the
|
|
274
|
+
// kb_query flagged_only branch); the trust filters are ignored then.
|
|
275
|
+
const flagged_only = url.searchParams.get('flagged_only') === 'true';
|
|
276
|
+
// fts_terms: JSON array of discrete terms, OR-joined as an FTS match
|
|
277
|
+
// (the kb_session_prime neighbour query sends only these).
|
|
278
|
+
const fts_terms = stringArrayParam(url, 'fts_terms');
|
|
279
|
+
// ids: JSON array of entry ids, an exact-id lookup (kb_query's L2 fetch).
|
|
280
|
+
const ids = stringArrayParam(url, 'ids');
|
|
281
|
+
if (fts_terms === null || ids === null) {
|
|
282
|
+
const name = fts_terms === null ? 'fts_terms' : 'ids';
|
|
283
|
+
return jsonResponse(res, 400, { error: `${name} must be a JSON array of strings`, code: 'BAD_REQUEST' });
|
|
284
|
+
}
|
|
285
|
+
const result = await provider.query({
|
|
286
|
+
query, type, tag, limit, l1_only, confidence, exclude_disputed, include_stale, include_superseded,
|
|
287
|
+
flagged_only, fts_terms, ids,
|
|
288
|
+
});
|
|
178
289
|
return jsonResponse(res, 200, result);
|
|
179
290
|
}
|
|
291
|
+
// GET /api/kb/list -- the no-bump read (provider.list): use_count and
|
|
292
|
+
// last_accessed are left alone. HttpKbProvider's member own-scope lookup
|
|
293
|
+
// uses it, so checking ownership is not counted as a retrieval.
|
|
294
|
+
if (pathname === '/api/kb/list' && method === 'GET') {
|
|
295
|
+
const confidence = url.searchParams.get('confidence')
|
|
296
|
+
?.split(',')
|
|
297
|
+
.filter((c) => c === 'CONFIRMED' || c === 'INFERRED' || c === 'UNVERIFIED');
|
|
298
|
+
// type/module/symbol/exclude_disputed: the kb_list filters, so a
|
|
299
|
+
// MEMBER kb_list's own half (HttpKbProvider.list) is filtered here.
|
|
300
|
+
const results = await provider.list({
|
|
301
|
+
tag: url.searchParams.get('tag') || undefined,
|
|
302
|
+
confidence,
|
|
303
|
+
type: (url.searchParams.get('type') || undefined),
|
|
304
|
+
module: url.searchParams.get('module') || undefined,
|
|
305
|
+
symbol: url.searchParams.get('symbol') || undefined,
|
|
306
|
+
exclude_disputed: url.searchParams.get('exclude_disputed') === 'true',
|
|
307
|
+
limit: url.searchParams.has('limit') ? parseInt(url.searchParams.get('limit'), 10) : undefined,
|
|
308
|
+
include_stale: url.searchParams.get('include_stale') === 'true',
|
|
309
|
+
});
|
|
310
|
+
return jsonResponse(res, 200, { results, total: results.length });
|
|
311
|
+
}
|
|
312
|
+
// POST /api/kb/promote {id, reason} -> {id, previous_confidence, new_confidence}
|
|
313
|
+
// Same reply shape as the kb_promote tool. An unknown id is 404
|
|
314
|
+
// ENTRY_NOT_FOUND (the code an optional id route such as demote needs
|
|
315
|
+
// for "entry unknown" rather than "route not served"); any
|
|
316
|
+
// other refusal of the promote ladder (reason, superseded, directive,
|
|
317
|
+
// unresolved basis) is 422 with the provider's message.
|
|
318
|
+
if (pathname === '/api/kb/promote' && method === 'POST') {
|
|
319
|
+
const { id, reason } = JSON.parse(await readBody(req));
|
|
320
|
+
if (typeof id !== 'string' || id.length === 0) {
|
|
321
|
+
return jsonResponse(res, 400, { error: 'id must be a non-empty string', code: 'BAD_REQUEST' });
|
|
322
|
+
}
|
|
323
|
+
if (reason !== undefined && typeof reason !== 'string') {
|
|
324
|
+
return jsonResponse(res, 400, { error: 'reason must be a string', code: 'BAD_REQUEST' });
|
|
325
|
+
}
|
|
326
|
+
try {
|
|
327
|
+
const result = await provider.promote(id, reason);
|
|
328
|
+
return jsonResponse(res, 200, {
|
|
329
|
+
id: result.id,
|
|
330
|
+
previous_confidence: result.confidence_before,
|
|
331
|
+
new_confidence: result.confidence_after,
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
catch (err) {
|
|
335
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
336
|
+
if (message.startsWith('Entry not found')) {
|
|
337
|
+
return jsonResponse(res, 404, { error: message, code: 'ENTRY_NOT_FOUND' });
|
|
338
|
+
}
|
|
339
|
+
if (PROMOTE_REFUSAL_PREFIXES.some(prefix => message.startsWith(prefix))) {
|
|
340
|
+
return jsonResponse(res, 422, { error: message, code: 'PROMOTE_REFUSED' });
|
|
341
|
+
}
|
|
342
|
+
// Not a refusal (e.g. a database failure): the generic 500 below.
|
|
343
|
+
throw err;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
// POST /api/kb/demote {id, reason, evidence_files} -> {id, previous_confidence, new_confidence}
|
|
347
|
+
// Backed by SqliteProvider.demote. evidence_files are untrusted:
|
|
348
|
+
// repo-relative to the repository this server serves (spec 2.9.1). An
|
|
349
|
+
// absolute or '..' path is refused first, before the id is looked up,
|
|
350
|
+
// whatever the platform's own path rules; the rest resolve against the
|
|
351
|
+
// served checkout. An unknown id is 404 ENTRY_NOT_FOUND; every demote
|
|
352
|
+
// refusal is 422 with its E-DEMOTE-* code; anything else is a 500.
|
|
353
|
+
if (pathname === '/api/kb/demote' && method === 'POST') {
|
|
354
|
+
const { id, reason, evidence_files: evidence } = JSON.parse(await readBody(req));
|
|
355
|
+
if (typeof id !== 'string' || id.length === 0 || typeof reason !== 'string'
|
|
356
|
+
|| !Array.isArray(evidence) || !evidence.every((f) => typeof f === 'string')) {
|
|
357
|
+
return jsonResponse(res, 400, {
|
|
358
|
+
error: 'id must be a non-empty string, reason a string and evidence_files an array of strings',
|
|
359
|
+
code: 'BAD_REQUEST',
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
const outside = evidence.filter(isAbsoluteOrTraversing);
|
|
363
|
+
if (outside.length > 0) {
|
|
364
|
+
return jsonResponse(res, 422, {
|
|
365
|
+
error: `E-DEMOTE-EVIDENCE-UNRESOLVED: kb_demote evidence is absolute or contains a '..' segment: ${outside.join(', ')}. Entry: ${id}`,
|
|
366
|
+
code: 'E-DEMOTE-EVIDENCE-UNRESOLVED',
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
try {
|
|
370
|
+
const result = await provider.demote(id, reason, evidence);
|
|
371
|
+
return jsonResponse(res, 200, {
|
|
372
|
+
id: result.id,
|
|
373
|
+
previous_confidence: result.confidence_before,
|
|
374
|
+
new_confidence: result.confidence_after,
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
catch (err) {
|
|
378
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
379
|
+
if (message.startsWith('Entry not found')) {
|
|
380
|
+
return jsonResponse(res, 404, { error: message, code: 'ENTRY_NOT_FOUND' });
|
|
381
|
+
}
|
|
382
|
+
const refusal = DEMOTE_REFUSAL_CODE.exec(message);
|
|
383
|
+
if (refusal)
|
|
384
|
+
return jsonResponse(res, 422, { error: message, code: refusal[1] });
|
|
385
|
+
// Not a refusal (e.g. a database failure): the generic 500 below.
|
|
386
|
+
throw err;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
180
389
|
// POST /api/kb/invalidate
|
|
181
390
|
if (pathname === '/api/kb/invalidate' && method === 'POST') {
|
|
182
391
|
const body = await readBody(req);
|
|
@@ -199,7 +408,9 @@ export async function startKbServer(port, generateToken, dbPath) {
|
|
|
199
408
|
const ctxConfidence = url.searchParams.get('confidence')
|
|
200
409
|
?.split(',')
|
|
201
410
|
.filter((c) => c === 'CONFIRMED' || c === 'INFERRED' || c === 'UNVERIFIED');
|
|
202
|
-
|
|
411
|
+
// tag: MEMBER own-scope (HttpKbProvider sends the owner tag), so each
|
|
412
|
+
// file's newest entry is chosen among that member's own.
|
|
413
|
+
const result = await provider.context(files, ctxConfidence, url.searchParams.get('exclude_disputed') === 'true', url.searchParams.get('tag') || undefined);
|
|
203
414
|
return jsonResponse(res, 200, { results: result });
|
|
204
415
|
}
|
|
205
416
|
// POST /api/kb/prime
|
|
@@ -211,6 +422,33 @@ export async function startKbServer(port, generateToken, dbPath) {
|
|
|
211
422
|
const result = await provider.prime(opts);
|
|
212
423
|
return jsonResponse(res, 200, result);
|
|
213
424
|
}
|
|
425
|
+
// POST /api/kb/feedback -- same author validation and response shape as
|
|
426
|
+
// the kb_feedback tool; confidence is never changed.
|
|
427
|
+
if (pathname === '/api/kb/feedback' && method === 'POST') {
|
|
428
|
+
const body = await readBody(req);
|
|
429
|
+
const input = JSON.parse(body);
|
|
430
|
+
if (typeof input.id !== 'string' || input.id.length === 0 ||
|
|
431
|
+
typeof input.reason !== 'string' || input.reason.length === 0) {
|
|
432
|
+
return jsonResponse(res, 400, { error: 'id and reason must be non-empty strings', code: 'BAD_REQUEST' });
|
|
433
|
+
}
|
|
434
|
+
const author = validateAuthor(typeof input.role === 'string' ? input.role : undefined);
|
|
435
|
+
let entry;
|
|
436
|
+
try {
|
|
437
|
+
entry = await provider.feedback(input.id, input.reason, author);
|
|
438
|
+
}
|
|
439
|
+
catch (err) {
|
|
440
|
+
if (err instanceof Error && err.message.startsWith('Entry not found')) {
|
|
441
|
+
return jsonResponse(res, 404, { error: err.message, code: 'ENTRY_NOT_FOUND' });
|
|
442
|
+
}
|
|
443
|
+
throw err;
|
|
444
|
+
}
|
|
445
|
+
return jsonResponse(res, 200, {
|
|
446
|
+
id: entry.id,
|
|
447
|
+
stale: entry.stale,
|
|
448
|
+
flagged_for_review: entry.flagged_for_review,
|
|
449
|
+
confidence: entry.confidence,
|
|
450
|
+
});
|
|
451
|
+
}
|
|
214
452
|
return jsonResponse(res, 404, { error: 'Not found', code: 'NOT_FOUND' });
|
|
215
453
|
}
|
|
216
454
|
catch (err) {
|
|
@@ -221,6 +459,10 @@ export async function startKbServer(port, generateToken, dbPath) {
|
|
|
221
459
|
if (err instanceof KbCaptureRejected) {
|
|
222
460
|
return jsonResponse(res, 400, { error: err.message, code: 'CAPTURE_REJECTED', reason: err.reason });
|
|
223
461
|
}
|
|
462
|
+
// A request body that is not JSON is the caller's fault, on every route.
|
|
463
|
+
if (err instanceof SyntaxError) {
|
|
464
|
+
return jsonResponse(res, 400, { error: 'Request body is not valid JSON', code: 'BAD_REQUEST' });
|
|
465
|
+
}
|
|
224
466
|
if (err instanceof Error) {
|
|
225
467
|
if (err.message === 'BODY_TOO_LARGE') {
|
|
226
468
|
return jsonResponse(res, 413, { error: 'Request body too large (max 1MB)', code: 'PAYLOAD_TOO_LARGE' });
|
|
@@ -232,12 +474,39 @@ export async function startKbServer(port, generateToken, dbPath) {
|
|
|
232
474
|
return jsonResponse(res, 500, { error: 'Internal server error', code: 'INTERNAL_ERROR' });
|
|
233
475
|
}
|
|
234
476
|
});
|
|
477
|
+
server.on('close', releaseOwnedProvider);
|
|
478
|
+
// Poll the token file by path (stat-free content compare) so in-place writes
|
|
479
|
+
// and rename-replacement are both picked up. A bad re-read keeps the last
|
|
480
|
+
// good token; the token value is never logged.
|
|
481
|
+
let tokenTimer;
|
|
482
|
+
if (tokenFile) {
|
|
483
|
+
tokenTimer = setInterval(() => {
|
|
484
|
+
try {
|
|
485
|
+
serverToken = readTokenFile(tokenFile);
|
|
486
|
+
}
|
|
487
|
+
catch (err) {
|
|
488
|
+
const msg = err.message;
|
|
489
|
+
if (msg !== lastTokenWarning) {
|
|
490
|
+
lastTokenWarning = msg;
|
|
491
|
+
process.stderr.write(`[kb-server] warning: ${msg}; keeping the last good token\n`);
|
|
492
|
+
}
|
|
493
|
+
return;
|
|
494
|
+
}
|
|
495
|
+
lastTokenWarning = undefined;
|
|
496
|
+
}, TOKEN_FILE_POLL_MS);
|
|
497
|
+
tokenTimer.unref();
|
|
498
|
+
server.on('close', () => { if (tokenTimer)
|
|
499
|
+
clearInterval(tokenTimer); });
|
|
500
|
+
}
|
|
235
501
|
return new Promise((resolve, reject) => {
|
|
236
502
|
server.on('error', (err) => {
|
|
237
503
|
if (err.code === 'EADDRINUSE') {
|
|
238
504
|
process.stderr.write(`KB server failed to start: port ${port} is already in use. Try --port ${port + 1}\n`);
|
|
239
505
|
process.exit(1);
|
|
240
506
|
}
|
|
507
|
+
releaseOwnedProvider();
|
|
508
|
+
if (tokenTimer)
|
|
509
|
+
clearInterval(tokenTimer);
|
|
241
510
|
reject(err);
|
|
242
511
|
});
|
|
243
512
|
server.listen(port, () => {
|
|
@@ -250,6 +519,7 @@ export function parseKbServerArgs(argv) {
|
|
|
250
519
|
let port = 7878;
|
|
251
520
|
let generateToken = false;
|
|
252
521
|
let dbPath;
|
|
522
|
+
let tokenFile;
|
|
253
523
|
for (let i = 0; i < argv.length; i++) {
|
|
254
524
|
if (argv[i] === '--port' && argv[i + 1]) {
|
|
255
525
|
port = parseInt(argv[i + 1], 10);
|
|
@@ -262,7 +532,11 @@ export function parseKbServerArgs(argv) {
|
|
|
262
532
|
dbPath = argv[i + 1];
|
|
263
533
|
i++;
|
|
264
534
|
}
|
|
535
|
+
if (argv[i] === '--token-file' && argv[i + 1]) {
|
|
536
|
+
tokenFile = argv[i + 1];
|
|
537
|
+
i++;
|
|
538
|
+
}
|
|
265
539
|
}
|
|
266
|
-
return { port, generateToken, dbPath };
|
|
540
|
+
return { port, generateToken, dbPath, tokenFile };
|
|
267
541
|
}
|
|
268
542
|
//# sourceMappingURL=kb-server.js.map
|
package/dist/index.js
CHANGED
|
@@ -54,6 +54,7 @@ Usage:
|
|
|
54
54
|
apra-fleet kb reject-directive <id> Reject a proposal or retire an active directive
|
|
55
55
|
apra-fleet kb add-directive "<text>" [--symbols a,b] Create an already-active directive (human-only)
|
|
56
56
|
apra-fleet kb commit [--repo <path>] [--global] Re-export + auto-commit the canonical bible (manual/recovery)
|
|
57
|
+
apra-fleet kb profile [full|developer|custom <a,b>] Show or set the KB tool profile for interactive sessions
|
|
57
58
|
apra-fleet join <member-jwt> [--hub-url <url>] Activate a device using a member JWT obtained out-of-band from fleet-dashboard
|
|
58
59
|
apra-fleet spoke <origin-member-id> Run as an outbound hub-connected spoke; requires apra-fleet join first
|
|
59
60
|
apra-fleet --version Print version
|
|
@@ -143,7 +144,7 @@ else if (arg === 'kb-server') {
|
|
|
143
144
|
import('./commands/kb-server.js')
|
|
144
145
|
.then(async (m) => {
|
|
145
146
|
const opts = m.parseKbServerArgs(process.argv.slice(3));
|
|
146
|
-
await m.startKbServer(opts.port, opts.generateToken, opts.dbPath);
|
|
147
|
+
await m.startKbServer(opts.port, opts.generateToken, opts.dbPath, opts.tokenFile);
|
|
147
148
|
})
|
|
148
149
|
.catch(err => { logError('cli', `kb-server failed: ${err.message}`); process.exit(1); });
|
|
149
150
|
}
|
|
@@ -182,6 +183,13 @@ else if (arg === 'kb') {
|
|
|
182
183
|
.then(code => process.exit(code))
|
|
183
184
|
.catch(err => { logError('cli', `kb commit failed: ${err.message}`); process.exit(1); });
|
|
184
185
|
}
|
|
186
|
+
else if (subCmd === 'profile') {
|
|
187
|
+
// GitHub #759: show/set the install-wide KB tool profile. Required because
|
|
188
|
+
// the developer profile hides kb_setup from interactive sessions.
|
|
189
|
+
import('./cli/kb-profile.js')
|
|
190
|
+
.then(m => process.exit(m.runKbProfile(process.argv.slice(4))))
|
|
191
|
+
.catch(err => { logError('cli', `kb profile failed: ${err.message}`); process.exit(1); });
|
|
192
|
+
}
|
|
185
193
|
else if (subCmd === 'import') {
|
|
186
194
|
// T2.2 (F4, D3): post-merge entry point for absorbing a merged bible into
|
|
187
195
|
// the local KB. Thin wrapper over the same kbImport the MCP tool uses.
|
|
@@ -310,6 +318,17 @@ function resolveTransport(args) {
|
|
|
310
318
|
}
|
|
311
319
|
return 'invalid';
|
|
312
320
|
}
|
|
321
|
+
/** Clear busy statuses persisted by a server that died mid-task. */
|
|
322
|
+
async function reconcileStartupBusyImpl() {
|
|
323
|
+
const { reconcileStaleBusy } = await import('./services/statusline.js');
|
|
324
|
+
const cleared = reconcileStaleBusy();
|
|
325
|
+
if (cleared.length > 0) {
|
|
326
|
+
logLine('startup', `reset stale busy status for ${cleared.length} member(s) left by a previous server: ${cleared.join(', ')}`);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
function reconcileStartupBusy() {
|
|
330
|
+
void reconcileStartupBusyImpl().catch(() => { });
|
|
331
|
+
}
|
|
313
332
|
async function startStdioServer() {
|
|
314
333
|
const { McpServer } = await import('@modelcontextprotocol/sdk/server/mcp.js');
|
|
315
334
|
const { StdioServerTransport } = await import('@modelcontextprotocol/sdk/server/stdio.js');
|
|
@@ -365,6 +384,7 @@ async function startStdioServer() {
|
|
|
365
384
|
logLine('startup', `apra-fleet ${serverVersion} started transport=stdio${clientStr}${versionStr}${pidStr} FLEET_DIR=${FLEET_DIR}`);
|
|
366
385
|
idleManager.start();
|
|
367
386
|
void cleanupStaleTasks();
|
|
387
|
+
reconcileStartupBusy();
|
|
368
388
|
purgeExpiredCredentials();
|
|
369
389
|
void checkForUpdate();
|
|
370
390
|
// GitHub #562: leave a trace when the event loop freezes.
|
|
@@ -518,6 +538,7 @@ async function startHttpServer() {
|
|
|
518
538
|
logLine('startup', `apra-fleet ${serverVersion} started transport=http port=${handle.port} pid=${process.pid} FLEET_DIR=${FLEET_DIR}`);
|
|
519
539
|
idleManager.start();
|
|
520
540
|
void cleanupStaleTasks();
|
|
541
|
+
reconcileStartupBusy();
|
|
521
542
|
purgeExpiredCredentials();
|
|
522
543
|
void checkForUpdate();
|
|
523
544
|
// GitHub #562: leave a trace when the event loop freezes.
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The git executable every fleet-server git spawn uses.
|
|
3
|
+
*
|
|
4
|
+
* On Windows, CreateProcess (and libuv's own search, which Node's child_process
|
|
5
|
+
* uses) looks in the CURRENT DIRECTORY before PATH when a bare program name is
|
|
6
|
+
* given. Every KB / code-intelligence git call runs with a work folder as its
|
|
7
|
+
* cwd, so `execFileSync('git', ..., { cwd: workFolder })` would run a git.exe
|
|
8
|
+
* planted at the root of that work folder instead of the real git
|
|
9
|
+
* (apra-fleet-rx6b).
|
|
10
|
+
*
|
|
11
|
+
* gitExecutable() therefore resolves git ONCE, on win32, to an absolute path
|
|
12
|
+
* taken ONLY from PATH entries -- never the process cwd or any spawn cwd:
|
|
13
|
+
* - empty and relative PATH entries are skipped (a relative entry, like an
|
|
14
|
+
* empty one, would be resolved against the cwd);
|
|
15
|
+
* - surrounding double quotes on an entry are stripped;
|
|
16
|
+
* - PATHEXT order is honoured, restricted to the extensions a shell-less
|
|
17
|
+
* spawn can run directly (.EXE / .COM). A git.cmd / git.bat shim cannot be
|
|
18
|
+
* spawned without a shell (Node refuses it with EINVAL), so it is never
|
|
19
|
+
* returned; Git for Windows puts cmd\git.exe on PATH.
|
|
20
|
+
* The PATH-only search itself lives in windows-executable.ts (shared with the
|
|
21
|
+
* Windows shells the fleet server starts). The result is cached for the
|
|
22
|
+
* process. A missing git throws GitNotFoundError, one clear error naming PATH, instead of a confusing failure in whichever
|
|
23
|
+
* caller ran first. A failed lookup is not cached, so installing git later
|
|
24
|
+
* starts working without a restart.
|
|
25
|
+
*
|
|
26
|
+
* On every other platform the bare name 'git' is returned unchanged: execvp
|
|
27
|
+
* never searches the cwd unless PATH itself says so.
|
|
28
|
+
*
|
|
29
|
+
* Out of scope: packages/apra-fleet-client git spawns (separate package).
|
|
30
|
+
* Member-bound command STRINGS (src/os/*.ts builders, member-config-io, vcs
|
|
31
|
+
* providers) run on the member through its own shell and are not spawns by
|
|
32
|
+
* the fleet server's own process.
|
|
33
|
+
*/
|
|
34
|
+
import { type WindowsExecutableDeps } from './windows-executable.js';
|
|
35
|
+
export declare const GIT_NOT_FOUND_CODE = "E-GIT-NOT-FOUND";
|
|
36
|
+
export declare class GitNotFoundError extends Error {
|
|
37
|
+
readonly searched: readonly string[];
|
|
38
|
+
readonly code = "E-GIT-NOT-FOUND";
|
|
39
|
+
constructor(searched: readonly string[]);
|
|
40
|
+
}
|
|
41
|
+
/** git has no preferred location: only the PATH fields of the shared deps apply. */
|
|
42
|
+
export type GitResolveDeps = Pick<WindowsExecutableDeps, 'platform' | 'pathValue' | 'pathext' | 'isFile'>;
|
|
43
|
+
export declare function defaultGitResolveDeps(): GitResolveDeps;
|
|
44
|
+
/**
|
|
45
|
+
* Pure resolution (no cache). Returns 'git' on non-Windows platforms; on win32
|
|
46
|
+
* returns an absolute path from a PATH entry or throws GitNotFoundError.
|
|
47
|
+
*/
|
|
48
|
+
export declare function resolveGitExecutable(deps: GitResolveDeps): string;
|
|
49
|
+
/**
|
|
50
|
+
* The git executable for a fleet-server spawn: cached absolute PATH-only
|
|
51
|
+
* resolution on win32, bare 'git' elsewhere. Throws GitNotFoundError on win32
|
|
52
|
+
* when git is not on PATH.
|
|
53
|
+
*/
|
|
54
|
+
export declare function gitExecutable(): string;
|
|
55
|
+
/** Test hook: forget the cached resolution. */
|
|
56
|
+
export declare function resetGitExecutableCache(): void;
|
|
57
|
+
//# sourceMappingURL=git-executable.d.ts.map
|