@mrc2204/agent-smart-memo 5.1.0 → 5.1.2
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 +209 -375
- package/bin/asm.mjs +365 -0
- package/bin/opencode-mcp-server.mjs +320 -0
- package/dist/core/contracts/adapter-contracts.d.ts +1 -1
- package/dist/core/contracts/adapter-contracts.d.ts.map +1 -1
- package/dist/core/contracts/change-overlay-contracts.d.ts +69 -0
- package/dist/core/contracts/change-overlay-contracts.d.ts.map +1 -0
- package/dist/core/contracts/change-overlay-contracts.js +2 -0
- package/dist/core/contracts/change-overlay-contracts.js.map +1 -0
- package/dist/core/contracts/feature-pack-contracts.d.ts +37 -0
- package/dist/core/contracts/feature-pack-contracts.d.ts.map +1 -0
- package/dist/core/contracts/feature-pack-contracts.js +8 -0
- package/dist/core/contracts/feature-pack-contracts.js.map +1 -0
- package/dist/core/contracts/project-query-contracts.d.ts +84 -0
- package/dist/core/contracts/project-query-contracts.d.ts.map +1 -0
- package/dist/core/contracts/project-query-contracts.js +2 -0
- package/dist/core/contracts/project-query-contracts.js.map +1 -0
- package/dist/core/graph/code-graph-model.d.ts +9 -0
- package/dist/core/graph/code-graph-model.d.ts.map +1 -0
- package/dist/core/graph/code-graph-model.js +70 -0
- package/dist/core/graph/code-graph-model.js.map +1 -0
- package/dist/core/graph/code-graph-populator.d.ts +20 -0
- package/dist/core/graph/code-graph-populator.d.ts.map +1 -0
- package/dist/core/graph/code-graph-populator.js +760 -0
- package/dist/core/graph/code-graph-populator.js.map +1 -0
- package/dist/core/graph/contracts.d.ts +29 -0
- package/dist/core/graph/contracts.d.ts.map +1 -0
- package/dist/core/graph/contracts.js +47 -0
- package/dist/core/graph/contracts.js.map +1 -0
- package/dist/core/ingest/contracts.d.ts +1 -1
- package/dist/core/ingest/contracts.d.ts.map +1 -1
- package/dist/core/ingest/ingest-pipeline.js +1 -1
- package/dist/core/ingest/ingest-pipeline.js.map +1 -1
- package/dist/core/ingest/semantic-block-extractor.d.ts.map +1 -1
- package/dist/core/ingest/semantic-block-extractor.js +36 -0
- package/dist/core/ingest/semantic-block-extractor.js.map +1 -1
- package/dist/core/usecases/default-memory-usecase-port.d.ts +35 -0
- package/dist/core/usecases/default-memory-usecase-port.d.ts.map +1 -1
- package/dist/core/usecases/default-memory-usecase-port.js +1578 -19
- package/dist/core/usecases/default-memory-usecase-port.js.map +1 -1
- package/dist/db/graph-db.d.ts +24 -0
- package/dist/db/graph-db.d.ts.map +1 -1
- package/dist/db/graph-db.js +81 -2
- package/dist/db/graph-db.js.map +1 -1
- package/dist/db/slot-db.d.ts +227 -1
- package/dist/db/slot-db.d.ts.map +1 -1
- package/dist/db/slot-db.js +700 -13
- package/dist/db/slot-db.js.map +1 -1
- package/dist/index.d.ts +7 -247
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +32 -119
- package/dist/index.js.map +1 -1
- package/dist/shared/asm-config.d.ts +82 -0
- package/dist/shared/asm-config.d.ts.map +1 -0
- package/dist/shared/asm-config.js +254 -0
- package/dist/shared/asm-config.js.map +1 -0
- package/dist/shared/slotdb-path.d.ts +4 -3
- package/dist/shared/slotdb-path.d.ts.map +1 -1
- package/dist/shared/slotdb-path.js +15 -6
- package/dist/shared/slotdb-path.js.map +1 -1
- package/dist/tools/graph-tools.d.ts.map +1 -1
- package/dist/tools/graph-tools.js +131 -0
- package/dist/tools/graph-tools.js.map +1 -1
- package/dist/tools/project-tools.d.ts.map +1 -1
- package/dist/tools/project-tools.js +476 -1
- package/dist/tools/project-tools.js.map +1 -1
- package/openclaw.plugin.json +5 -164
- package/package.json +61 -26
- package/scripts/init-openclaw.mjs +727 -0
|
@@ -2,6 +2,10 @@ import { execSync } from "node:child_process";
|
|
|
2
2
|
import { createHash } from "node:crypto";
|
|
3
3
|
import { chmodSync, existsSync, mkdirSync, readdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
|
|
4
4
|
import { basename, dirname, isAbsolute, resolve } from "node:path";
|
|
5
|
+
import { UNIVERSAL_GRAPH_MODEL_VERSION, isUniversalGraphNodeType, isUniversalGraphRelationType, isValidUniversalGraphProvenance, } from "../graph/contracts.js";
|
|
6
|
+
import { upsertUniversalGraphNode, upsertUniversalGraphRelation, } from "../graph/code-graph-model.js";
|
|
7
|
+
import { FEATURE_PACK_KEYS, } from "../contracts/feature-pack-contracts.js";
|
|
8
|
+
import { resolveAsmCoreProjectWorkspaceRoot } from "../../shared/asm-config.js";
|
|
5
9
|
function asRecord(value) {
|
|
6
10
|
return value && typeof value === "object" && !Array.isArray(value)
|
|
7
11
|
? value
|
|
@@ -35,6 +39,9 @@ function allScopeIdentities(ctx) {
|
|
|
35
39
|
function randomJobId() {
|
|
36
40
|
return `idxjob_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 10)}`;
|
|
37
41
|
}
|
|
42
|
+
function sha1(raw) {
|
|
43
|
+
return createHash("sha1").update(raw).digest("hex");
|
|
44
|
+
}
|
|
38
45
|
function shellEscape(value) {
|
|
39
46
|
const input = String(value || "");
|
|
40
47
|
return `'${input.replace(/'/g, `'"'"'`)}'`;
|
|
@@ -61,6 +68,10 @@ export class DefaultMemoryUseCasePort {
|
|
|
61
68
|
return this.handleProjectRegister(payload, req);
|
|
62
69
|
case "project.get":
|
|
63
70
|
return this.handleProjectGet(payload, req);
|
|
71
|
+
case "project.binding_preview":
|
|
72
|
+
return this.handleProjectBindingPreview(payload, req);
|
|
73
|
+
case "project.opencode_search":
|
|
74
|
+
return this.handleProjectOpenCodeSearch(payload, req);
|
|
64
75
|
case "project.list":
|
|
65
76
|
return this.handleProjectList(req);
|
|
66
77
|
case "project.set_registration_state":
|
|
@@ -73,6 +84,16 @@ export class DefaultMemoryUseCasePort {
|
|
|
73
84
|
return this.handleProjectLinkTracker(payload, req);
|
|
74
85
|
case "project.trigger_index":
|
|
75
86
|
return this.handleProjectTriggerIndex(payload, req);
|
|
87
|
+
case "project.deindex":
|
|
88
|
+
return this.handleProjectDeindex(payload, req);
|
|
89
|
+
case "project.detach":
|
|
90
|
+
return this.handleProjectDetach(payload, req);
|
|
91
|
+
case "project.unregister":
|
|
92
|
+
return this.handleProjectUnregister(payload, req);
|
|
93
|
+
case "project.purge_preview":
|
|
94
|
+
return this.handleProjectPurgePreview(payload, req);
|
|
95
|
+
case "project.purge":
|
|
96
|
+
return this.handleProjectPurge(payload, req);
|
|
76
97
|
case "project.reindex_diff":
|
|
77
98
|
return this.handleProjectReindexDiff(payload, req);
|
|
78
99
|
case "project.index_event":
|
|
@@ -87,10 +108,18 @@ export class DefaultMemoryUseCasePort {
|
|
|
87
108
|
return this.handleProjectTaskLineageContext(payload, req);
|
|
88
109
|
case "project.hybrid_search":
|
|
89
110
|
return this.handleProjectHybridSearch(payload, req);
|
|
111
|
+
case "project.change_overlay.query":
|
|
112
|
+
return this.handleProjectChangeOverlayQuery(payload, req);
|
|
90
113
|
case "project.legacy_backfill":
|
|
91
114
|
return this.handleProjectLegacyBackfill(payload, req);
|
|
92
115
|
case "project.telegram_onboarding":
|
|
93
116
|
return this.handleProjectTelegramOnboarding(payload, req);
|
|
117
|
+
case "project.feature_pack.generate":
|
|
118
|
+
return this.handleProjectFeaturePackGenerate(payload, req);
|
|
119
|
+
case "project.feature_pack.query":
|
|
120
|
+
return this.handleProjectFeaturePackQuery(payload, req);
|
|
121
|
+
case "project.developer_query":
|
|
122
|
+
return this.handleProjectDeveloperQuery(payload, req);
|
|
94
123
|
case "graph.entity.get":
|
|
95
124
|
return this.handleGraphEntityGet(payload, req);
|
|
96
125
|
case "graph.entity.set":
|
|
@@ -101,6 +130,10 @@ export class DefaultMemoryUseCasePort {
|
|
|
101
130
|
return this.handleGraphRelRemove(payload, req);
|
|
102
131
|
case "graph.search":
|
|
103
132
|
return this.handleGraphSearch(payload, req);
|
|
133
|
+
case "graph.code.upsert":
|
|
134
|
+
return this.handleGraphCodeUpsert(payload, req);
|
|
135
|
+
case "graph.code.chain":
|
|
136
|
+
return this.handleGraphCodeChain(payload, req);
|
|
104
137
|
case "memory.capture":
|
|
105
138
|
return this.handleMemoryCapture(payload, req);
|
|
106
139
|
case "memory.search":
|
|
@@ -253,6 +286,143 @@ export class DefaultMemoryUseCasePort {
|
|
|
253
286
|
const identity = normalizePrivateIdentity(req.context);
|
|
254
287
|
return this.slotDb.listProjects(identity.userId, identity.agentId);
|
|
255
288
|
}
|
|
289
|
+
handleProjectBindingPreview(payload, req) {
|
|
290
|
+
const identity = normalizePrivateIdentity(req.context);
|
|
291
|
+
const projects = this.slotDb.listProjects(identity.userId, identity.agentId);
|
|
292
|
+
const normalizedRepoRoot = this.normalizeRepoRootInput(payload.repo_root);
|
|
293
|
+
const aliasSelector = String(payload.project_alias || payload.session_project_alias || "").trim();
|
|
294
|
+
const matches = [];
|
|
295
|
+
const pushMatch = (project, aliases, source) => {
|
|
296
|
+
if (matches.some((item) => item.project_id === project.project_id && item.source === source))
|
|
297
|
+
return;
|
|
298
|
+
matches.push({
|
|
299
|
+
project_id: project.project_id,
|
|
300
|
+
project_alias: aliases.find((item) => item.is_primary === 1)?.project_alias || aliases[0]?.project_alias || null,
|
|
301
|
+
project_name: project.project_name,
|
|
302
|
+
repo_root: project.repo_root,
|
|
303
|
+
lifecycle_status: project.lifecycle_status,
|
|
304
|
+
source,
|
|
305
|
+
});
|
|
306
|
+
};
|
|
307
|
+
if (payload.project_id) {
|
|
308
|
+
const direct = this.slotDb.getProjectById(identity.userId, identity.agentId, payload.project_id);
|
|
309
|
+
if (direct) {
|
|
310
|
+
const row = projects.find((item) => item.project.project_id === direct.project_id);
|
|
311
|
+
pushMatch(direct, row?.aliases || [], "project_id");
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
if (aliasSelector) {
|
|
315
|
+
const byAlias = this.slotDb.getProjectByAlias(identity.userId, identity.agentId, aliasSelector);
|
|
316
|
+
if (byAlias) {
|
|
317
|
+
const row = projects.find((item) => item.project.project_id === byAlias.project.project_id);
|
|
318
|
+
pushMatch(byAlias.project, row?.aliases || [byAlias.alias], payload.project_alias ? "project_alias" : "session_project_alias");
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
if (normalizedRepoRoot) {
|
|
322
|
+
for (const row of projects) {
|
|
323
|
+
const projectRepoRoot = this.normalizeRepoRootInput(row.project.repo_root || undefined);
|
|
324
|
+
if (projectRepoRoot && projectRepoRoot === normalizedRepoRoot) {
|
|
325
|
+
pushMatch(row.project, row.aliases, "repo_root");
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
const uniqueByProject = Array.from(new Map(matches.map((item) => [item.project_id, item])).values());
|
|
330
|
+
const activeMatches = uniqueByProject.filter((item) => item.lifecycle_status === "active");
|
|
331
|
+
const crossProjectRequired = activeMatches.length > 1;
|
|
332
|
+
const allowed = !crossProjectRequired || payload.allow_cross_project === true;
|
|
333
|
+
const selected = activeMatches[0] || uniqueByProject[0] || null;
|
|
334
|
+
const resolutionStatus = selected
|
|
335
|
+
? (crossProjectRequired && !allowed ? "ambiguous" : "resolved")
|
|
336
|
+
: "unresolved";
|
|
337
|
+
const resolutionReason = resolutionStatus === "ambiguous"
|
|
338
|
+
? "multiple_active_projects"
|
|
339
|
+
: resolutionStatus === "unresolved"
|
|
340
|
+
? (normalizedRepoRoot ? "unregistered_repo_root" : "selector_not_matched")
|
|
341
|
+
: "matched";
|
|
342
|
+
return {
|
|
343
|
+
mode: "read-only",
|
|
344
|
+
project_scoped_by_default: true,
|
|
345
|
+
cross_project_allowed: payload.allow_cross_project === true,
|
|
346
|
+
resolution_status: resolutionStatus,
|
|
347
|
+
selected_project: selected,
|
|
348
|
+
candidate_projects: uniqueByProject,
|
|
349
|
+
resolution: {
|
|
350
|
+
selectors: {
|
|
351
|
+
project_id: payload.project_id || null,
|
|
352
|
+
project_alias: payload.project_alias || null,
|
|
353
|
+
session_project_alias: payload.session_project_alias || null,
|
|
354
|
+
repo_root: normalizedRepoRoot || null,
|
|
355
|
+
},
|
|
356
|
+
reason: resolutionReason,
|
|
357
|
+
cross_project_required: crossProjectRequired,
|
|
358
|
+
explicit_cross_project_required: crossProjectRequired,
|
|
359
|
+
read_only_tool_surface: ["project_registry_get", "project_registry_list", "project_hybrid_search", "project_developer_query"],
|
|
360
|
+
},
|
|
361
|
+
errors: selected
|
|
362
|
+
? (crossProjectRequired && !allowed ? ["multiple active project matches found; explicit cross-project approval required"] : [])
|
|
363
|
+
: [normalizedRepoRoot ? "no active registered project matched repo_root" : "no registered project matched provided selectors"],
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
handleProjectOpenCodeSearch(payload, req) {
|
|
367
|
+
const binding = this.handleProjectBindingPreview({
|
|
368
|
+
project_id: payload.explicit_project_id || payload.project_id,
|
|
369
|
+
project_alias: payload.explicit_project_alias || payload.project_alias,
|
|
370
|
+
repo_root: payload.repo_root,
|
|
371
|
+
session_project_alias: payload.session_project_alias,
|
|
372
|
+
allow_cross_project: payload.explicit_cross_project || payload.allow_cross_project,
|
|
373
|
+
}, req);
|
|
374
|
+
if (binding.resolution_status !== "resolved" || !binding.selected_project?.project_id) {
|
|
375
|
+
return {
|
|
376
|
+
mode: "read-only",
|
|
377
|
+
resolution_status: binding.resolution_status,
|
|
378
|
+
binding,
|
|
379
|
+
query: payload.query,
|
|
380
|
+
results: null,
|
|
381
|
+
errors: binding.errors || ["project binding could not be resolved for read-only search"],
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
const selectedProjectId = binding.selected_project.project_id;
|
|
385
|
+
const selectedProjectAlias = binding.selected_project.project_alias;
|
|
386
|
+
const selectedLifecycle = String(binding.selected_project.lifecycle_status || "active");
|
|
387
|
+
if (["deindexed", "detached", "disabled", "purged"].includes(selectedLifecycle)) {
|
|
388
|
+
return {
|
|
389
|
+
mode: "read-only",
|
|
390
|
+
resolution_status: "resolved",
|
|
391
|
+
binding,
|
|
392
|
+
query: payload.query,
|
|
393
|
+
results: {
|
|
394
|
+
project_id: selectedProjectId,
|
|
395
|
+
project_alias: selectedProjectAlias || null,
|
|
396
|
+
project_lifecycle_status: selectedLifecycle,
|
|
397
|
+
searchable: false,
|
|
398
|
+
count: 0,
|
|
399
|
+
results: [],
|
|
400
|
+
reason: selectedLifecycle === "deindexed"
|
|
401
|
+
? "project is deindexed; read-only retrieval is disabled until reindex"
|
|
402
|
+
: selectedLifecycle === "detached"
|
|
403
|
+
? "project is detached; read-only retrieval is disabled until re-attachment"
|
|
404
|
+
: selectedLifecycle === "disabled"
|
|
405
|
+
? "project is unregistered/disabled; read-only retrieval is disabled"
|
|
406
|
+
: "project is purged; read-only retrieval is disabled",
|
|
407
|
+
},
|
|
408
|
+
errors: [],
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
const results = this.handleProjectDeveloperQuery({
|
|
412
|
+
project_id: selectedProjectId,
|
|
413
|
+
project_alias: selectedProjectAlias || undefined,
|
|
414
|
+
query: payload.query,
|
|
415
|
+
limit: payload.limit,
|
|
416
|
+
}, req);
|
|
417
|
+
return {
|
|
418
|
+
mode: "read-only",
|
|
419
|
+
resolution_status: "resolved",
|
|
420
|
+
binding,
|
|
421
|
+
query: payload.query,
|
|
422
|
+
results,
|
|
423
|
+
errors: [],
|
|
424
|
+
};
|
|
425
|
+
}
|
|
256
426
|
handleProjectSetRegistrationState(payload, req) {
|
|
257
427
|
const identity = normalizePrivateIdentity(req.context);
|
|
258
428
|
if (!payload.project_id) {
|
|
@@ -423,7 +593,7 @@ export class DefaultMemoryUseCasePort {
|
|
|
423
593
|
const project = this.resolveProjectRef(identity.userId, identity.agentId, payload.project_ref);
|
|
424
594
|
const queuedAt = new Date().toISOString();
|
|
425
595
|
const jobId = randomJobId();
|
|
426
|
-
const normalizedPaths = (payload.paths || []).filter((item) => String(item.relative_path || "").trim().length > 0);
|
|
596
|
+
const normalizedPaths = this.hydrateIndexPathsFromRepo(project.repo_root, (payload.paths || []).filter((item) => String(item.relative_path || "").trim().length > 0));
|
|
427
597
|
this.scheduleProjectReindexJob({
|
|
428
598
|
scopeUserId: identity.userId,
|
|
429
599
|
scopeAgentId: identity.agentId,
|
|
@@ -452,13 +622,16 @@ export class DefaultMemoryUseCasePort {
|
|
|
452
622
|
scheduleProjectReindexJob(input) {
|
|
453
623
|
setTimeout(() => {
|
|
454
624
|
try {
|
|
625
|
+
const project = this.slotDb.getProjectById(input.scopeUserId, input.scopeAgentId, input.projectId);
|
|
455
626
|
let paths = input.paths;
|
|
456
627
|
if (paths.length === 0) {
|
|
457
|
-
const project = this.slotDb.getProjectById(input.scopeUserId, input.scopeAgentId, input.projectId);
|
|
458
628
|
if (project?.repo_root) {
|
|
459
629
|
paths = this.collectGitTrackedPaths(project.repo_root);
|
|
460
630
|
}
|
|
461
631
|
}
|
|
632
|
+
else {
|
|
633
|
+
paths = this.hydrateIndexPathsFromRepo(project?.repo_root, paths);
|
|
634
|
+
}
|
|
462
635
|
if (paths.length === 0)
|
|
463
636
|
return;
|
|
464
637
|
this.slotDb.reindexProjectByDiff(input.scopeUserId, input.scopeAgentId, {
|
|
@@ -494,25 +667,86 @@ export class DefaultMemoryUseCasePort {
|
|
|
494
667
|
if (!repoRoot)
|
|
495
668
|
return { installed: false, hooks: [], note: 'repo_root_missing' };
|
|
496
669
|
const gitDir = resolve(repoRoot, '.git');
|
|
497
|
-
const hooksDir = resolve(gitDir, 'hooks');
|
|
498
670
|
if (!existsSync(gitDir))
|
|
499
671
|
return { installed: false, hooks: [], note: 'git_dir_missing' };
|
|
672
|
+
let hooksDir = resolve(gitDir, 'hooks');
|
|
673
|
+
try {
|
|
674
|
+
const hooksPath = execSync('git config --get core.hooksPath', { cwd: repoRoot, stdio: ['ignore', 'pipe', 'ignore'], encoding: 'utf8' }).trim();
|
|
675
|
+
if (hooksPath)
|
|
676
|
+
hooksDir = resolve(repoRoot, hooksPath);
|
|
677
|
+
}
|
|
678
|
+
catch { }
|
|
500
679
|
mkdirSync(hooksDir, { recursive: true });
|
|
501
|
-
const
|
|
502
|
-
|
|
503
|
-
|
|
680
|
+
const listenerPath = resolve(hooksDir, 'asm-project-event.sh');
|
|
681
|
+
const marker = '# ASM_AUTO_INDEX_HOOK';
|
|
682
|
+
const listener = `#!/bin/sh
|
|
504
683
|
PROJECT_ID="${projectId}"
|
|
505
684
|
REPO_ROOT="${repoRoot}"
|
|
685
|
+
EVENT_TYPE="$1"
|
|
506
686
|
SOURCE_REV="$(git rev-parse HEAD 2>/dev/null || echo unknown)"
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
687
|
+
DEFAULT_BRANCH="$(git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null | sed 's@^refs/remotes/origin/@@')"
|
|
688
|
+
CURRENT_BRANCH="$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo unknown)"
|
|
689
|
+
WORKTREE_DIRTY="$(if git diff --quiet --ignore-submodules HEAD -- 2>/dev/null && git diff --cached --quiet --ignore-submodules -- 2>/dev/null; then echo 0; else echo 1; fi)"
|
|
690
|
+
TRUSTED_SYNC="0"
|
|
691
|
+
FULL_SNAPSHOT="0"
|
|
692
|
+
CHANGED_FILES=""
|
|
693
|
+
DELETED_FILES=""
|
|
694
|
+
|
|
695
|
+
if [ "$EVENT_TYPE" = "post_commit" ]; then
|
|
696
|
+
CHANGED_FILES="$(git diff-tree --no-commit-id --name-only -r HEAD 2>/dev/null | paste -sd, -)"
|
|
697
|
+
DELETED_FILES="$(git diff-tree --no-commit-id --name-only --diff-filter=D -r HEAD 2>/dev/null | paste -sd, -)"
|
|
698
|
+
fi
|
|
699
|
+
|
|
700
|
+
if [ -n "$DEFAULT_BRANCH" ] && [ "$CURRENT_BRANCH" = "$DEFAULT_BRANCH" ] && [ "$WORKTREE_DIRTY" = "0" ]; then
|
|
701
|
+
if git rev-parse --verify "origin/$DEFAULT_BRANCH" >/dev/null 2>&1; then
|
|
702
|
+
LOCAL_HEAD="$(git rev-parse HEAD 2>/dev/null || echo unknown)"
|
|
703
|
+
REMOTE_HEAD="$(git rev-parse "origin/$DEFAULT_BRANCH" 2>/dev/null || echo unknown)"
|
|
704
|
+
if [ "$LOCAL_HEAD" = "$REMOTE_HEAD" ]; then
|
|
705
|
+
TRUSTED_SYNC="1"
|
|
706
|
+
FULL_SNAPSHOT="1"
|
|
707
|
+
fi
|
|
708
|
+
fi
|
|
709
|
+
fi
|
|
710
|
+
|
|
711
|
+
if [ "$TRUSTED_SYNC" = "1" ]; then
|
|
712
|
+
CHANGED_FILES="$(git ls-files 2>/dev/null | paste -sd, -)"
|
|
713
|
+
DELETED_FILES=""
|
|
714
|
+
fi
|
|
715
|
+
|
|
716
|
+
asm project-event --project-id "$PROJECT_ID" --repo-root "$REPO_ROOT" --event-type "$EVENT_TYPE" --source-rev "$SOURCE_REV" --changed-files "$CHANGED_FILES" --deleted-files "$DELETED_FILES" --trusted-sync "$TRUSTED_SYNC" --full-snapshot "$FULL_SNAPSHOT" >/dev/null 2>&1 || true
|
|
510
717
|
`;
|
|
511
|
-
|
|
718
|
+
writeFileSync(listenerPath, listener, 'utf8');
|
|
719
|
+
chmodSync(listenerPath, 0o755);
|
|
720
|
+
const attachHook = (name, eventType) => {
|
|
721
|
+
const hookPath = resolve(hooksDir, name);
|
|
722
|
+
const callLine = `${marker}\n\"${listenerPath}\" ${eventType} || true`;
|
|
723
|
+
let content = existsSync(hookPath) ? readFileSync(hookPath, 'utf8') : '';
|
|
724
|
+
if (content.includes(marker))
|
|
725
|
+
return hookPath;
|
|
726
|
+
if (!content.trim()) {
|
|
727
|
+
content = `#!/bin/sh\n\n${callLine}\n`;
|
|
728
|
+
}
|
|
729
|
+
else {
|
|
730
|
+
const backupPath = `${hookPath}.asm-backup`;
|
|
731
|
+
if (!existsSync(backupPath))
|
|
732
|
+
writeFileSync(backupPath, content, 'utf8');
|
|
733
|
+
if (!content.startsWith('#!')) {
|
|
734
|
+
content = `#!/bin/sh\n${content}`;
|
|
735
|
+
}
|
|
736
|
+
if (!content.endsWith('\n'))
|
|
737
|
+
content += '\n';
|
|
738
|
+
content += `\n${callLine}\n`;
|
|
739
|
+
}
|
|
740
|
+
writeFileSync(hookPath, content, 'utf8');
|
|
512
741
|
chmodSync(hookPath, 0o755);
|
|
513
742
|
return hookPath;
|
|
514
743
|
};
|
|
515
|
-
const hooks = [
|
|
744
|
+
const hooks = [
|
|
745
|
+
attachHook('post-commit', 'post_commit'),
|
|
746
|
+
attachHook('post-merge', 'post_merge'),
|
|
747
|
+
attachHook('post-rewrite', 'post_rewrite'),
|
|
748
|
+
listenerPath,
|
|
749
|
+
];
|
|
516
750
|
return { installed: true, hooks };
|
|
517
751
|
}
|
|
518
752
|
validateJiraTrackerFields(trackerSpaceKey, defaultEpicKey) {
|
|
@@ -551,9 +785,7 @@ asm project-event --project-id "$PROJECT_ID" --repo-root "$REPO_ROOT" --event-ty
|
|
|
551
785
|
process.env.PROJECT_WORKSPACE_ROOT,
|
|
552
786
|
process.env.REPO_CLONE_ROOT,
|
|
553
787
|
req?.meta?.projectWorkspaceRoot,
|
|
554
|
-
req?.meta?.repoCloneRoot,
|
|
555
788
|
req?.context?.metadata?.projectWorkspaceRoot,
|
|
556
|
-
req?.context?.metadata?.repoCloneRoot,
|
|
557
789
|
req?.context?.metadata?.workspaceRoot,
|
|
558
790
|
];
|
|
559
791
|
for (const raw of candidates) {
|
|
@@ -570,6 +802,20 @@ asm project-event --project-id "$PROJECT_ID" --repo-root "$REPO_ROOT" --event-ty
|
|
|
570
802
|
if (existsSync(resolved))
|
|
571
803
|
return resolved;
|
|
572
804
|
}
|
|
805
|
+
const sharedWorkspaceRoot = resolveAsmCoreProjectWorkspaceRoot({ env: process.env, homeDir: process.env.HOME });
|
|
806
|
+
if (sharedWorkspaceRoot) {
|
|
807
|
+
const resolved = isAbsolute(sharedWorkspaceRoot)
|
|
808
|
+
? resolve(sharedWorkspaceRoot)
|
|
809
|
+
: resolve(process.cwd(), sharedWorkspaceRoot);
|
|
810
|
+
try {
|
|
811
|
+
mkdirSync(resolved, { recursive: true });
|
|
812
|
+
}
|
|
813
|
+
catch {
|
|
814
|
+
// ignore and fallback
|
|
815
|
+
}
|
|
816
|
+
if (existsSync(resolved))
|
|
817
|
+
return resolved;
|
|
818
|
+
}
|
|
573
819
|
const fallback = resolve(process.env.HOME || process.cwd(), ".openclaw", "workspace", "projects");
|
|
574
820
|
mkdirSync(fallback, { recursive: true });
|
|
575
821
|
return fallback;
|
|
@@ -846,7 +1092,7 @@ asm project-event --project-id "$PROJECT_ID" --repo-root "$REPO_ROOT" --event-ty
|
|
|
846
1092
|
}
|
|
847
1093
|
return {
|
|
848
1094
|
relative_path: relativePath,
|
|
849
|
-
checksum: `git:${relativePath}`,
|
|
1095
|
+
checksum: content != null ? sha1(content) : `git:${relativePath}`,
|
|
850
1096
|
module: relativePath.split("/")[0] || undefined,
|
|
851
1097
|
language: ext || undefined,
|
|
852
1098
|
content,
|
|
@@ -887,7 +1133,7 @@ asm project-event --project-id "$PROJECT_ID" --repo-root "$REPO_ROOT" --event-ty
|
|
|
887
1133
|
}
|
|
888
1134
|
return {
|
|
889
1135
|
relative_path: relativePath,
|
|
890
|
-
checksum: `fs:${relativePath}`,
|
|
1136
|
+
checksum: content != null ? sha1(content) : `fs:${relativePath}`,
|
|
891
1137
|
module: relativePath.split("/")[0] || undefined,
|
|
892
1138
|
language: relativePath.includes(".") ? relativePath.split(".").pop() || undefined : undefined,
|
|
893
1139
|
content,
|
|
@@ -895,6 +1141,77 @@ asm project-event --project-id "$PROJECT_ID" --repo-root "$REPO_ROOT" --event-ty
|
|
|
895
1141
|
});
|
|
896
1142
|
}
|
|
897
1143
|
}
|
|
1144
|
+
hydrateIndexPathsFromRepo(repoRoot, paths) {
|
|
1145
|
+
if (!repoRoot)
|
|
1146
|
+
return paths;
|
|
1147
|
+
return paths.map((item) => {
|
|
1148
|
+
const relativePath = String(item.relative_path || '').trim();
|
|
1149
|
+
if (!relativePath)
|
|
1150
|
+
return item;
|
|
1151
|
+
const abs = resolve(repoRoot, relativePath);
|
|
1152
|
+
let content = item.content;
|
|
1153
|
+
if ((content == null || content === '') && existsSync(abs)) {
|
|
1154
|
+
try {
|
|
1155
|
+
content = readFileSync(abs, 'utf8');
|
|
1156
|
+
}
|
|
1157
|
+
catch {
|
|
1158
|
+
content = item.content;
|
|
1159
|
+
}
|
|
1160
|
+
}
|
|
1161
|
+
const checksum = content != null && String(content).trim() !== ''
|
|
1162
|
+
? sha1(String(content))
|
|
1163
|
+
: (item.checksum || null);
|
|
1164
|
+
return {
|
|
1165
|
+
...item,
|
|
1166
|
+
checksum,
|
|
1167
|
+
content,
|
|
1168
|
+
};
|
|
1169
|
+
});
|
|
1170
|
+
}
|
|
1171
|
+
handleProjectDeindex(payload, req) {
|
|
1172
|
+
const identity = normalizePrivateIdentity(req.context);
|
|
1173
|
+
if (!payload.project_id) {
|
|
1174
|
+
throw new Error("project.deindex requires payload.project_id");
|
|
1175
|
+
}
|
|
1176
|
+
return this.slotDb.deindexProject(identity.userId, identity.agentId, {
|
|
1177
|
+
project_id: payload.project_id,
|
|
1178
|
+
reason: payload.reason,
|
|
1179
|
+
});
|
|
1180
|
+
}
|
|
1181
|
+
handleProjectDetach(payload, req) {
|
|
1182
|
+
const identity = normalizePrivateIdentity(req.context);
|
|
1183
|
+
const project = this.resolveProjectRef(identity.userId, identity.agentId, payload.project_ref || {});
|
|
1184
|
+
return this.slotDb.detachProject(identity.userId, identity.agentId, {
|
|
1185
|
+
project_id: project.project_id,
|
|
1186
|
+
reason: payload.reason,
|
|
1187
|
+
});
|
|
1188
|
+
}
|
|
1189
|
+
handleProjectUnregister(payload, req) {
|
|
1190
|
+
const identity = normalizePrivateIdentity(req.context);
|
|
1191
|
+
const project = this.resolveProjectRef(identity.userId, identity.agentId, payload.project_ref || {});
|
|
1192
|
+
return this.slotDb.unregisterProject(identity.userId, identity.agentId, {
|
|
1193
|
+
project_id: project.project_id,
|
|
1194
|
+
confirm: payload.confirm,
|
|
1195
|
+
mode: payload.mode,
|
|
1196
|
+
reason: payload.reason,
|
|
1197
|
+
});
|
|
1198
|
+
}
|
|
1199
|
+
handleProjectPurgePreview(payload, req) {
|
|
1200
|
+
const identity = normalizePrivateIdentity(req.context);
|
|
1201
|
+
const project = this.resolveProjectRef(identity.userId, identity.agentId, payload.project_ref || {});
|
|
1202
|
+
return this.slotDb.purgePreviewProject(identity.userId, identity.agentId, {
|
|
1203
|
+
project_id: project.project_id,
|
|
1204
|
+
});
|
|
1205
|
+
}
|
|
1206
|
+
handleProjectPurge(payload, req) {
|
|
1207
|
+
const identity = normalizePrivateIdentity(req.context);
|
|
1208
|
+
const project = this.resolveProjectRef(identity.userId, identity.agentId, payload.project_ref || {});
|
|
1209
|
+
return this.slotDb.purgeProject(identity.userId, identity.agentId, {
|
|
1210
|
+
project_id: project.project_id,
|
|
1211
|
+
confirm: payload.confirm,
|
|
1212
|
+
reason: payload.reason,
|
|
1213
|
+
});
|
|
1214
|
+
}
|
|
898
1215
|
handleProjectReindexDiff(payload, req) {
|
|
899
1216
|
const identity = normalizePrivateIdentity(req.context);
|
|
900
1217
|
if (!payload.project_id) {
|
|
@@ -918,8 +1235,15 @@ asm project-event --project-id "$PROJECT_ID" --repo-root "$REPO_ROOT" --event-ty
|
|
|
918
1235
|
if (!project || !project.repo_root) {
|
|
919
1236
|
throw new Error("project.index_event requires a registered project with repo_root");
|
|
920
1237
|
}
|
|
1238
|
+
const registeredRepoRoot = this.normalizeRepoRootInput(project.repo_root || undefined);
|
|
1239
|
+
const eventRepoRoot = this.normalizeRepoRootInput(payload.repo_root || undefined);
|
|
1240
|
+
if (eventRepoRoot && registeredRepoRoot && eventRepoRoot !== registeredRepoRoot) {
|
|
1241
|
+
throw new Error(`project.index_event repo_root mismatch: event='${eventRepoRoot}' registered='${registeredRepoRoot}'`);
|
|
1242
|
+
}
|
|
921
1243
|
const changedFiles = Array.from(new Set((payload.changed_files || []).map((x) => String(x || "").trim()).filter(Boolean)));
|
|
922
1244
|
const deletedFiles = Array.from(new Set((payload.deleted_files || []).map((x) => String(x || "").trim()).filter(Boolean)));
|
|
1245
|
+
const trustedSync = payload.trusted_sync === true;
|
|
1246
|
+
const fullSnapshot = payload.full_snapshot === true || trustedSync;
|
|
923
1247
|
const paths = changedFiles.map((relativePath) => {
|
|
924
1248
|
const abs = resolve(project.repo_root, relativePath);
|
|
925
1249
|
let content = null;
|
|
@@ -931,7 +1255,7 @@ asm project-event --project-id "$PROJECT_ID" --repo-root "$REPO_ROOT" --event-ty
|
|
|
931
1255
|
}
|
|
932
1256
|
return {
|
|
933
1257
|
relative_path: relativePath,
|
|
934
|
-
checksum: `event:${relativePath}:${payload.source_rev || "unknown"}`,
|
|
1258
|
+
checksum: content != null && String(content).trim() !== '' ? sha1(String(content)) : `event:${relativePath}:${payload.source_rev || "unknown"}`,
|
|
935
1259
|
module: relativePath.split("/")[0] || undefined,
|
|
936
1260
|
language: relativePath.includes(".") ? relativePath.split(".").pop() || undefined : undefined,
|
|
937
1261
|
content,
|
|
@@ -940,9 +1264,9 @@ asm project-event --project-id "$PROJECT_ID" --repo-root "$REPO_ROOT" --event-ty
|
|
|
940
1264
|
const reindex = this.slotDb.reindexProjectByDiff(identity.userId, identity.agentId, {
|
|
941
1265
|
project_id: payload.project_id,
|
|
942
1266
|
source_rev: payload.source_rev || null,
|
|
943
|
-
trigger_type: "incremental",
|
|
944
|
-
index_profile: "default",
|
|
945
|
-
full_snapshot:
|
|
1267
|
+
trigger_type: trustedSync ? "repair" : "incremental",
|
|
1268
|
+
index_profile: trustedSync ? "authoritative" : "default",
|
|
1269
|
+
full_snapshot: fullSnapshot,
|
|
946
1270
|
paths,
|
|
947
1271
|
});
|
|
948
1272
|
if (deletedFiles.length > 0) {
|
|
@@ -955,6 +1279,8 @@ asm project-event --project-id "$PROJECT_ID" --repo-root "$REPO_ROOT" --event-ty
|
|
|
955
1279
|
project_id: payload.project_id,
|
|
956
1280
|
event_type: payload.event_type || "manual",
|
|
957
1281
|
source_rev: payload.source_rev || null,
|
|
1282
|
+
trusted_sync: trustedSync,
|
|
1283
|
+
full_snapshot: fullSnapshot,
|
|
958
1284
|
changed_files: changedFiles,
|
|
959
1285
|
deleted_files: deletedFiles,
|
|
960
1286
|
reindex,
|
|
@@ -1033,6 +1359,160 @@ asm project-event --project-id "$PROJECT_ID" --repo-root "$REPO_ROOT" --event-ty
|
|
|
1033
1359
|
task_context: payload.task_context,
|
|
1034
1360
|
});
|
|
1035
1361
|
}
|
|
1362
|
+
handleProjectChangeOverlayQuery(payload, req) {
|
|
1363
|
+
const identity = normalizePrivateIdentity(req.context);
|
|
1364
|
+
if (!payload.project_id) {
|
|
1365
|
+
throw new Error("project.change_overlay.query requires payload.project_id");
|
|
1366
|
+
}
|
|
1367
|
+
if (!payload.task_id && !payload.tracker_issue_key && !payload.task_title) {
|
|
1368
|
+
throw new Error("project.change_overlay.query requires one selector: task_id|tracker_issue_key|task_title");
|
|
1369
|
+
}
|
|
1370
|
+
const requestedFeature = payload.feature_key
|
|
1371
|
+
? payload.feature_key
|
|
1372
|
+
: (payload.feature_name ? this.resolveFeatureKeyInput(undefined, payload.feature_name) : undefined);
|
|
1373
|
+
const result = this.slotDb.queryProjectChangeOverlay(identity.userId, identity.agentId, {
|
|
1374
|
+
project_id: payload.project_id,
|
|
1375
|
+
task_id: payload.task_id,
|
|
1376
|
+
tracker_issue_key: payload.tracker_issue_key,
|
|
1377
|
+
task_title: payload.task_title,
|
|
1378
|
+
feature_key: requestedFeature,
|
|
1379
|
+
feature_name: payload.feature_name,
|
|
1380
|
+
include_related: payload.include_related,
|
|
1381
|
+
include_parent_chain: payload.include_parent_chain,
|
|
1382
|
+
});
|
|
1383
|
+
const baseEvidence = [
|
|
1384
|
+
{ type: "task", ref: result.focus.task_id, note: result.focus.task_title },
|
|
1385
|
+
...(result.focus.tracker_issue_key
|
|
1386
|
+
? [{ type: "tracker_issue", ref: result.focus.tracker_issue_key }]
|
|
1387
|
+
: []),
|
|
1388
|
+
...result.changed_files.map((file) => ({ type: "file", ref: file })),
|
|
1389
|
+
...result.related_symbols.slice(0, 20).map((symbol) => ({
|
|
1390
|
+
type: "symbol",
|
|
1391
|
+
ref: symbol.symbol_fqn || symbol.symbol_name,
|
|
1392
|
+
note: symbol.relative_path,
|
|
1393
|
+
})),
|
|
1394
|
+
...result.commit_refs.map((ref) => ({ type: "commit_ref", ref })),
|
|
1395
|
+
];
|
|
1396
|
+
const featurePackCandidates = requestedFeature
|
|
1397
|
+
? [requestedFeature]
|
|
1398
|
+
: [
|
|
1399
|
+
"project_onboarding_registration_indexing",
|
|
1400
|
+
"code_aware_retrieval",
|
|
1401
|
+
"heartbeat_health_runtime_integrity",
|
|
1402
|
+
"change_aware_impact",
|
|
1403
|
+
"post_entry_review_decision_support",
|
|
1404
|
+
];
|
|
1405
|
+
const featurePackMatches = [];
|
|
1406
|
+
for (const featureKey of featurePackCandidates) {
|
|
1407
|
+
let pack = null;
|
|
1408
|
+
try {
|
|
1409
|
+
pack = this.handleProjectFeaturePackGenerate({
|
|
1410
|
+
project_id: result.project_id,
|
|
1411
|
+
feature_key: featureKey,
|
|
1412
|
+
}, req);
|
|
1413
|
+
}
|
|
1414
|
+
catch {
|
|
1415
|
+
// Optional mapping: skip packs without enough evidence/context for this project.
|
|
1416
|
+
continue;
|
|
1417
|
+
}
|
|
1418
|
+
const packEvidenceSet = new Set((pack.evidence || []).map((item) => `${item.type}:${String(item.ref || "").toLowerCase()}`));
|
|
1419
|
+
const matchedEvidence = baseEvidence.filter((item) => packEvidenceSet.has(`${item.type}:${String(item.ref || "").toLowerCase()}`));
|
|
1420
|
+
if (matchedEvidence.length === 0) {
|
|
1421
|
+
continue;
|
|
1422
|
+
}
|
|
1423
|
+
const trackerHit = Boolean(result.focus.tracker_issue_key) &&
|
|
1424
|
+
pack.evidence.some((item) => item.type === "task" && String(item.ref || "") === String(result.focus.tracker_issue_key || ""));
|
|
1425
|
+
const taskHit = pack.evidence.some((item) => item.type === "task" && String(item.ref || "") === String(result.focus.task_id));
|
|
1426
|
+
const commitHitCount = result.commit_refs.filter((ref) => pack.related_commits.some((hint) => hint.toLowerCase().includes(String(ref || "").toLowerCase()))).length;
|
|
1427
|
+
const overlapRatio = matchedEvidence.length / Math.max(baseEvidence.length, 1);
|
|
1428
|
+
const confidenceRaw = Math.min(1, overlapRatio * 0.75) +
|
|
1429
|
+
(trackerHit ? 0.12 : 0) +
|
|
1430
|
+
(taskHit ? 0.08 : 0) +
|
|
1431
|
+
Math.min(0.1, commitHitCount * 0.05);
|
|
1432
|
+
const confidence = Number(Math.min(1, confidenceRaw).toFixed(2));
|
|
1433
|
+
if (confidence < 0.25) {
|
|
1434
|
+
continue;
|
|
1435
|
+
}
|
|
1436
|
+
featurePackMatches.push({
|
|
1437
|
+
feature_key: featureKey,
|
|
1438
|
+
title: pack.title,
|
|
1439
|
+
confidence,
|
|
1440
|
+
matched_evidence: matchedEvidence.slice(0, 10),
|
|
1441
|
+
note: `matched ${matchedEvidence.length} evidence items`,
|
|
1442
|
+
});
|
|
1443
|
+
}
|
|
1444
|
+
featurePackMatches.sort((a, b) => b.confidence - a.confidence);
|
|
1445
|
+
const symbolsByPath = new Map();
|
|
1446
|
+
for (const path of result.changed_files) {
|
|
1447
|
+
symbolsByPath.set(path, 0);
|
|
1448
|
+
}
|
|
1449
|
+
for (const symbol of result.related_symbols) {
|
|
1450
|
+
if (symbol.relative_path && symbolsByPath.has(symbol.relative_path)) {
|
|
1451
|
+
symbolsByPath.set(symbol.relative_path, Number(symbolsByPath.get(symbol.relative_path) || 0) + 1);
|
|
1452
|
+
}
|
|
1453
|
+
}
|
|
1454
|
+
const enrichedSymbols = result.related_symbols
|
|
1455
|
+
.map((symbol) => {
|
|
1456
|
+
const hasPath = Boolean(symbol.relative_path && result.changed_files.includes(symbol.relative_path));
|
|
1457
|
+
const pathDensity = hasPath
|
|
1458
|
+
? Math.min(1, Number(symbolsByPath.get(symbol.relative_path || "") || 0) / 4)
|
|
1459
|
+
: 0;
|
|
1460
|
+
const name = String(symbol.symbol_name || "");
|
|
1461
|
+
const nameLower = name.toLowerCase();
|
|
1462
|
+
const symbolFromTask = result.focus.task_title
|
|
1463
|
+
.toLowerCase()
|
|
1464
|
+
.split(/[^a-z0-9_]+/)
|
|
1465
|
+
.filter((token) => token.length >= 3)
|
|
1466
|
+
.some((token) => nameLower.includes(token));
|
|
1467
|
+
const confidence = Number(Math.min(1, (symbol.source === "task_registry" ? 0.45 : 0.35) +
|
|
1468
|
+
(hasPath ? 0.25 : 0) +
|
|
1469
|
+
pathDensity * 0.2 +
|
|
1470
|
+
(symbolFromTask ? 0.1 : 0)).toFixed(2));
|
|
1471
|
+
return {
|
|
1472
|
+
...symbol,
|
|
1473
|
+
confidence,
|
|
1474
|
+
evidence_refs: [
|
|
1475
|
+
...(symbol.relative_path ? [`file:${symbol.relative_path}`] : []),
|
|
1476
|
+
...(symbol.symbol_fqn ? [`symbol:${symbol.symbol_fqn}`] : [`symbol:${symbol.symbol_name}`]),
|
|
1477
|
+
],
|
|
1478
|
+
};
|
|
1479
|
+
})
|
|
1480
|
+
.sort((a, b) => {
|
|
1481
|
+
const confidenceDiff = Number((b.confidence || 0) - (a.confidence || 0));
|
|
1482
|
+
if (confidenceDiff !== 0)
|
|
1483
|
+
return confidenceDiff;
|
|
1484
|
+
return String(a.symbol_name).localeCompare(String(b.symbol_name));
|
|
1485
|
+
});
|
|
1486
|
+
const confidence = {
|
|
1487
|
+
overall: Number(Math.min(1, (result.changed_files.length > 0 ? 0.3 : 0) +
|
|
1488
|
+
Math.min(0.25, result.related_symbols.length * 0.03) +
|
|
1489
|
+
Math.min(0.15, result.commit_refs.length * 0.05) +
|
|
1490
|
+
Math.min(0.3, featurePackMatches.length * 0.1)).toFixed(2)),
|
|
1491
|
+
signals: {
|
|
1492
|
+
changed_files: result.changed_files.length,
|
|
1493
|
+
related_symbols: result.related_symbols.length,
|
|
1494
|
+
commit_refs: result.commit_refs.length,
|
|
1495
|
+
feature_pack_matches: featurePackMatches.length,
|
|
1496
|
+
},
|
|
1497
|
+
};
|
|
1498
|
+
return {
|
|
1499
|
+
overlay_id: `change-overlay:${result.project_id}:${result.focus.task_id}${requestedFeature ? `:${requestedFeature}` : ""}`,
|
|
1500
|
+
status: result.status,
|
|
1501
|
+
...(result.reason ? { reason: result.reason } : {}),
|
|
1502
|
+
selector: result.selector,
|
|
1503
|
+
recoverable: result.recoverable,
|
|
1504
|
+
project_id: result.project_id,
|
|
1505
|
+
focus: result.focus,
|
|
1506
|
+
changed_files: result.changed_files,
|
|
1507
|
+
related_symbols: enrichedSymbols,
|
|
1508
|
+
commit_refs: result.commit_refs,
|
|
1509
|
+
feature_packs: featurePackMatches,
|
|
1510
|
+
evidence: baseEvidence,
|
|
1511
|
+
confidence,
|
|
1512
|
+
generated_at: new Date().toISOString(),
|
|
1513
|
+
generator_version: "asm-94-slice3",
|
|
1514
|
+
};
|
|
1515
|
+
}
|
|
1036
1516
|
handleProjectLegacyBackfill(payload, req) {
|
|
1037
1517
|
const identity = normalizePrivateIdentity(req.context);
|
|
1038
1518
|
return this.slotDb.runLegacyCompatibilityBackfill(identity.userId, identity.agentId, {
|
|
@@ -1154,6 +1634,1032 @@ asm project-event --project-id "$PROJECT_ID" --repo-root "$REPO_ROOT" --event-ty
|
|
|
1154
1634
|
used_commands: ["project.register_command", "project.link_tracker", "project.trigger_index"],
|
|
1155
1635
|
};
|
|
1156
1636
|
}
|
|
1637
|
+
handleProjectFeaturePackGenerate(payload, req) {
|
|
1638
|
+
const identity = normalizePrivateIdentity(req.context);
|
|
1639
|
+
const featureKey = payload.feature_key || "project_onboarding_registration_indexing";
|
|
1640
|
+
const project = this.resolveProjectRef(identity.userId, identity.agentId, {
|
|
1641
|
+
project_id: payload.project_id,
|
|
1642
|
+
project_alias: payload.project_alias,
|
|
1643
|
+
});
|
|
1644
|
+
const snapshot = this.slotDb.getProjectFeaturePackProjectOnboardingIndexingSnapshot(identity.userId, identity.agentId, project.project_id);
|
|
1645
|
+
const primaryAlias = snapshot.aliases.find((item) => item.is_primary === 1)?.project_alias || payload.project_alias || project.project_name;
|
|
1646
|
+
switch (featureKey) {
|
|
1647
|
+
case "project_onboarding_registration_indexing":
|
|
1648
|
+
return this.buildProjectOnboardingRegistrationIndexingPack(snapshot, project.project_id, primaryAlias);
|
|
1649
|
+
case "code_aware_retrieval":
|
|
1650
|
+
return this.buildCodeAwareRetrievalPack(snapshot, project.project_id, primaryAlias);
|
|
1651
|
+
case "heartbeat_health_runtime_integrity":
|
|
1652
|
+
return this.buildHeartbeatHealthRuntimeIntegrityPack(snapshot, project.project_id, primaryAlias);
|
|
1653
|
+
case "change_aware_impact":
|
|
1654
|
+
return this.buildChangeAwareImpactPack(snapshot, project.project_id, primaryAlias);
|
|
1655
|
+
case "post_entry_review_decision_support":
|
|
1656
|
+
return this.buildPostEntryReviewDecisionSupportPack(snapshot, project.project_id, primaryAlias);
|
|
1657
|
+
default:
|
|
1658
|
+
throw new Error(`Unsupported feature_key: ${featureKey}`);
|
|
1659
|
+
}
|
|
1660
|
+
}
|
|
1661
|
+
handleProjectFeaturePackQuery(payload, req) {
|
|
1662
|
+
const identity = normalizePrivateIdentity(req.context);
|
|
1663
|
+
const project = this.resolveProjectRef(identity.userId, identity.agentId, {
|
|
1664
|
+
project_id: payload.project_id,
|
|
1665
|
+
project_alias: payload.project_alias,
|
|
1666
|
+
});
|
|
1667
|
+
const requestedFeature = this.resolveFeatureKeyInput(payload.feature_key, payload.feature_name);
|
|
1668
|
+
const pack = this.handleProjectFeaturePackGenerate({
|
|
1669
|
+
project_id: project.project_id,
|
|
1670
|
+
project_alias: payload.project_alias,
|
|
1671
|
+
feature_key: requestedFeature,
|
|
1672
|
+
}, req);
|
|
1673
|
+
return {
|
|
1674
|
+
project_id: project.project_id,
|
|
1675
|
+
project_alias: payload.project_alias || null,
|
|
1676
|
+
feature_key: requestedFeature,
|
|
1677
|
+
pack,
|
|
1678
|
+
};
|
|
1679
|
+
}
|
|
1680
|
+
handleProjectDeveloperQuery(payload, req) {
|
|
1681
|
+
const identity = normalizePrivateIdentity(req.context);
|
|
1682
|
+
const parsed = this.parseProjectDeveloperQueryPayload(payload);
|
|
1683
|
+
const query = parsed.query_text;
|
|
1684
|
+
const project = this.resolveProjectRef(identity.userId, identity.agentId, {
|
|
1685
|
+
project_id: payload.project_id,
|
|
1686
|
+
project_alias: payload.project_alias,
|
|
1687
|
+
});
|
|
1688
|
+
const inferredIntent = parsed.legacy_intent;
|
|
1689
|
+
const retrievalPlan = this.buildDeveloperRetrievalPlan(parsed.canonical_intent, payload.limit, parsed);
|
|
1690
|
+
const queryFingerprint = createHash("sha1")
|
|
1691
|
+
.update(`${project.project_id}|${parsed.canonical_intent}|${query.toLowerCase()}`)
|
|
1692
|
+
.digest("hex")
|
|
1693
|
+
.slice(0, 16);
|
|
1694
|
+
const queryId = `pdevq:${queryFingerprint}`;
|
|
1695
|
+
const trackerIssueHint = parsed.tracker_issue_key || parsed.tracker_issue_keys?.[0] || query.match(/\b[A-Z][A-Z0-9_]+-\d+\b/)?.[0];
|
|
1696
|
+
const hybridTaskContext = retrievalPlan.use_task_context
|
|
1697
|
+
? {
|
|
1698
|
+
tracker_issue_key: trackerIssueHint,
|
|
1699
|
+
task_id: parsed.task_id,
|
|
1700
|
+
task_title: parsed.task_title,
|
|
1701
|
+
include_related: true,
|
|
1702
|
+
include_parent_chain: inferredIntent === "trace_flow",
|
|
1703
|
+
}
|
|
1704
|
+
: undefined;
|
|
1705
|
+
let locate = this.handleProjectHybridSearch({
|
|
1706
|
+
project_id: project.project_id,
|
|
1707
|
+
query,
|
|
1708
|
+
limit: retrievalPlan.locate_limit,
|
|
1709
|
+
debug: false,
|
|
1710
|
+
...(hybridTaskContext ? { task_context: hybridTaskContext } : {}),
|
|
1711
|
+
...(retrievalPlan.path_prefix_hint && retrievalPlan.path_prefix_hint.length > 0
|
|
1712
|
+
? { path_prefix: retrievalPlan.path_prefix_hint }
|
|
1713
|
+
: {}),
|
|
1714
|
+
}, req);
|
|
1715
|
+
let locateFallbackUsed = false;
|
|
1716
|
+
if (locate.results.length === 0 && hybridTaskContext) {
|
|
1717
|
+
locate = this.handleProjectHybridSearch({
|
|
1718
|
+
project_id: project.project_id,
|
|
1719
|
+
query,
|
|
1720
|
+
limit: retrievalPlan.locate_limit,
|
|
1721
|
+
debug: false,
|
|
1722
|
+
...(retrievalPlan.path_prefix_hint && retrievalPlan.path_prefix_hint.length > 0
|
|
1723
|
+
? { path_prefix: retrievalPlan.path_prefix_hint }
|
|
1724
|
+
: {}),
|
|
1725
|
+
}, req);
|
|
1726
|
+
locateFallbackUsed = true;
|
|
1727
|
+
}
|
|
1728
|
+
const topN = {
|
|
1729
|
+
primary_results: 12,
|
|
1730
|
+
files: 12,
|
|
1731
|
+
symbols: 16,
|
|
1732
|
+
snippets: 10,
|
|
1733
|
+
graph_paths: 8,
|
|
1734
|
+
change_context: 8,
|
|
1735
|
+
answer_points: 5,
|
|
1736
|
+
};
|
|
1737
|
+
const sourceRank = retrievalPlan.source_priority.reduce((acc, source, index) => {
|
|
1738
|
+
acc[source] = index;
|
|
1739
|
+
return acc;
|
|
1740
|
+
}, {
|
|
1741
|
+
symbol_registry: 99,
|
|
1742
|
+
file_index_state: 99,
|
|
1743
|
+
chunk_registry: 99,
|
|
1744
|
+
task_registry: 99,
|
|
1745
|
+
});
|
|
1746
|
+
const sourceBoostByPriority = retrievalPlan.source_priority.reduce((acc, source, index) => {
|
|
1747
|
+
acc[source] = Math.max(0, 0.15 - index * 0.04);
|
|
1748
|
+
return acc;
|
|
1749
|
+
}, {
|
|
1750
|
+
symbol_registry: 0,
|
|
1751
|
+
file_index_state: 0,
|
|
1752
|
+
chunk_registry: 0,
|
|
1753
|
+
task_registry: 0,
|
|
1754
|
+
});
|
|
1755
|
+
const sortStringsStable = (values) => values.sort((a, b) => a.localeCompare(b));
|
|
1756
|
+
const locateScored = locate.results.map((item) => {
|
|
1757
|
+
const source = item.source;
|
|
1758
|
+
const adjustedScore = Number((Number(item.score || 0) + (sourceBoostByPriority[source] || 0)).toFixed(4));
|
|
1759
|
+
return {
|
|
1760
|
+
...item,
|
|
1761
|
+
adjusted_score: adjustedScore,
|
|
1762
|
+
};
|
|
1763
|
+
});
|
|
1764
|
+
const locateSorted = [...locateScored].sort((a, b) => Number(b.adjusted_score || 0) - Number(a.adjusted_score || 0)
|
|
1765
|
+
|| (sourceRank[a.source] ?? 99) - (sourceRank[b.source] ?? 99)
|
|
1766
|
+
|| String(a.relative_path || "").localeCompare(String(b.relative_path || ""))
|
|
1767
|
+
|| String(a.symbol_name || "").localeCompare(String(b.symbol_name || ""))
|
|
1768
|
+
|| String(a.task_id || a.id).localeCompare(String(b.task_id || b.id)));
|
|
1769
|
+
const locatePrimary = locateSorted.map((item) => ({
|
|
1770
|
+
type: item.source === "file_index_state"
|
|
1771
|
+
? "file"
|
|
1772
|
+
: item.source === "symbol_registry"
|
|
1773
|
+
? "symbol"
|
|
1774
|
+
: item.source === "chunk_registry"
|
|
1775
|
+
? "chunk"
|
|
1776
|
+
: "task",
|
|
1777
|
+
id: item.id,
|
|
1778
|
+
title: item.symbol_name
|
|
1779
|
+
? `${item.symbol_name}${item.relative_path ? ` (${item.relative_path})` : ""}`
|
|
1780
|
+
: item.relative_path || item.task_title || item.id,
|
|
1781
|
+
score: item.adjusted_score,
|
|
1782
|
+
relative_path: item.relative_path,
|
|
1783
|
+
symbol_name: item.symbol_name,
|
|
1784
|
+
snippet: item.snippet,
|
|
1785
|
+
}));
|
|
1786
|
+
const requestedFeature = this.pickFeatureKeyForIntent(inferredIntent, parsed.feature_key || payload.feature_key, payload.feature_name, query);
|
|
1787
|
+
const shouldAttachFeaturePack = retrievalPlan.attach_feature_pack
|
|
1788
|
+
|| Boolean(parsed.feature_key || payload.feature_key || payload.feature_name);
|
|
1789
|
+
let featurePacks = [];
|
|
1790
|
+
if (shouldAttachFeaturePack && requestedFeature) {
|
|
1791
|
+
try {
|
|
1792
|
+
const featureQuery = this.handleProjectFeaturePackQuery({
|
|
1793
|
+
project_id: project.project_id,
|
|
1794
|
+
feature_key: requestedFeature,
|
|
1795
|
+
}, req);
|
|
1796
|
+
featurePacks = [featureQuery.pack];
|
|
1797
|
+
}
|
|
1798
|
+
catch {
|
|
1799
|
+
featurePacks = [];
|
|
1800
|
+
}
|
|
1801
|
+
}
|
|
1802
|
+
const overlaySelector = this.pickOverlaySelectorFromLocate(locate.results, parsed);
|
|
1803
|
+
let overlay = null;
|
|
1804
|
+
if (retrievalPlan.attach_overlay && (overlaySelector.task_id || overlaySelector.tracker_issue_key)) {
|
|
1805
|
+
try {
|
|
1806
|
+
overlay = this.handleProjectChangeOverlayQuery({
|
|
1807
|
+
project_id: project.project_id,
|
|
1808
|
+
task_id: overlaySelector.task_id,
|
|
1809
|
+
tracker_issue_key: overlaySelector.tracker_issue_key,
|
|
1810
|
+
feature_key: requestedFeature || undefined,
|
|
1811
|
+
include_related: true,
|
|
1812
|
+
include_parent_chain: true,
|
|
1813
|
+
}, req);
|
|
1814
|
+
}
|
|
1815
|
+
catch {
|
|
1816
|
+
overlay = null;
|
|
1817
|
+
}
|
|
1818
|
+
}
|
|
1819
|
+
const featurePrimary = featurePacks
|
|
1820
|
+
.map((pack) => ({
|
|
1821
|
+
type: "feature_pack",
|
|
1822
|
+
id: pack.pack_id,
|
|
1823
|
+
title: pack.title,
|
|
1824
|
+
score: 1,
|
|
1825
|
+
snippet: pack.summary,
|
|
1826
|
+
}))
|
|
1827
|
+
.sort((a, b) => String(a.id).localeCompare(String(b.id)));
|
|
1828
|
+
const overlaySymbolPrimary = parsed.canonical_intent === "change_lookup"
|
|
1829
|
+
? [...(overlay?.related_symbols || [])]
|
|
1830
|
+
.sort((a, b) => Number(b.confidence || 0) - Number(a.confidence || 0)
|
|
1831
|
+
|| String(a.relative_path || "").localeCompare(String(b.relative_path || ""))
|
|
1832
|
+
|| String(a.symbol_name || "").localeCompare(String(b.symbol_name || "")))
|
|
1833
|
+
.slice(0, 3)
|
|
1834
|
+
.map((symbol) => ({
|
|
1835
|
+
type: "symbol",
|
|
1836
|
+
id: symbol.symbol_fqn || symbol.symbol_name,
|
|
1837
|
+
title: `${symbol.symbol_name}${symbol.relative_path ? ` (${symbol.relative_path})` : ""}`,
|
|
1838
|
+
score: symbol.confidence,
|
|
1839
|
+
relative_path: symbol.relative_path,
|
|
1840
|
+
symbol_name: symbol.symbol_name,
|
|
1841
|
+
}))
|
|
1842
|
+
: [];
|
|
1843
|
+
const mergedPrimaryCandidates = [
|
|
1844
|
+
...(retrievalPlan.prefer_feature_primary ? featurePrimary : []),
|
|
1845
|
+
...overlaySymbolPrimary,
|
|
1846
|
+
...locatePrimary,
|
|
1847
|
+
...(!retrievalPlan.prefer_feature_primary ? featurePrimary : []),
|
|
1848
|
+
];
|
|
1849
|
+
const mergedPrimaryDeduped = Array.from(new Map(mergedPrimaryCandidates.map((item) => {
|
|
1850
|
+
const key = `${item.type}:${item.id}`;
|
|
1851
|
+
return [key, item];
|
|
1852
|
+
})).values());
|
|
1853
|
+
const mergedPrimary = mergedPrimaryDeduped
|
|
1854
|
+
.sort((a, b) => Number(b.score || 0) - Number(a.score || 0)
|
|
1855
|
+
|| String(a.type).localeCompare(String(b.type))
|
|
1856
|
+
|| String(a.relative_path || "").localeCompare(String(b.relative_path || ""))
|
|
1857
|
+
|| String(a.title).localeCompare(String(b.title)))
|
|
1858
|
+
.slice(0, topN.primary_results);
|
|
1859
|
+
const files = sortStringsStable(Array.from(new Set([
|
|
1860
|
+
...locateSorted.map((item) => item.relative_path).filter(Boolean),
|
|
1861
|
+
...(overlay?.changed_files || []),
|
|
1862
|
+
...featurePacks.flatMap((pack) => pack.primary_files || []),
|
|
1863
|
+
]))).slice(0, topN.files);
|
|
1864
|
+
const symbols = sortStringsStable(Array.from(new Set([
|
|
1865
|
+
...locateSorted.map((item) => item.symbol_name).filter(Boolean),
|
|
1866
|
+
...(overlay?.related_symbols || []).map((item) => item.symbol_fqn || item.symbol_name).filter(Boolean),
|
|
1867
|
+
...featurePacks.flatMap((pack) => pack.primary_symbols || []),
|
|
1868
|
+
]))).slice(0, topN.symbols);
|
|
1869
|
+
const snippets = sortStringsStable(Array.from(new Set([
|
|
1870
|
+
...locateSorted.map((item) => String(item.snippet || "").trim()).filter(Boolean),
|
|
1871
|
+
...featurePacks.map((pack) => pack.summary).filter(Boolean),
|
|
1872
|
+
...(overlay
|
|
1873
|
+
? [
|
|
1874
|
+
`overlay focus ${overlay.focus.task_id}${overlay.focus.tracker_issue_key ? ` (${overlay.focus.tracker_issue_key})` : ""}`,
|
|
1875
|
+
...overlay.feature_packs.slice(0, 2).map((pack) => `${pack.feature_key}: ${pack.note || "overlay match"}`),
|
|
1876
|
+
]
|
|
1877
|
+
: []),
|
|
1878
|
+
]))).slice(0, topN.snippets);
|
|
1879
|
+
const graphPaths = sortStringsStable(overlay
|
|
1880
|
+
? Array.from(new Set(overlay.related_symbols
|
|
1881
|
+
.map((item) => `${item.relative_path || "unknown"}::${item.symbol_fqn || item.symbol_name}`)))
|
|
1882
|
+
: []).slice(0, topN.graph_paths);
|
|
1883
|
+
const changeContext = sortStringsStable(Array.from(new Set([
|
|
1884
|
+
...locateSorted
|
|
1885
|
+
.map((item) => item.task_id || item.tracker_issue_key)
|
|
1886
|
+
.filter((value) => Boolean(value)),
|
|
1887
|
+
...(overlay ? [overlay.focus.task_id, ...(overlay.focus.tracker_issue_key ? [overlay.focus.tracker_issue_key] : [])] : []),
|
|
1888
|
+
...featurePacks.flatMap((pack) => pack.related_tasks || []),
|
|
1889
|
+
]))).slice(0, topN.change_context);
|
|
1890
|
+
const assemblySources = Array.from(new Set([
|
|
1891
|
+
...(files.length > 0 ? ["file"] : []),
|
|
1892
|
+
...(symbols.length > 0 ? ["symbol"] : []),
|
|
1893
|
+
...(featurePacks.length > 0 ? ["feature_pack"] : []),
|
|
1894
|
+
...(overlay ? ["change_overlay"] : []),
|
|
1895
|
+
])).sort((a, b) => a.localeCompare(b));
|
|
1896
|
+
const confidenceOverall = Number(Math.min(0.97, (locate.results.length > 0 ? 0.45 : 0.1)
|
|
1897
|
+
+ (featurePacks.length > 0 ? 0.2 : 0)
|
|
1898
|
+
+ (overlay ? 0.2 : 0)
|
|
1899
|
+
+ (parsed.canonical_intent === "change_lookup" && overlay ? 0.07 : 0)
|
|
1900
|
+
+ (inferredIntent === "trace_flow" && !locateFallbackUsed ? 0.03 : 0)
|
|
1901
|
+
+ Math.min(0.07, snippets.length * 0.01)).toFixed(2));
|
|
1902
|
+
const confidenceReasonParts = [];
|
|
1903
|
+
confidenceReasonParts.push(`intent=${inferredIntent}`);
|
|
1904
|
+
confidenceReasonParts.push(`locate_hits=${locate.results.length}`);
|
|
1905
|
+
confidenceReasonParts.push(`plan=${retrievalPlan.plan_key}`);
|
|
1906
|
+
if (featurePacks.length > 0)
|
|
1907
|
+
confidenceReasonParts.push(`feature_pack=${featurePacks[0].feature_key}`);
|
|
1908
|
+
if (overlay)
|
|
1909
|
+
confidenceReasonParts.push(`overlay_focus=${overlay.focus.task_id}`);
|
|
1910
|
+
if (locateFallbackUsed)
|
|
1911
|
+
confidenceReasonParts.push("trace_task_context_fallback=true");
|
|
1912
|
+
const whyThisResult = [
|
|
1913
|
+
"resolved via project.hybrid_search",
|
|
1914
|
+
`retrieval plan ${retrievalPlan.plan_key} source priority: ${retrievalPlan.source_priority.join(" > ")}`,
|
|
1915
|
+
...(hybridTaskContext ? ["intent-aware task_context applied"] : []),
|
|
1916
|
+
...(retrievalPlan.path_prefix_hint && retrievalPlan.path_prefix_hint.length > 0
|
|
1917
|
+
? [`path_prefix hint: ${retrievalPlan.path_prefix_hint.join(", ")}`]
|
|
1918
|
+
: []),
|
|
1919
|
+
...(featurePacks.length > 0 ? ["enriched via project.feature_pack.query"] : []),
|
|
1920
|
+
...(overlay ? ["enriched via project.change_overlay.query"] : []),
|
|
1921
|
+
`result_count=${locate.count}`,
|
|
1922
|
+
"stable ordering: score desc -> source/path/title",
|
|
1923
|
+
"dedup key: primary(type:id), lists via set",
|
|
1924
|
+
];
|
|
1925
|
+
const answerTemplate = parsed.canonical_intent === "locate_symbol" || parsed.canonical_intent === "locate_file"
|
|
1926
|
+
? "locate"
|
|
1927
|
+
: parsed.canonical_intent === "feature_lookup"
|
|
1928
|
+
? "feature_understanding"
|
|
1929
|
+
: "generic";
|
|
1930
|
+
const answerSummary = answerTemplate === "locate"
|
|
1931
|
+
? `Located ${mergedPrimary.length} candidate result(s) for '${query}' in project ${project.project_id}.`
|
|
1932
|
+
: answerTemplate === "feature_understanding"
|
|
1933
|
+
? `Feature understanding assembled for '${query}' with ${featurePacks.length} feature pack(s).`
|
|
1934
|
+
: `Developer query '${query}' resolved with ${assemblySources.length} assembly source(s).`;
|
|
1935
|
+
const answerPoints = (answerTemplate === "locate"
|
|
1936
|
+
? [
|
|
1937
|
+
mergedPrimary[0] ? `Top hit: ${mergedPrimary[0].title}` : "Top hit: none",
|
|
1938
|
+
files.length > 0 ? `Files: ${files.slice(0, 3).join(", ")}` : "Files: none",
|
|
1939
|
+
symbols.length > 0 ? `Symbols: ${symbols.slice(0, 3).join(", ")}` : "Symbols: none",
|
|
1940
|
+
`Assembly sources: ${assemblySources.join(", ") || "none"}`,
|
|
1941
|
+
]
|
|
1942
|
+
: answerTemplate === "feature_understanding"
|
|
1943
|
+
? [
|
|
1944
|
+
featurePacks[0] ? `Feature pack: ${featurePacks[0].title}` : "Feature pack: none",
|
|
1945
|
+
featurePacks[0]?.summary ? `Summary: ${featurePacks[0].summary}` : "Summary: none",
|
|
1946
|
+
featurePacks[0]?.primary_files?.length ? `Primary files: ${featurePacks[0].primary_files.slice(0, 3).join(", ")}` : "Primary files: none",
|
|
1947
|
+
featurePacks[0]?.primary_symbols?.length ? `Primary symbols: ${featurePacks[0].primary_symbols.slice(0, 3).join(", ")}` : "Primary symbols: none",
|
|
1948
|
+
]
|
|
1949
|
+
: [
|
|
1950
|
+
`Intent: ${inferredIntent}`,
|
|
1951
|
+
`Top result: ${mergedPrimary[0]?.title || "none"}`,
|
|
1952
|
+
`Assembly sources: ${assemblySources.join(", ") || "none"}`,
|
|
1953
|
+
])
|
|
1954
|
+
.slice(0, topN.answer_points);
|
|
1955
|
+
return {
|
|
1956
|
+
query_id: queryId,
|
|
1957
|
+
intent: inferredIntent,
|
|
1958
|
+
project_id: project.project_id,
|
|
1959
|
+
project_alias: payload.project_alias || null,
|
|
1960
|
+
query,
|
|
1961
|
+
primary_results: mergedPrimary,
|
|
1962
|
+
files,
|
|
1963
|
+
symbols,
|
|
1964
|
+
snippets,
|
|
1965
|
+
graph_paths: graphPaths,
|
|
1966
|
+
feature_packs: featurePacks,
|
|
1967
|
+
change_context: changeContext,
|
|
1968
|
+
assembly_sources: assemblySources,
|
|
1969
|
+
answer_template: answerTemplate,
|
|
1970
|
+
answer_summary: answerSummary,
|
|
1971
|
+
answer_points: answerPoints,
|
|
1972
|
+
explainability: {
|
|
1973
|
+
ranking_rules: [
|
|
1974
|
+
"typed query parser maps query -> canonical intent/selectors deterministically",
|
|
1975
|
+
`retrieval plan ${retrievalPlan.plan_key} applies source priority ${retrievalPlan.source_priority.join(" > ")}`,
|
|
1976
|
+
"primary_results sorted by score desc, then type/path/title",
|
|
1977
|
+
"files/symbols/snippets/graph_paths/change_context sorted lexicographically",
|
|
1978
|
+
"hybrid locate candidates pre-sorted by score/source/path/symbol/task",
|
|
1979
|
+
],
|
|
1980
|
+
top_n: topN,
|
|
1981
|
+
evidence_counts: {
|
|
1982
|
+
locate_hits: locate.results.length,
|
|
1983
|
+
feature_pack_hits: featurePacks.length,
|
|
1984
|
+
overlay_changed_files: overlay?.changed_files.length || 0,
|
|
1985
|
+
overlay_related_symbols: overlay?.related_symbols.length || 0,
|
|
1986
|
+
},
|
|
1987
|
+
dedup: {
|
|
1988
|
+
primary_results: true,
|
|
1989
|
+
files: true,
|
|
1990
|
+
symbols: true,
|
|
1991
|
+
snippets: true,
|
|
1992
|
+
graph_paths: true,
|
|
1993
|
+
change_context: true,
|
|
1994
|
+
},
|
|
1995
|
+
fallbacks: [
|
|
1996
|
+
...(locateFallbackUsed ? ["trace_task_context_fallback=true"] : []),
|
|
1997
|
+
...(featurePacks.length === 0 && shouldAttachFeaturePack ? ["feature_pack_unavailable_or_unresolved"] : []),
|
|
1998
|
+
...(overlay === null && retrievalPlan.attach_overlay ? ["overlay_unavailable_or_unresolved"] : []),
|
|
1999
|
+
],
|
|
2000
|
+
},
|
|
2001
|
+
confidence: {
|
|
2002
|
+
overall: confidenceOverall,
|
|
2003
|
+
reason: confidenceReasonParts.join("; ") || "minimal evidence",
|
|
2004
|
+
},
|
|
2005
|
+
why_this_result: whyThisResult,
|
|
2006
|
+
generated_at: new Date().toISOString(),
|
|
2007
|
+
generator_version: "asm-109-slice8",
|
|
2008
|
+
};
|
|
2009
|
+
}
|
|
2010
|
+
buildDeveloperRetrievalPlan(intent, requestedLimit, parsed) {
|
|
2011
|
+
const locateLimit = Math.min(Math.max(Number(requestedLimit || 8), 1), 20);
|
|
2012
|
+
if (intent === "locate_symbol") {
|
|
2013
|
+
return {
|
|
2014
|
+
plan_key: "locate_symbol",
|
|
2015
|
+
source_priority: ["symbol_registry", "chunk_registry", "file_index_state", "task_registry"],
|
|
2016
|
+
locate_limit: locateLimit,
|
|
2017
|
+
use_task_context: false,
|
|
2018
|
+
attach_feature_pack: false,
|
|
2019
|
+
attach_overlay: false,
|
|
2020
|
+
prefer_feature_primary: false,
|
|
2021
|
+
};
|
|
2022
|
+
}
|
|
2023
|
+
if (intent === "locate_file") {
|
|
2024
|
+
return {
|
|
2025
|
+
plan_key: "locate_file",
|
|
2026
|
+
source_priority: ["file_index_state", "chunk_registry", "symbol_registry", "task_registry"],
|
|
2027
|
+
locate_limit: locateLimit,
|
|
2028
|
+
use_task_context: false,
|
|
2029
|
+
attach_feature_pack: false,
|
|
2030
|
+
attach_overlay: false,
|
|
2031
|
+
prefer_feature_primary: false,
|
|
2032
|
+
path_prefix_hint: this.buildLocatePathPrefixHint(parsed.relative_path || parsed.query_text),
|
|
2033
|
+
};
|
|
2034
|
+
}
|
|
2035
|
+
if (intent === "feature_lookup") {
|
|
2036
|
+
return {
|
|
2037
|
+
plan_key: "feature_lookup",
|
|
2038
|
+
source_priority: ["symbol_registry", "file_index_state", "task_registry", "chunk_registry"],
|
|
2039
|
+
locate_limit: Math.min(locateLimit, 12),
|
|
2040
|
+
use_task_context: false,
|
|
2041
|
+
attach_feature_pack: true,
|
|
2042
|
+
attach_overlay: false,
|
|
2043
|
+
prefer_feature_primary: true,
|
|
2044
|
+
};
|
|
2045
|
+
}
|
|
2046
|
+
return {
|
|
2047
|
+
plan_key: "change_lookup",
|
|
2048
|
+
source_priority: ["task_registry", "symbol_registry", "file_index_state", "chunk_registry"],
|
|
2049
|
+
locate_limit: locateLimit,
|
|
2050
|
+
use_task_context: true,
|
|
2051
|
+
attach_feature_pack: true,
|
|
2052
|
+
attach_overlay: true,
|
|
2053
|
+
prefer_feature_primary: false,
|
|
2054
|
+
};
|
|
2055
|
+
}
|
|
2056
|
+
buildLocatePathPrefixHint(rawPath) {
|
|
2057
|
+
const normalized = String(rawPath || "").trim().replace(/\\/g, "/").replace(/^\.\//, "");
|
|
2058
|
+
if (!normalized || !normalized.includes("/"))
|
|
2059
|
+
return undefined;
|
|
2060
|
+
const segments = normalized.split("/").filter(Boolean);
|
|
2061
|
+
if (segments.length === 0)
|
|
2062
|
+
return undefined;
|
|
2063
|
+
const hints = [normalized];
|
|
2064
|
+
if (segments.length > 1) {
|
|
2065
|
+
hints.push(segments.slice(0, -1).join("/"));
|
|
2066
|
+
}
|
|
2067
|
+
hints.push(segments[0]);
|
|
2068
|
+
return Array.from(new Set(hints)).filter(Boolean);
|
|
2069
|
+
}
|
|
2070
|
+
parseProjectDeveloperQueryPayload(payload) {
|
|
2071
|
+
const explicitIntent = payload.intent;
|
|
2072
|
+
const query = String(payload.query || "").trim();
|
|
2073
|
+
const symbolName = String(payload.symbol_name || "").trim();
|
|
2074
|
+
const relativePath = String(payload.relative_path || "").trim();
|
|
2075
|
+
const routePath = String(payload.route_path || "").trim();
|
|
2076
|
+
const trackerIssueKey = String(payload.tracker_issue_key || "").trim();
|
|
2077
|
+
const taskId = String(payload.task_id || "").trim();
|
|
2078
|
+
const taskTitle = String(payload.task_title || "").trim();
|
|
2079
|
+
const trackerIssueKeys = this.extractTrackerIssueKeys(query);
|
|
2080
|
+
const taskIds = this.extractTaskIds(query);
|
|
2081
|
+
const routePaths = this.extractRoutePaths(query);
|
|
2082
|
+
const inferredFeatureKey = this.extractFeatureKeyFromQuery(query);
|
|
2083
|
+
const canonicalFromExplicit = {
|
|
2084
|
+
locate_symbol: "locate_symbol",
|
|
2085
|
+
locate_file: "locate_file",
|
|
2086
|
+
feature_lookup: "feature_lookup",
|
|
2087
|
+
change_lookup: "change_lookup",
|
|
2088
|
+
locate: "locate_symbol",
|
|
2089
|
+
trace_flow: "change_lookup",
|
|
2090
|
+
impact: "change_lookup",
|
|
2091
|
+
impact_analysis: "change_lookup",
|
|
2092
|
+
change_aware_lookup: "change_lookup",
|
|
2093
|
+
feature_understanding: "feature_lookup",
|
|
2094
|
+
};
|
|
2095
|
+
const canonical_intent = explicitIntent
|
|
2096
|
+
? canonicalFromExplicit[explicitIntent]
|
|
2097
|
+
: this.inferCanonicalIntentFromQuery({
|
|
2098
|
+
query,
|
|
2099
|
+
symbolName,
|
|
2100
|
+
relativePath,
|
|
2101
|
+
routePath: routePath || routePaths[0],
|
|
2102
|
+
trackerIssueKey: trackerIssueKey || trackerIssueKeys[0],
|
|
2103
|
+
taskId: taskId || taskIds[0],
|
|
2104
|
+
taskTitle,
|
|
2105
|
+
hasFeatureSelector: Boolean(payload.feature_key || payload.feature_name),
|
|
2106
|
+
});
|
|
2107
|
+
const explicitLegacyIntents = [
|
|
2108
|
+
"locate",
|
|
2109
|
+
"trace_flow",
|
|
2110
|
+
"impact",
|
|
2111
|
+
"impact_analysis",
|
|
2112
|
+
"change_aware_lookup",
|
|
2113
|
+
"feature_understanding",
|
|
2114
|
+
];
|
|
2115
|
+
const legacy_intent = explicitIntent && explicitLegacyIntents.includes(explicitIntent)
|
|
2116
|
+
? explicitIntent
|
|
2117
|
+
: (canonical_intent === "feature_lookup"
|
|
2118
|
+
? "feature_understanding"
|
|
2119
|
+
: canonical_intent === "change_lookup"
|
|
2120
|
+
? "change_aware_lookup"
|
|
2121
|
+
: "locate");
|
|
2122
|
+
const feature_key = payload.feature_key
|
|
2123
|
+
|| (payload.feature_name ? this.tryResolveFeatureKeyInput(undefined, payload.feature_name) : null)
|
|
2124
|
+
|| ((canonical_intent === "feature_lookup" && !query && inferredFeatureKey) ? inferredFeatureKey : null)
|
|
2125
|
+
|| (canonical_intent === "change_lookup" ? "change_aware_impact" : undefined);
|
|
2126
|
+
const query_text = String(canonical_intent === "locate_symbol"
|
|
2127
|
+
? (symbolName || query)
|
|
2128
|
+
: canonical_intent === "locate_file"
|
|
2129
|
+
? (relativePath || query)
|
|
2130
|
+
: canonical_intent === "feature_lookup"
|
|
2131
|
+
? (query || payload.feature_name || feature_key || "")
|
|
2132
|
+
: (query || trackerIssueKey || taskId || taskTitle || "")).trim();
|
|
2133
|
+
if (!query_text) {
|
|
2134
|
+
throw new Error("project.developer_query requires payload.query or deterministic selectors");
|
|
2135
|
+
}
|
|
2136
|
+
return {
|
|
2137
|
+
canonical_intent,
|
|
2138
|
+
legacy_intent,
|
|
2139
|
+
query_text,
|
|
2140
|
+
...(symbolName ? { symbol_name: symbolName } : {}),
|
|
2141
|
+
...(relativePath ? { relative_path: relativePath } : {}),
|
|
2142
|
+
...((routePath || routePaths[0]) ? { route_path: routePath || routePaths[0] } : {}),
|
|
2143
|
+
...(routePaths.length > 0 ? { route_paths: routePaths } : {}),
|
|
2144
|
+
...((trackerIssueKey || trackerIssueKeys[0]) ? { tracker_issue_key: trackerIssueKey || trackerIssueKeys[0] } : {}),
|
|
2145
|
+
...((taskId || taskIds[0]) ? { task_id: taskId || taskIds[0] } : {}),
|
|
2146
|
+
...(taskTitle ? { task_title: taskTitle } : {}),
|
|
2147
|
+
...(trackerIssueKeys.length > 0 ? { tracker_issue_keys: trackerIssueKeys } : {}),
|
|
2148
|
+
...(taskIds.length > 0 ? { task_ids: taskIds } : {}),
|
|
2149
|
+
...(feature_key ? { feature_key } : {}),
|
|
2150
|
+
};
|
|
2151
|
+
}
|
|
2152
|
+
inferCanonicalIntentFromQuery(input) {
|
|
2153
|
+
if (input.symbolName)
|
|
2154
|
+
return "locate_symbol";
|
|
2155
|
+
if (input.trackerIssueKey || input.taskId || input.taskTitle)
|
|
2156
|
+
return "change_lookup";
|
|
2157
|
+
if (input.relativePath || input.routePath)
|
|
2158
|
+
return "locate_file";
|
|
2159
|
+
const lowered = input.query.toLowerCase();
|
|
2160
|
+
if (/what breaks if|blast radius|affected|impact|impact analysis|change-aware|change aware|overlay|lookup/.test(lowered)) {
|
|
2161
|
+
return "change_lookup";
|
|
2162
|
+
}
|
|
2163
|
+
if (/where does .* flow|trace|flow/.test(lowered)) {
|
|
2164
|
+
return "change_lookup";
|
|
2165
|
+
}
|
|
2166
|
+
if (/who handles|entrypoint for|where is .* implemented|route|endpoint|api\//.test(lowered)) {
|
|
2167
|
+
return "locate_file";
|
|
2168
|
+
}
|
|
2169
|
+
if (/file|path|\.tsx?|\.jsx?|\/src\//.test(lowered)) {
|
|
2170
|
+
return "locate_file";
|
|
2171
|
+
}
|
|
2172
|
+
if (input.hasFeatureSelector || this.extractFeatureKeyFromQuery(input.query)) {
|
|
2173
|
+
return "feature_lookup";
|
|
2174
|
+
}
|
|
2175
|
+
return "locate_symbol";
|
|
2176
|
+
}
|
|
2177
|
+
pickFeatureKeyForIntent(intent, featureKey, featureName, query) {
|
|
2178
|
+
if (featureKey || featureName) {
|
|
2179
|
+
const resolved = this.tryResolveFeatureKeyInput(featureKey, featureName);
|
|
2180
|
+
if (resolved)
|
|
2181
|
+
return resolved;
|
|
2182
|
+
}
|
|
2183
|
+
if (intent === "impact" || intent === "impact_analysis" || intent === "change_aware_lookup" || intent === "change_lookup") {
|
|
2184
|
+
return "change_aware_impact";
|
|
2185
|
+
}
|
|
2186
|
+
if (intent === "feature_understanding" || intent === "feature_lookup") {
|
|
2187
|
+
if (query)
|
|
2188
|
+
return this.tryResolveFeatureKeyInput(undefined, query);
|
|
2189
|
+
}
|
|
2190
|
+
return null;
|
|
2191
|
+
}
|
|
2192
|
+
tryResolveFeatureKeyInput(featureKey, featureName) {
|
|
2193
|
+
try {
|
|
2194
|
+
return this.resolveFeatureKeyInput(featureKey, featureName);
|
|
2195
|
+
}
|
|
2196
|
+
catch {
|
|
2197
|
+
return null;
|
|
2198
|
+
}
|
|
2199
|
+
}
|
|
2200
|
+
pickOverlaySelectorFromLocate(items, parsed) {
|
|
2201
|
+
const firstTaskId = items.map((item) => item.task_id).find((value) => Boolean(value));
|
|
2202
|
+
const firstIssue = items
|
|
2203
|
+
.map((item) => item.tracker_issue_key)
|
|
2204
|
+
.find((value) => Boolean(value));
|
|
2205
|
+
return {
|
|
2206
|
+
task_id: parsed?.task_id || parsed?.task_ids?.[0] || firstTaskId,
|
|
2207
|
+
tracker_issue_key: parsed?.tracker_issue_key || parsed?.tracker_issue_keys?.[0] || firstIssue,
|
|
2208
|
+
};
|
|
2209
|
+
}
|
|
2210
|
+
extractTrackerIssueKeys(query) {
|
|
2211
|
+
const matches = String(query || "").match(/\b[A-Z][A-Z0-9_]+-\d+\b/g) || [];
|
|
2212
|
+
return Array.from(new Set(matches.map((item) => item.trim().toUpperCase()).filter(Boolean)));
|
|
2213
|
+
}
|
|
2214
|
+
extractTaskIds(query) {
|
|
2215
|
+
const matches = String(query || "").match(/\btask-[a-z0-9-]+\b/gi) || [];
|
|
2216
|
+
return Array.from(new Set(matches.map((item) => item.trim()).filter(Boolean)));
|
|
2217
|
+
}
|
|
2218
|
+
extractRoutePaths(query) {
|
|
2219
|
+
const matches = String(query || "").match(/\/(?:[A-Za-z0-9._~-]+(?:\/[A-Za-z0-9._~-]+)*)?/g) || [];
|
|
2220
|
+
return Array.from(new Set(matches.map((item) => item.trim()).filter((item) => item.startsWith("/") && item.length >= 2)));
|
|
2221
|
+
}
|
|
2222
|
+
extractFeatureKeyFromQuery(query) {
|
|
2223
|
+
const normalized = String(query || "").trim();
|
|
2224
|
+
if (!normalized)
|
|
2225
|
+
return null;
|
|
2226
|
+
return this.tryResolveFeatureKeyInput(undefined, normalized);
|
|
2227
|
+
}
|
|
2228
|
+
resolveFeatureKeyInput(featureKey, featureName) {
|
|
2229
|
+
if (featureKey)
|
|
2230
|
+
return featureKey;
|
|
2231
|
+
const raw = String(featureName || "").trim().toLowerCase();
|
|
2232
|
+
if (!raw)
|
|
2233
|
+
return "project_onboarding_registration_indexing";
|
|
2234
|
+
if (FEATURE_PACK_KEYS.includes(raw)) {
|
|
2235
|
+
return raw;
|
|
2236
|
+
}
|
|
2237
|
+
const compact = raw.replace(/[^a-z0-9]+/g, " ").trim();
|
|
2238
|
+
const has = (token) => compact.includes(token);
|
|
2239
|
+
if ((has("onboarding") || has("registration") || has("index")) && !has("retrieval")) {
|
|
2240
|
+
return "project_onboarding_registration_indexing";
|
|
2241
|
+
}
|
|
2242
|
+
if (has("retrieval") || has("code aware") || has("hybrid")) {
|
|
2243
|
+
return "code_aware_retrieval";
|
|
2244
|
+
}
|
|
2245
|
+
if (has("heartbeat") || has("health") || has("integrity") || has("runtime")) {
|
|
2246
|
+
return "heartbeat_health_runtime_integrity";
|
|
2247
|
+
}
|
|
2248
|
+
if (has("impact") || has("change aware") || has("change")) {
|
|
2249
|
+
return "change_aware_impact";
|
|
2250
|
+
}
|
|
2251
|
+
if (has("post entry") || has("post-entry") || has("review") || has("decision")) {
|
|
2252
|
+
return "post_entry_review_decision_support";
|
|
2253
|
+
}
|
|
2254
|
+
throw new Error(`Unsupported feature selector '${featureName}'. Supported keys: ${FEATURE_PACK_KEYS.join(", ")}`);
|
|
2255
|
+
}
|
|
2256
|
+
buildProjectOnboardingRegistrationIndexingPack(snapshot, projectId, primaryAlias) {
|
|
2257
|
+
const latestRun = snapshot.recent_index_runs[0] || null;
|
|
2258
|
+
const primaryFiles = Array.from(new Set([
|
|
2259
|
+
"src/commands/telegram-addproject-command.ts",
|
|
2260
|
+
"src/tools/project-tools.ts",
|
|
2261
|
+
"src/core/usecases/default-memory-usecase-port.ts",
|
|
2262
|
+
...snapshot.recent_files.map((item) => item.relative_path),
|
|
2263
|
+
].filter(Boolean))).slice(0, 12);
|
|
2264
|
+
const primarySymbols = this.rankPrimarySymbols(snapshot, [
|
|
2265
|
+
"project.telegram_onboarding",
|
|
2266
|
+
"project.register_command",
|
|
2267
|
+
"project.link_tracker",
|
|
2268
|
+
"project.trigger_index",
|
|
2269
|
+
"project.reindex_diff",
|
|
2270
|
+
"registerTelegramAddProjectCommand",
|
|
2271
|
+
"registerProjectTools",
|
|
2272
|
+
"handleProjectRegisterCommand",
|
|
2273
|
+
"handleProjectTriggerIndex",
|
|
2274
|
+
]);
|
|
2275
|
+
return {
|
|
2276
|
+
pack_id: `feature-pack:project_onboarding_registration_indexing:${projectId}`,
|
|
2277
|
+
title: "Project onboarding / registration / indexing",
|
|
2278
|
+
feature_key: "project_onboarding_registration_indexing",
|
|
2279
|
+
summary: `Covers the cross-agent project setup flow from /project onboarding through registry persistence, optional tracker linking, and index/reindex execution for project '${primaryAlias}'.`,
|
|
2280
|
+
primary_files: primaryFiles,
|
|
2281
|
+
primary_symbols: primarySymbols,
|
|
2282
|
+
flow_steps: [
|
|
2283
|
+
{
|
|
2284
|
+
step: 1,
|
|
2285
|
+
title: "Operator enters onboarding",
|
|
2286
|
+
details: "Telegram /project command and project onboarding helper collect repo, alias, Jira, and index-now intent.",
|
|
2287
|
+
related_files: ["src/commands/telegram-addproject-command.ts", "src/tools/project-tools.ts"],
|
|
2288
|
+
related_symbols: ["registerTelegramAddProjectCommand", "project.telegram_onboarding"],
|
|
2289
|
+
},
|
|
2290
|
+
{
|
|
2291
|
+
step: 2,
|
|
2292
|
+
title: "Registration command resolves repo and persists registry state",
|
|
2293
|
+
details: `project.register_command normalizes alias '${primaryAlias}', resolves repo root/remote, writes project + alias + registration state, and can attach tracker mapping.`,
|
|
2294
|
+
related_files: ["src/core/usecases/default-memory-usecase-port.ts", "src/db/slot-db.ts"],
|
|
2295
|
+
related_symbols: ["handleProjectRegisterCommand", "project.register_command"],
|
|
2296
|
+
},
|
|
2297
|
+
{
|
|
2298
|
+
step: 3,
|
|
2299
|
+
title: "Tracker linking enriches project identity",
|
|
2300
|
+
details: "jira/github/other mapping is stored in project tracker mappings so later agents can navigate issue space consistently.",
|
|
2301
|
+
related_files: ["src/core/usecases/default-memory-usecase-port.ts", "src/tools/project-tools.ts"],
|
|
2302
|
+
related_symbols: ["handleProjectLinkTracker", "project.link_tracker"],
|
|
2303
|
+
},
|
|
2304
|
+
{
|
|
2305
|
+
step: 4,
|
|
2306
|
+
title: "Index bootstrap or reindex updates searchable project context",
|
|
2307
|
+
details: `latest known index state is '${latestRun?.state || "not_yet_indexed"}' via ${latestRun?.trigger_type || "bootstrap/manual"} path; background trigger and diff reindex feed file/symbol/chunk registries.`,
|
|
2308
|
+
related_files: ["src/core/usecases/default-memory-usecase-port.ts", "src/db/slot-db.ts"],
|
|
2309
|
+
related_symbols: ["handleProjectTriggerIndex", "project.trigger_index", "project.reindex_diff"],
|
|
2310
|
+
},
|
|
2311
|
+
],
|
|
2312
|
+
risk_points: [
|
|
2313
|
+
"Repo resolution can bind to wrong working tree if repo_root/repo_url selection is inconsistent.",
|
|
2314
|
+
"Invalid Jira space/default epic pairing blocks confirm flow.",
|
|
2315
|
+
"Index trigger may be accepted before concrete paths exist, so first pack consumers should inspect recent index run/watch state.",
|
|
2316
|
+
],
|
|
2317
|
+
test_points: [
|
|
2318
|
+
"project.telegram_onboarding preview rejects invalid Jira mapping and returns summary card.",
|
|
2319
|
+
"project.register_command persists project, alias, registration, and optional tracker mapping.",
|
|
2320
|
+
"project.trigger_index or project.reindex_diff updates index_runs and file/symbol registries for the target project.",
|
|
2321
|
+
],
|
|
2322
|
+
related_tasks: this.collectRelatedTasks(snapshot),
|
|
2323
|
+
related_commits: this.collectRelatedCommitHints(snapshot, ["register", "index", "onboarding"]),
|
|
2324
|
+
related_prs: [],
|
|
2325
|
+
evidence: this.buildEvidenceOrdered(snapshot, {
|
|
2326
|
+
includeRegistration: true,
|
|
2327
|
+
includeTracker: true,
|
|
2328
|
+
includeIndexRuns: 2,
|
|
2329
|
+
includeTasks: 4,
|
|
2330
|
+
includeFiles: 4,
|
|
2331
|
+
includeSymbols: 4,
|
|
2332
|
+
}),
|
|
2333
|
+
generated_at: new Date().toISOString(),
|
|
2334
|
+
generator_version: "asm-93-slice2",
|
|
2335
|
+
};
|
|
2336
|
+
}
|
|
2337
|
+
buildCodeAwareRetrievalPack(snapshot, projectId, primaryAlias) {
|
|
2338
|
+
const primaryFiles = Array.from(new Set([
|
|
2339
|
+
"src/db/slot-db.ts",
|
|
2340
|
+
"src/core/usecases/default-memory-usecase-port.ts",
|
|
2341
|
+
"src/tools/project-tools.ts",
|
|
2342
|
+
...snapshot.recent_files.map((item) => item.relative_path),
|
|
2343
|
+
].filter(Boolean))).slice(0, 12);
|
|
2344
|
+
const primarySymbols = this.rankPrimarySymbols(snapshot, [
|
|
2345
|
+
"project.hybrid_search",
|
|
2346
|
+
"project.task_lineage_context",
|
|
2347
|
+
"graph.code.upsert",
|
|
2348
|
+
"graph.code.chain",
|
|
2349
|
+
"project.reindex_diff",
|
|
2350
|
+
]);
|
|
2351
|
+
return {
|
|
2352
|
+
pack_id: `feature-pack:code_aware_retrieval:${projectId}`,
|
|
2353
|
+
title: "Code-aware retrieval",
|
|
2354
|
+
feature_key: "code_aware_retrieval",
|
|
2355
|
+
summary: `Covers retrieving actionable code context for project '${primaryAlias}' from indexed files/symbols/chunks/tasks with optional lineage expansion and code-graph traversal signals.`,
|
|
2356
|
+
primary_files: primaryFiles,
|
|
2357
|
+
primary_symbols: primarySymbols,
|
|
2358
|
+
flow_steps: [
|
|
2359
|
+
{
|
|
2360
|
+
step: 1,
|
|
2361
|
+
title: "Ingest/reindex populates retrieval registries",
|
|
2362
|
+
details: "project.reindex_diff writes file_index_state, symbol_registry, and chunk_registry with active entries for changed files.",
|
|
2363
|
+
related_files: ["src/db/slot-db.ts", "src/core/usecases/default-memory-usecase-port.ts"],
|
|
2364
|
+
related_symbols: ["project.reindex_diff", "handleProjectReindexDiff"],
|
|
2365
|
+
},
|
|
2366
|
+
{
|
|
2367
|
+
step: 2,
|
|
2368
|
+
title: "Task lineage context narrows retrieval intent",
|
|
2369
|
+
details: "project.task_lineage_context assembles focus task, parent chain, related tasks, and touched symbols/files before ranking.",
|
|
2370
|
+
related_files: ["src/db/slot-db.ts", "src/core/usecases/default-memory-usecase-port.ts"],
|
|
2371
|
+
related_symbols: ["project.task_lineage_context", "handleProjectTaskLineageContext"],
|
|
2372
|
+
},
|
|
2373
|
+
{
|
|
2374
|
+
step: 3,
|
|
2375
|
+
title: "Hybrid retrieval ranks candidates across registries",
|
|
2376
|
+
details: "project.hybrid_search blends file/symbol/chunk/task candidates and supports debug candidate buckets for conformance checks.",
|
|
2377
|
+
related_files: ["src/db/slot-db.ts", "src/tools/project-tools.ts"],
|
|
2378
|
+
related_symbols: ["project.hybrid_search", "handleProjectHybridSearch"],
|
|
2379
|
+
},
|
|
2380
|
+
{
|
|
2381
|
+
step: 4,
|
|
2382
|
+
title: "Code graph traversal augments symbol relations",
|
|
2383
|
+
details: "graph.code.upsert / graph.code.chain provide relation-level traversal for dependency/call chains when symbol-level context is needed.",
|
|
2384
|
+
related_files: ["src/core/usecases/default-memory-usecase-port.ts", "src/tools/graph-tools.ts"],
|
|
2385
|
+
related_symbols: ["graph.code.upsert", "graph.code.chain"],
|
|
2386
|
+
},
|
|
2387
|
+
],
|
|
2388
|
+
risk_points: [
|
|
2389
|
+
"Hybrid retrieval quality depends on freshness of reindex runs and active symbol/chunk state.",
|
|
2390
|
+
"Weak or missing task metadata can reduce lineage-assisted ranking quality.",
|
|
2391
|
+
],
|
|
2392
|
+
test_points: [
|
|
2393
|
+
"project.reindex_diff persists symbols/chunks for changed files.",
|
|
2394
|
+
"project.task_lineage_context returns parent/related context for known task ids.",
|
|
2395
|
+
"project.hybrid_search returns ranked results with debug buckets when requested.",
|
|
2396
|
+
],
|
|
2397
|
+
related_tasks: this.collectRelatedTasks(snapshot),
|
|
2398
|
+
related_commits: this.collectRelatedCommitHints(snapshot, ["hybrid", "retrieval", "reindex", "graph", "symbol"]),
|
|
2399
|
+
related_prs: [],
|
|
2400
|
+
evidence: this.buildEvidenceOrdered(snapshot, {
|
|
2401
|
+
includeRegistration: false,
|
|
2402
|
+
includeTracker: false,
|
|
2403
|
+
includeIndexRuns: 2,
|
|
2404
|
+
includeTasks: 6,
|
|
2405
|
+
includeFiles: 6,
|
|
2406
|
+
includeSymbols: 8,
|
|
2407
|
+
}),
|
|
2408
|
+
generated_at: new Date().toISOString(),
|
|
2409
|
+
generator_version: "asm-93-slice2",
|
|
2410
|
+
};
|
|
2411
|
+
}
|
|
2412
|
+
buildHeartbeatHealthRuntimeIntegrityPack(snapshot, projectId, primaryAlias) {
|
|
2413
|
+
const latestRun = snapshot.recent_index_runs[0] || null;
|
|
2414
|
+
return {
|
|
2415
|
+
pack_id: `feature-pack:heartbeat_health_runtime_integrity:${projectId}`,
|
|
2416
|
+
title: "Heartbeat / health / runtime integrity",
|
|
2417
|
+
feature_key: "heartbeat_health_runtime_integrity",
|
|
2418
|
+
summary: `Covers runtime integrity signals for project '${primaryAlias}' via registration validation state, tracker linkage consistency, and latest index run heartbeat evidence.`,
|
|
2419
|
+
primary_files: Array.from(new Set([
|
|
2420
|
+
"src/core/usecases/default-memory-usecase-port.ts",
|
|
2421
|
+
"src/db/slot-db.ts",
|
|
2422
|
+
"src/tools/project-tools.ts",
|
|
2423
|
+
...snapshot.recent_files.map((item) => item.relative_path),
|
|
2424
|
+
])).slice(0, 10),
|
|
2425
|
+
primary_symbols: this.rankPrimarySymbols(snapshot, [
|
|
2426
|
+
"project.get",
|
|
2427
|
+
"project.set_registration_state",
|
|
2428
|
+
"project.link_tracker",
|
|
2429
|
+
"project.trigger_index",
|
|
2430
|
+
"project.index_watch_get",
|
|
2431
|
+
]),
|
|
2432
|
+
flow_steps: [
|
|
2433
|
+
{
|
|
2434
|
+
step: 1,
|
|
2435
|
+
title: "Registration lifecycle state is the control baseline",
|
|
2436
|
+
details: "project registration_status + validation_status represent current readiness and integrity posture.",
|
|
2437
|
+
related_files: ["src/db/slot-db.ts"],
|
|
2438
|
+
related_symbols: ["project.set_registration_state", "project.get"],
|
|
2439
|
+
},
|
|
2440
|
+
{
|
|
2441
|
+
step: 2,
|
|
2442
|
+
title: "Tracker mapping coherence is validated",
|
|
2443
|
+
details: "Jira/GitHub tracker mappings are validated and persisted, reducing cross-agent drift in runtime operations.",
|
|
2444
|
+
related_files: ["src/core/usecases/default-memory-usecase-port.ts"],
|
|
2445
|
+
related_symbols: ["project.link_tracker", "handleProjectLinkTracker"],
|
|
2446
|
+
},
|
|
2447
|
+
{
|
|
2448
|
+
step: 3,
|
|
2449
|
+
title: "Index runs provide heartbeat for data-plane readiness",
|
|
2450
|
+
details: `latest run is '${latestRun?.state || "none"}' (${latestRun?.trigger_type || "n/a"}); index_runs are used as runtime heartbeat checkpoints.`,
|
|
2451
|
+
related_files: ["src/db/slot-db.ts"],
|
|
2452
|
+
related_symbols: ["project.trigger_index", "project.index_watch_get"],
|
|
2453
|
+
},
|
|
2454
|
+
],
|
|
2455
|
+
risk_points: [
|
|
2456
|
+
"No recent index run can indicate stale runtime context even if registration is valid.",
|
|
2457
|
+
"Validation status can be stale if lifecycle updates are not maintained after tracker/repo changes.",
|
|
2458
|
+
],
|
|
2459
|
+
test_points: [
|
|
2460
|
+
"project.get exposes registration + tracker mapping state for an alias/project id.",
|
|
2461
|
+
"project.trigger_index updates index_runs and can be used as heartbeat signal.",
|
|
2462
|
+
"project.index_watch_get returns checksum/revision watch state for integrity checks.",
|
|
2463
|
+
],
|
|
2464
|
+
related_tasks: this.collectRelatedTasks(snapshot),
|
|
2465
|
+
related_commits: this.collectRelatedCommitHints(snapshot, ["health", "integrity", "watch", "registration", "index"]),
|
|
2466
|
+
related_prs: [],
|
|
2467
|
+
evidence: this.buildEvidenceOrdered(snapshot, {
|
|
2468
|
+
includeRegistration: true,
|
|
2469
|
+
includeTracker: true,
|
|
2470
|
+
includeIndexRuns: 3,
|
|
2471
|
+
includeTasks: 3,
|
|
2472
|
+
includeFiles: 3,
|
|
2473
|
+
includeSymbols: 3,
|
|
2474
|
+
}),
|
|
2475
|
+
generated_at: new Date().toISOString(),
|
|
2476
|
+
generator_version: "asm-93-slice2",
|
|
2477
|
+
};
|
|
2478
|
+
}
|
|
2479
|
+
buildChangeAwareImpactPack(snapshot, projectId, primaryAlias) {
|
|
2480
|
+
const latestRun = snapshot.recent_index_runs[0] || null;
|
|
2481
|
+
return {
|
|
2482
|
+
pack_id: `feature-pack:change_aware_impact:${projectId}`,
|
|
2483
|
+
title: "Change-aware impact",
|
|
2484
|
+
feature_key: "change_aware_impact",
|
|
2485
|
+
summary: `Covers impact-oriented flow for project '${primaryAlias}' where changed files/symbols are reindexed and then consumed by lineage/hybrid retrieval to estimate downstream effect scope.`,
|
|
2486
|
+
primary_files: Array.from(new Set([
|
|
2487
|
+
"src/db/slot-db.ts",
|
|
2488
|
+
"src/core/usecases/default-memory-usecase-port.ts",
|
|
2489
|
+
"src/tools/project-tools.ts",
|
|
2490
|
+
...snapshot.recent_files.map((item) => item.relative_path),
|
|
2491
|
+
])).slice(0, 12),
|
|
2492
|
+
primary_symbols: this.rankPrimarySymbols(snapshot, [
|
|
2493
|
+
"project.reindex_diff",
|
|
2494
|
+
"project.index_event",
|
|
2495
|
+
"project.index_watch_get",
|
|
2496
|
+
"project.task_registry_upsert",
|
|
2497
|
+
"project.task_lineage_context",
|
|
2498
|
+
"project.hybrid_search",
|
|
2499
|
+
]),
|
|
2500
|
+
flow_steps: [
|
|
2501
|
+
{
|
|
2502
|
+
step: 1,
|
|
2503
|
+
title: "Diff/event ingestion captures changed paths",
|
|
2504
|
+
details: "project.reindex_diff (or project.index_event) accepts changed/deleted files and updates index/watch state.",
|
|
2505
|
+
related_files: ["src/db/slot-db.ts", "src/core/usecases/default-memory-usecase-port.ts"],
|
|
2506
|
+
related_symbols: ["project.reindex_diff", "project.index_event", "project.index_watch_get"],
|
|
2507
|
+
},
|
|
2508
|
+
{
|
|
2509
|
+
step: 2,
|
|
2510
|
+
title: "Task lineage stores declared impact hints",
|
|
2511
|
+
details: "project.task_registry_upsert tracks files_touched/symbols_touched/related tasks to enrich later impact analysis.",
|
|
2512
|
+
related_files: ["src/db/slot-db.ts"],
|
|
2513
|
+
related_symbols: ["project.task_registry_upsert", "project.task_lineage_context"],
|
|
2514
|
+
},
|
|
2515
|
+
{
|
|
2516
|
+
step: 3,
|
|
2517
|
+
title: "Hybrid retrieval assembles impact candidates",
|
|
2518
|
+
details: "project.hybrid_search combines changed files/symbols and lineage context to return practical impact candidates.",
|
|
2519
|
+
related_files: ["src/db/slot-db.ts", "src/tools/project-tools.ts"],
|
|
2520
|
+
related_symbols: ["project.hybrid_search"],
|
|
2521
|
+
},
|
|
2522
|
+
],
|
|
2523
|
+
risk_points: [
|
|
2524
|
+
"Placeholder checksums or stale watch state can hide true file deltas.",
|
|
2525
|
+
"Impact accuracy depends on discipline in task_registry_upsert metadata quality.",
|
|
2526
|
+
],
|
|
2527
|
+
test_points: [
|
|
2528
|
+
"project.reindex_diff updates file index and watch state for changed/deleted paths.",
|
|
2529
|
+
"project.task_registry_upsert captures files_touched and symbols_touched.",
|
|
2530
|
+
"project.hybrid_search can be constrained by task context for impact-oriented queries.",
|
|
2531
|
+
],
|
|
2532
|
+
related_tasks: this.collectRelatedTasks(snapshot),
|
|
2533
|
+
related_commits: this.collectRelatedCommitHints(snapshot, ["reindex", "diff", "impact", "lineage", "watch"]),
|
|
2534
|
+
related_prs: [],
|
|
2535
|
+
evidence: this.buildEvidenceOrdered(snapshot, {
|
|
2536
|
+
includeRegistration: false,
|
|
2537
|
+
includeTracker: false,
|
|
2538
|
+
includeIndexRuns: 3,
|
|
2539
|
+
includeTasks: 6,
|
|
2540
|
+
includeFiles: 8,
|
|
2541
|
+
includeSymbols: 6,
|
|
2542
|
+
}),
|
|
2543
|
+
generated_at: new Date().toISOString(),
|
|
2544
|
+
generator_version: "asm-93-slice2",
|
|
2545
|
+
};
|
|
2546
|
+
}
|
|
2547
|
+
buildPostEntryReviewDecisionSupportPack(snapshot, projectId, primaryAlias) {
|
|
2548
|
+
const keywordMatchers = ["post-entry", "post entry", "review", "decision", "outcome", "policy", "trace"];
|
|
2549
|
+
const matchingTasks = snapshot.recent_tasks.filter((task) => {
|
|
2550
|
+
const title = task.task_title.toLowerCase();
|
|
2551
|
+
return keywordMatchers.some((kw) => title.includes(kw));
|
|
2552
|
+
});
|
|
2553
|
+
const matchingSymbols = snapshot.recent_symbols.filter((symbol) => {
|
|
2554
|
+
const s = `${symbol.symbol_name} ${symbol.symbol_fqn}`.toLowerCase();
|
|
2555
|
+
return keywordMatchers.some((kw) => s.includes(kw));
|
|
2556
|
+
});
|
|
2557
|
+
if (matchingTasks.length === 0 && matchingSymbols.length === 0) {
|
|
2558
|
+
throw new Error("feature_key post_entry_review_decision_support does not have enough indexed evidence yet (need task/symbol signals for post-entry/review/decision).");
|
|
2559
|
+
}
|
|
2560
|
+
return {
|
|
2561
|
+
pack_id: `feature-pack:post_entry_review_decision_support:${projectId}`,
|
|
2562
|
+
title: "Post-entry review decision support",
|
|
2563
|
+
feature_key: "post_entry_review_decision_support",
|
|
2564
|
+
summary: `Covers post-entry decision support for project '${primaryAlias}' by prioritizing review/outcome evidence from task + symbol history and mapping it into retrieval-ready surfaces.`,
|
|
2565
|
+
primary_files: Array.from(new Set([
|
|
2566
|
+
...matchingSymbols.map((item) => item.relative_path),
|
|
2567
|
+
...snapshot.recent_files.map((item) => item.relative_path),
|
|
2568
|
+
"src/core/usecases/default-memory-usecase-port.ts",
|
|
2569
|
+
"src/db/slot-db.ts",
|
|
2570
|
+
].filter(Boolean))).slice(0, 10),
|
|
2571
|
+
primary_symbols: this.rankPrimarySymbols(snapshot, [
|
|
2572
|
+
"project.task_registry_upsert",
|
|
2573
|
+
"project.task_lineage_context",
|
|
2574
|
+
"project.hybrid_search",
|
|
2575
|
+
...matchingSymbols.map((item) => item.symbol_fqn || item.symbol_name),
|
|
2576
|
+
]),
|
|
2577
|
+
flow_steps: [
|
|
2578
|
+
{
|
|
2579
|
+
step: 1,
|
|
2580
|
+
title: "Review/decision traces are captured in task metadata",
|
|
2581
|
+
details: "task_registry entries store decision_notes, task_status, tracker key, and touched files/symbols to preserve post-entry context.",
|
|
2582
|
+
related_files: ["src/db/slot-db.ts"],
|
|
2583
|
+
related_symbols: ["project.task_registry_upsert"],
|
|
2584
|
+
},
|
|
2585
|
+
{
|
|
2586
|
+
step: 2,
|
|
2587
|
+
title: "Lineage context reconstructs decision chain",
|
|
2588
|
+
details: "project.task_lineage_context can reconstruct parent/related chain to explain why a post-entry action was taken.",
|
|
2589
|
+
related_files: ["src/core/usecases/default-memory-usecase-port.ts"],
|
|
2590
|
+
related_symbols: ["project.task_lineage_context"],
|
|
2591
|
+
},
|
|
2592
|
+
{
|
|
2593
|
+
step: 3,
|
|
2594
|
+
title: "Hybrid retrieval surfaces decision-support evidence",
|
|
2595
|
+
details: "project.hybrid_search ranks symbols/files/tasks so agents can consume review evidence with minimal manual browsing.",
|
|
2596
|
+
related_files: ["src/db/slot-db.ts", "src/tools/project-tools.ts"],
|
|
2597
|
+
related_symbols: ["project.hybrid_search"],
|
|
2598
|
+
},
|
|
2599
|
+
],
|
|
2600
|
+
risk_points: [
|
|
2601
|
+
"If task titles/notes do not contain explicit review/decision markers, this pack can become too weak.",
|
|
2602
|
+
"Without indexed symbols related to review/outcome logic, evidence may skew toward generic tasks.",
|
|
2603
|
+
],
|
|
2604
|
+
test_points: [
|
|
2605
|
+
"project.task_registry_upsert stores decision-oriented metadata for review tasks.",
|
|
2606
|
+
"project.task_lineage_context returns parent/related chain for decision tasks.",
|
|
2607
|
+
"project.hybrid_search retrieves decision keywords from task/symbol/file registries.",
|
|
2608
|
+
],
|
|
2609
|
+
related_tasks: Array.from(new Set(matchingTasks
|
|
2610
|
+
.flatMap((task) => [task.tracker_issue_key, task.task_id])
|
|
2611
|
+
.filter(Boolean))).slice(0, 12),
|
|
2612
|
+
related_commits: this.collectRelatedCommitHints(snapshot, ["post-entry", "review", "decision", "outcome", "trace"]),
|
|
2613
|
+
related_prs: [],
|
|
2614
|
+
evidence: this.buildEvidenceOrdered(snapshot, {
|
|
2615
|
+
includeRegistration: false,
|
|
2616
|
+
includeTracker: false,
|
|
2617
|
+
includeIndexRuns: 2,
|
|
2618
|
+
includeTasks: 8,
|
|
2619
|
+
includeFiles: 6,
|
|
2620
|
+
includeSymbols: 8,
|
|
2621
|
+
}),
|
|
2622
|
+
generated_at: new Date().toISOString(),
|
|
2623
|
+
generator_version: "asm-93-slice2",
|
|
2624
|
+
};
|
|
2625
|
+
}
|
|
2626
|
+
rankPrimarySymbols(snapshot, preferred) {
|
|
2627
|
+
const snapshotSymbols = snapshot.recent_symbols.flatMap((item) => [item.symbol_fqn, item.symbol_name]);
|
|
2628
|
+
return Array.from(new Set([...preferred, ...snapshotSymbols].filter(Boolean))).slice(0, 16);
|
|
2629
|
+
}
|
|
2630
|
+
collectRelatedTasks(snapshot) {
|
|
2631
|
+
return Array.from(new Set(snapshot.recent_tasks
|
|
2632
|
+
.flatMap((task) => [task.tracker_issue_key, task.task_id])
|
|
2633
|
+
.filter(Boolean))).slice(0, 12);
|
|
2634
|
+
}
|
|
2635
|
+
collectRelatedCommitHints(snapshot, keywords) {
|
|
2636
|
+
const lowered = keywords.map((kw) => kw.toLowerCase());
|
|
2637
|
+
return Array.from(new Set(snapshot.recent_tasks
|
|
2638
|
+
.map((task) => {
|
|
2639
|
+
const title = task.task_title.toLowerCase();
|
|
2640
|
+
const hit = lowered.find((kw) => title.includes(kw));
|
|
2641
|
+
return hit ? `task:${hit.replace(/\s+/g, "-")}` : null;
|
|
2642
|
+
})
|
|
2643
|
+
.filter(Boolean)));
|
|
2644
|
+
}
|
|
2645
|
+
buildEvidenceOrdered(snapshot, options) {
|
|
2646
|
+
const registrationState = snapshot.registration;
|
|
2647
|
+
const jiraMapping = snapshot.tracker_mappings.find((item) => item.tracker_type === "jira") || snapshot.tracker_mappings[0] || null;
|
|
2648
|
+
return [
|
|
2649
|
+
{ type: "project", ref: snapshot.project.project_id, note: snapshot.project.project_name },
|
|
2650
|
+
...snapshot.aliases.slice(0, 3).map((item) => ({ type: "project", ref: item.project_alias, note: item.is_primary === 1 ? "primary_alias" : "alias" })),
|
|
2651
|
+
...(options.includeRegistration && registrationState
|
|
2652
|
+
? [{ type: "registration", ref: registrationState.registration_status, note: registrationState.validation_status }]
|
|
2653
|
+
: []),
|
|
2654
|
+
...(options.includeTracker && jiraMapping
|
|
2655
|
+
? [{ type: "tracker", ref: jiraMapping.tracker_type, note: jiraMapping.tracker_space_key || jiraMapping.default_epic_key || undefined }]
|
|
2656
|
+
: []),
|
|
2657
|
+
...snapshot.recent_index_runs.slice(0, options.includeIndexRuns).map((item) => ({ type: "index", ref: item.run_id, note: `${item.trigger_type}:${item.state}` })),
|
|
2658
|
+
...snapshot.recent_tasks.slice(0, options.includeTasks).map((item) => ({ type: "task", ref: item.tracker_issue_key || item.task_id, note: item.task_title })),
|
|
2659
|
+
...snapshot.recent_files.slice(0, options.includeFiles).map((item) => ({ type: "file", ref: item.relative_path })),
|
|
2660
|
+
...snapshot.recent_symbols.slice(0, options.includeSymbols).map((item) => ({ type: "symbol", ref: item.symbol_fqn || item.symbol_name, note: item.relative_path })),
|
|
2661
|
+
];
|
|
2662
|
+
}
|
|
1157
2663
|
handleGraphEntityGet(payload, req) {
|
|
1158
2664
|
const identity = normalizePrivateIdentity(req.context);
|
|
1159
2665
|
if (payload.id) {
|
|
@@ -1247,5 +2753,58 @@ asm project-event --project-id "$PROJECT_ID" --repo-root "$REPO_ROOT" --event-ty
|
|
|
1247
2753
|
relationships: traversed.relationships.filter((rel) => rel.relation_type === payload.relation_type),
|
|
1248
2754
|
};
|
|
1249
2755
|
}
|
|
2756
|
+
handleGraphCodeUpsert(payload, req) {
|
|
2757
|
+
const identity = normalizePrivateIdentity(req.context);
|
|
2758
|
+
const nodes = Array.isArray(payload.nodes) ? payload.nodes : [];
|
|
2759
|
+
const relations = Array.isArray(payload.relations) ? payload.relations : [];
|
|
2760
|
+
if (nodes.length === 0) {
|
|
2761
|
+
throw new Error("graph.code.upsert requires non-empty nodes");
|
|
2762
|
+
}
|
|
2763
|
+
for (const node of nodes) {
|
|
2764
|
+
if (!node.node_id || !isUniversalGraphNodeType(node.node_type) || !node.name) {
|
|
2765
|
+
throw new Error("graph.code.upsert node invalid: require node_id, node_type, name");
|
|
2766
|
+
}
|
|
2767
|
+
upsertUniversalGraphNode(this.slotDb.graph, identity.userId, identity.agentId, node);
|
|
2768
|
+
}
|
|
2769
|
+
for (const relation of relations) {
|
|
2770
|
+
if (!relation.source_node_id ||
|
|
2771
|
+
!relation.target_node_id ||
|
|
2772
|
+
!isUniversalGraphRelationType(relation.relation_type) ||
|
|
2773
|
+
!isValidUniversalGraphProvenance(relation.provenance)) {
|
|
2774
|
+
throw new Error("graph.code.upsert relation invalid: require source_node_id, target_node_id, relation_type, provenance");
|
|
2775
|
+
}
|
|
2776
|
+
const source = this.slotDb.graph.getEntity(identity.userId, identity.agentId, relation.source_node_id);
|
|
2777
|
+
if (!source) {
|
|
2778
|
+
throw new Error(`graph.code.upsert relation source '${relation.source_node_id}' not found`);
|
|
2779
|
+
}
|
|
2780
|
+
const target = this.slotDb.graph.getEntity(identity.userId, identity.agentId, relation.target_node_id);
|
|
2781
|
+
if (!target) {
|
|
2782
|
+
throw new Error(`graph.code.upsert relation target '${relation.target_node_id}' not found`);
|
|
2783
|
+
}
|
|
2784
|
+
upsertUniversalGraphRelation(this.slotDb.graph, identity.userId, identity.agentId, relation);
|
|
2785
|
+
}
|
|
2786
|
+
return {
|
|
2787
|
+
graph_model: UNIVERSAL_GRAPH_MODEL_VERSION,
|
|
2788
|
+
nodes_upserted: nodes.length,
|
|
2789
|
+
relations_upserted: relations.length,
|
|
2790
|
+
};
|
|
2791
|
+
}
|
|
2792
|
+
handleGraphCodeChain(payload, req) {
|
|
2793
|
+
const identity = normalizePrivateIdentity(req.context);
|
|
2794
|
+
const nodeId = String(payload.node_id || "").trim();
|
|
2795
|
+
if (!nodeId) {
|
|
2796
|
+
throw new Error("graph.code.chain requires node_id");
|
|
2797
|
+
}
|
|
2798
|
+
const depth = Math.min(Math.max(payload.depth || 2, 1), 4);
|
|
2799
|
+
const traversed = this.slotDb.graph.traverseCodeGraph(identity.userId, identity.agentId, nodeId, depth, payload.relation_type);
|
|
2800
|
+
const relationships = traversed.relationships;
|
|
2801
|
+
return {
|
|
2802
|
+
graph_model: UNIVERSAL_GRAPH_MODEL_VERSION,
|
|
2803
|
+
start_node_id: nodeId,
|
|
2804
|
+
depth,
|
|
2805
|
+
entities: traversed.entities,
|
|
2806
|
+
relationships,
|
|
2807
|
+
};
|
|
2808
|
+
}
|
|
1250
2809
|
}
|
|
1251
2810
|
//# sourceMappingURL=default-memory-usecase-port.js.map
|