@adhdev/daemon-core 0.9.82-rc.410 → 0.9.82-rc.412
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/med-family/mesh-crud.d.ts +27 -0
- package/dist/config/mesh-json-config.d.ts +31 -131
- package/dist/config/repo-settings.d.ts +77 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +372 -419
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +360 -408
- package/dist/index.mjs.map +1 -1
- package/dist/mesh/mesh-ledger.d.ts +1 -1
- package/package.json +2 -2
- package/src/commands/high-family/mesh-coordinator-launch.ts +9 -4
- package/src/commands/med-family/mesh-crud.ts +85 -8
- package/src/config/mesh-json-config.ts +40 -281
- package/src/config/repo-settings.ts +111 -0
- package/src/index.ts +5 -0
- package/src/mesh/mesh-ledger.ts +10 -0
- package/src/mesh/mesh-missions.ts +86 -1
- package/src/mesh/mesh-queue-assignment.ts +15 -51
package/dist/index.mjs
CHANGED
|
@@ -31,14 +31,6 @@ function normalizeMeshSchedulingStrategy(value) {
|
|
|
31
31
|
const trimmed = value.trim();
|
|
32
32
|
return MESH_SCHEDULING_STRATEGIES.includes(trimmed) ? trimmed : DEFAULT_MESH_SCHEDULING_STRATEGY;
|
|
33
33
|
}
|
|
34
|
-
function normalizeMeshDistribution(value) {
|
|
35
|
-
if (typeof value !== "string") return DEFAULT_MESH_DISTRIBUTION;
|
|
36
|
-
const trimmed = value.trim();
|
|
37
|
-
return MESH_DISTRIBUTIONS.includes(trimmed) ? trimmed : DEFAULT_MESH_DISTRIBUTION;
|
|
38
|
-
}
|
|
39
|
-
function distributionToStrategy(distribution) {
|
|
40
|
-
return distribution === "spread" ? "least_loaded" : "first_eligible";
|
|
41
|
-
}
|
|
42
34
|
function resolveNodeSchedulingPriority(nodePolicy) {
|
|
43
35
|
const raw = Number(nodePolicy?.schedulingPriority);
|
|
44
36
|
return Number.isFinite(raw) ? raw : 0;
|
|
@@ -125,7 +117,7 @@ function resolveProviderMaxParallel(nodePolicy, providerType) {
|
|
|
125
117
|
}
|
|
126
118
|
return void 0;
|
|
127
119
|
}
|
|
128
|
-
var MESH_SCHEDULING_STRATEGIES, DEFAULT_MESH_SCHEDULING_STRATEGY,
|
|
120
|
+
var MESH_SCHEDULING_STRATEGIES, DEFAULT_MESH_SCHEDULING_STRATEGY, MESH_CONVERGE_REFINE_TAG, MESH_CONVERGE_FAST_FORWARD_TAG, DEFAULT_MESH_POLICY, SESSION_CLEANUP_MODES, SPAWNED_SESSION_VISIBILITY_MODES, DIRTY_WORKSPACE_BEHAVIORS, MESH_MAX_PARALLEL_TASKS_MIN, MESH_MAX_PARALLEL_TASKS_MAX, DEFAULT_MESH_READONLY_MULTIPLIER;
|
|
129
121
|
var init_repo_mesh_types = __esm({
|
|
130
122
|
"src/repo-mesh-types.ts"() {
|
|
131
123
|
"use strict";
|
|
@@ -136,8 +128,6 @@ var init_repo_mesh_types = __esm({
|
|
|
136
128
|
"priority_only"
|
|
137
129
|
];
|
|
138
130
|
DEFAULT_MESH_SCHEDULING_STRATEGY = "first_eligible";
|
|
139
|
-
MESH_DISTRIBUTIONS = ["spread", "in_order"];
|
|
140
|
-
DEFAULT_MESH_DISTRIBUTION = "spread";
|
|
141
131
|
MESH_CONVERGE_REFINE_TAG = "converge=refine";
|
|
142
132
|
MESH_CONVERGE_FAST_FORWARD_TAG = "converge=fast_forward";
|
|
143
133
|
DEFAULT_MESH_POLICY = {
|
|
@@ -394,10 +384,10 @@ function readInjected(value) {
|
|
|
394
384
|
}
|
|
395
385
|
function getDaemonBuildInfo() {
|
|
396
386
|
if (cached) return cached;
|
|
397
|
-
const commit = readInjected(true ? "
|
|
398
|
-
const commitShort = readInjected(true ? "
|
|
399
|
-
const version = readInjected(true ? "0.9.82-rc.
|
|
400
|
-
const builtAt = readInjected(true ? "2026-06-
|
|
387
|
+
const commit = readInjected(true ? "f8bbe838081c3b3e14df690b3ed24568979f635e" : void 0) ?? "unknown";
|
|
388
|
+
const commitShort = readInjected(true ? "f8bbe838" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
|
|
389
|
+
const version = readInjected(true ? "0.9.82-rc.412" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
|
|
390
|
+
const builtAt = readInjected(true ? "2026-06-28T10:27:03.423Z" : void 0);
|
|
401
391
|
cached = builtAt ? { commit, commitShort, version, builtAt } : { commit, commitShort, version };
|
|
402
392
|
return cached;
|
|
403
393
|
}
|
|
@@ -7092,6 +7082,9 @@ __export(mesh_missions_exports, {
|
|
|
7092
7082
|
upsertMeshMission: () => upsertMeshMission
|
|
7093
7083
|
});
|
|
7094
7084
|
import { randomUUID as randomUUID7 } from "crypto";
|
|
7085
|
+
function summarizeGoalForLedger(goal) {
|
|
7086
|
+
return goal.length > LEDGER_GOAL_SUMMARY_MAX ? goal.slice(0, LEDGER_GOAL_SUMMARY_MAX) : goal;
|
|
7087
|
+
}
|
|
7095
7088
|
function normalizeMissionStatus(value) {
|
|
7096
7089
|
return MESH_MISSION_STATUSES.includes(value) ? value : "active";
|
|
7097
7090
|
}
|
|
@@ -7104,6 +7097,8 @@ function upsertMeshMission(meshId, input) {
|
|
|
7104
7097
|
const id = typeof input.id === "string" && input.id.trim() ? input.id.trim() : randomUUID7();
|
|
7105
7098
|
const store = MeshRuntimeStore.getInstance();
|
|
7106
7099
|
const existing = store.getMission(meshId, id);
|
|
7100
|
+
const prevStatus = existing ? normalizeMissionStatus(existing.status) : null;
|
|
7101
|
+
const prevGoal = existing?.goal ?? "";
|
|
7107
7102
|
const record = {
|
|
7108
7103
|
id,
|
|
7109
7104
|
meshId,
|
|
@@ -7113,7 +7108,61 @@ function upsertMeshMission(meshId, input) {
|
|
|
7113
7108
|
};
|
|
7114
7109
|
store.upsertMission(record);
|
|
7115
7110
|
const saved = store.getMission(meshId, id);
|
|
7116
|
-
|
|
7111
|
+
const result = { ...saved, status: normalizeMissionStatus(saved.status) };
|
|
7112
|
+
appendMissionLedgerEntries(meshId, {
|
|
7113
|
+
isCreate: !existing,
|
|
7114
|
+
record: result,
|
|
7115
|
+
prevStatus,
|
|
7116
|
+
prevGoal
|
|
7117
|
+
});
|
|
7118
|
+
return result;
|
|
7119
|
+
}
|
|
7120
|
+
function appendMissionLedgerEntries(meshId, args) {
|
|
7121
|
+
const { isCreate, record, prevStatus, prevGoal } = args;
|
|
7122
|
+
try {
|
|
7123
|
+
if (isCreate) {
|
|
7124
|
+
const goal = record.goal ?? "";
|
|
7125
|
+
appendLedgerEntry(meshId, {
|
|
7126
|
+
kind: "mission_created",
|
|
7127
|
+
payload: {
|
|
7128
|
+
missionId: record.id,
|
|
7129
|
+
title: record.title,
|
|
7130
|
+
goalSummary: summarizeGoalForLedger(goal),
|
|
7131
|
+
goalLength: goal.length,
|
|
7132
|
+
goalTruncated: goal.length > LEDGER_GOAL_SUMMARY_MAX,
|
|
7133
|
+
status: record.status
|
|
7134
|
+
}
|
|
7135
|
+
});
|
|
7136
|
+
return;
|
|
7137
|
+
}
|
|
7138
|
+
if (prevStatus !== null && prevStatus !== record.status) {
|
|
7139
|
+
appendLedgerEntry(meshId, {
|
|
7140
|
+
kind: "mission_status_changed",
|
|
7141
|
+
payload: {
|
|
7142
|
+
missionId: record.id,
|
|
7143
|
+
title: record.title,
|
|
7144
|
+
fromStatus: prevStatus,
|
|
7145
|
+
toStatus: record.status
|
|
7146
|
+
}
|
|
7147
|
+
});
|
|
7148
|
+
}
|
|
7149
|
+
const nextGoal = record.goal ?? "";
|
|
7150
|
+
if (nextGoal !== prevGoal) {
|
|
7151
|
+
appendLedgerEntry(meshId, {
|
|
7152
|
+
kind: "mission_goal_updated",
|
|
7153
|
+
payload: {
|
|
7154
|
+
missionId: record.id,
|
|
7155
|
+
title: record.title,
|
|
7156
|
+
prevGoalSummary: summarizeGoalForLedger(prevGoal),
|
|
7157
|
+
nextGoalSummary: summarizeGoalForLedger(nextGoal),
|
|
7158
|
+
prevGoalLength: prevGoal.length,
|
|
7159
|
+
nextGoalLength: nextGoal.length,
|
|
7160
|
+
goalTruncated: prevGoal.length > LEDGER_GOAL_SUMMARY_MAX || nextGoal.length > LEDGER_GOAL_SUMMARY_MAX
|
|
7161
|
+
}
|
|
7162
|
+
});
|
|
7163
|
+
}
|
|
7164
|
+
} catch {
|
|
7165
|
+
}
|
|
7117
7166
|
}
|
|
7118
7167
|
function getMeshMissions(meshId, statuses) {
|
|
7119
7168
|
return MeshRuntimeStore.getInstance().getMissions(meshId, statuses).map((m) => ({ ...m, status: normalizeMissionStatus(m.status) }));
|
|
@@ -7217,13 +7266,15 @@ function buildMissionPromptSection(meshId) {
|
|
|
7217
7266
|
);
|
|
7218
7267
|
return lines.join("\n");
|
|
7219
7268
|
}
|
|
7220
|
-
var MESH_MISSION_STATUSES, GOAL_PREVIEW_MAX, COMPACT_STATUS_GOAL_PREVIEW_MAX;
|
|
7269
|
+
var LEDGER_GOAL_SUMMARY_MAX, MESH_MISSION_STATUSES, GOAL_PREVIEW_MAX, COMPACT_STATUS_GOAL_PREVIEW_MAX;
|
|
7221
7270
|
var init_mesh_missions = __esm({
|
|
7222
7271
|
"src/mesh/mesh-missions.ts"() {
|
|
7223
7272
|
"use strict";
|
|
7224
7273
|
init_mesh_runtime_store();
|
|
7225
7274
|
init_mesh_work_queue();
|
|
7226
7275
|
init_mesh_task_stats();
|
|
7276
|
+
init_mesh_ledger();
|
|
7277
|
+
LEDGER_GOAL_SUMMARY_MAX = 200;
|
|
7227
7278
|
MESH_MISSION_STATUSES = ["active", "paused", "completed", "abandoned"];
|
|
7228
7279
|
GOAL_PREVIEW_MAX = 120;
|
|
7229
7280
|
COMPACT_STATUS_GOAL_PREVIEW_MAX = 80;
|
|
@@ -8677,6 +8728,216 @@ var init_worktree_bootstrap_config = __esm({
|
|
|
8677
8728
|
}
|
|
8678
8729
|
});
|
|
8679
8730
|
|
|
8731
|
+
// src/config/mesh-json-config.ts
|
|
8732
|
+
var mesh_json_config_exports = {};
|
|
8733
|
+
__export(mesh_json_config_exports, {
|
|
8734
|
+
MESH_JSON_CONFIG_LOCATIONS: () => MESH_JSON_CONFIG_LOCATIONS,
|
|
8735
|
+
MESH_JSON_CONFIG_SCHEMA: () => MESH_JSON_CONFIG_SCHEMA,
|
|
8736
|
+
applyRepoMeshConfig: () => applyRepoMeshConfig,
|
|
8737
|
+
buildMeshJsonConfigScaffold: () => buildMeshJsonConfigScaffold,
|
|
8738
|
+
loadRepoMeshJsonConfig: () => loadRepoMeshJsonConfig,
|
|
8739
|
+
mergeEffectiveCoordinatorConfig: () => mergeEffectiveCoordinatorConfig,
|
|
8740
|
+
mergeEffectiveOperatingNotes: () => mergeEffectiveOperatingNotes,
|
|
8741
|
+
normalizeRepoMeshDeclarativeConfig: () => normalizeRepoMeshDeclarativeConfig,
|
|
8742
|
+
serializeMeshJsonConfigScaffold: () => serializeMeshJsonConfigScaffold
|
|
8743
|
+
});
|
|
8744
|
+
import { existsSync as existsSync14, readFileSync as readFileSync11 } from "fs";
|
|
8745
|
+
import { join as join15 } from "path";
|
|
8746
|
+
import * as yaml4 from "js-yaml";
|
|
8747
|
+
function isRecord3(value) {
|
|
8748
|
+
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
8749
|
+
}
|
|
8750
|
+
function parseConfigText4(path43, text) {
|
|
8751
|
+
if (/\.json$/i.test(path43)) return JSON.parse(text);
|
|
8752
|
+
return yaml4.load(text);
|
|
8753
|
+
}
|
|
8754
|
+
function normalizeOperatingNote(value) {
|
|
8755
|
+
if (!isRecord3(value)) return null;
|
|
8756
|
+
const text = typeof value.text === "string" ? value.text.trim() : "";
|
|
8757
|
+
if (!text) return null;
|
|
8758
|
+
const category = value.category === "provider_quirk" || value.category === "pattern_to_avoid" || value.category === "recovery_lesson" ? value.category : void 0;
|
|
8759
|
+
return {
|
|
8760
|
+
text,
|
|
8761
|
+
...category ? { category } : {},
|
|
8762
|
+
...typeof value.createdAt === "string" ? { createdAt: value.createdAt } : {},
|
|
8763
|
+
...typeof value.sourceCoordinator === "string" ? { sourceCoordinator: value.sourceCoordinator } : {}
|
|
8764
|
+
};
|
|
8765
|
+
}
|
|
8766
|
+
function normalizeRepoMeshDeclarativeConfig(parsed) {
|
|
8767
|
+
const errors = [];
|
|
8768
|
+
if (!isRecord3(parsed)) return { valid: false, errors: ["config must be an object"] };
|
|
8769
|
+
if (parsed.version !== 1) {
|
|
8770
|
+
return { valid: false, errors: [`version must be 1 (got ${JSON.stringify(parsed.version)})`] };
|
|
8771
|
+
}
|
|
8772
|
+
const config = { version: 1 };
|
|
8773
|
+
if (parsed.coordinator !== void 0) {
|
|
8774
|
+
if (isRecord3(parsed.coordinator)) {
|
|
8775
|
+
const coord = {};
|
|
8776
|
+
const c = parsed.coordinator;
|
|
8777
|
+
if (typeof c.systemPromptOverride === "string") coord.systemPromptOverride = c.systemPromptOverride;
|
|
8778
|
+
if (typeof c.systemPromptAppend === "string") coord.systemPromptAppend = c.systemPromptAppend;
|
|
8779
|
+
if (Number.isFinite(Number(c.maxPromptChars))) coord.maxPromptChars = Number(c.maxPromptChars);
|
|
8780
|
+
config.coordinator = coord;
|
|
8781
|
+
} else {
|
|
8782
|
+
errors.push("coordinator must be an object when provided");
|
|
8783
|
+
}
|
|
8784
|
+
}
|
|
8785
|
+
if (parsed.operatingNotes !== void 0) {
|
|
8786
|
+
if (Array.isArray(parsed.operatingNotes)) {
|
|
8787
|
+
const notes = parsed.operatingNotes.map(normalizeOperatingNote).filter((n) => n !== null);
|
|
8788
|
+
if (notes.length) config.operatingNotes = notes;
|
|
8789
|
+
} else {
|
|
8790
|
+
errors.push("operatingNotes must be an array when provided");
|
|
8791
|
+
}
|
|
8792
|
+
}
|
|
8793
|
+
if (parsed.limits !== void 0) {
|
|
8794
|
+
if (isRecord3(parsed.limits)) {
|
|
8795
|
+
const limits = {};
|
|
8796
|
+
if (Number.isFinite(Number(parsed.limits.maxNoteChars))) limits.maxNoteChars = Number(parsed.limits.maxNoteChars);
|
|
8797
|
+
if (Number.isFinite(Number(parsed.limits.maxNotes))) limits.maxNotes = Number(parsed.limits.maxNotes);
|
|
8798
|
+
if (Object.keys(limits).length) config.limits = limits;
|
|
8799
|
+
} else {
|
|
8800
|
+
errors.push("limits must be an object when provided");
|
|
8801
|
+
}
|
|
8802
|
+
}
|
|
8803
|
+
return { valid: true, config, errors };
|
|
8804
|
+
}
|
|
8805
|
+
function loadRepoMeshJsonConfig(workspace) {
|
|
8806
|
+
const bases = [];
|
|
8807
|
+
const ws = typeof workspace === "string" ? workspace.trim() : "";
|
|
8808
|
+
if (ws) bases.push(ws);
|
|
8809
|
+
let cwd = "";
|
|
8810
|
+
try {
|
|
8811
|
+
cwd = process.cwd();
|
|
8812
|
+
} catch {
|
|
8813
|
+
}
|
|
8814
|
+
if (cwd && cwd !== ws) bases.push(cwd);
|
|
8815
|
+
for (const base of bases) {
|
|
8816
|
+
for (const relative5 of MESH_JSON_CONFIG_LOCATIONS) {
|
|
8817
|
+
const configPath = join15(base, relative5);
|
|
8818
|
+
if (!existsSync14(configPath)) continue;
|
|
8819
|
+
try {
|
|
8820
|
+
const parsed = parseConfigText4(configPath, readFileSync11(configPath, "utf-8"));
|
|
8821
|
+
const result = normalizeRepoMeshDeclarativeConfig(parsed);
|
|
8822
|
+
if (!result.valid || !result.config) {
|
|
8823
|
+
return { source: relative5, sourceType: "invalid", path: configPath, error: result.errors.join("; ") };
|
|
8824
|
+
}
|
|
8825
|
+
return { config: result.config, source: relative5, sourceType: "repo_file", path: configPath };
|
|
8826
|
+
} catch (error) {
|
|
8827
|
+
return { source: relative5, sourceType: "invalid", path: configPath, error: error?.message || String(error) };
|
|
8828
|
+
}
|
|
8829
|
+
}
|
|
8830
|
+
}
|
|
8831
|
+
return {
|
|
8832
|
+
source: "unavailable",
|
|
8833
|
+
sourceType: "unavailable",
|
|
8834
|
+
error: `No repo mesh config found. Checked: ${MESH_JSON_CONFIG_LOCATIONS.join(", ")}`
|
|
8835
|
+
};
|
|
8836
|
+
}
|
|
8837
|
+
function mergeEffectiveCoordinatorConfig(repoCoord, localCoord) {
|
|
8838
|
+
const out = { ...localCoord || {} };
|
|
8839
|
+
const localOverride = localCoord?.systemPromptOverride?.trim();
|
|
8840
|
+
const repoOverride = repoCoord?.systemPromptOverride?.trim();
|
|
8841
|
+
if (localOverride) {
|
|
8842
|
+
out.systemPromptOverride = localCoord.systemPromptOverride;
|
|
8843
|
+
} else if (repoOverride) {
|
|
8844
|
+
out.systemPromptOverride = repoCoord.systemPromptOverride;
|
|
8845
|
+
} else {
|
|
8846
|
+
delete out.systemPromptOverride;
|
|
8847
|
+
}
|
|
8848
|
+
const repoAppend = repoCoord?.systemPromptAppend?.trim() ? repoCoord.systemPromptAppend.trim() : "";
|
|
8849
|
+
const localAppendRaw = localCoord?.systemPromptAppend ?? localCoord?.systemPromptSuffix;
|
|
8850
|
+
const localAppend = localAppendRaw?.trim() ? localAppendRaw.trim() : "";
|
|
8851
|
+
const stacked = [repoAppend, localAppend].filter(Boolean).join("\n\n");
|
|
8852
|
+
if (stacked) {
|
|
8853
|
+
out.systemPromptAppend = stacked;
|
|
8854
|
+
delete out.systemPromptSuffix;
|
|
8855
|
+
}
|
|
8856
|
+
return out;
|
|
8857
|
+
}
|
|
8858
|
+
function mergeEffectiveOperatingNotes(repoNotes, ledgerNotes) {
|
|
8859
|
+
const usable = (notes) => Array.isArray(notes) ? notes.filter((n) => n && typeof n.text === "string" && n.text.trim()) : [];
|
|
8860
|
+
const repo = usable(repoNotes);
|
|
8861
|
+
const ledger = usable(ledgerNotes);
|
|
8862
|
+
const ledgerTexts = new Set(ledger.map((n) => n.text.trim()));
|
|
8863
|
+
const repoKept = repo.filter((n) => !ledgerTexts.has(n.text.trim()));
|
|
8864
|
+
const merged = [...repoKept, ...ledger];
|
|
8865
|
+
return merged.length ? merged : void 0;
|
|
8866
|
+
}
|
|
8867
|
+
function applyRepoMeshConfig(mesh, repoConfig) {
|
|
8868
|
+
if (!repoConfig) return mesh;
|
|
8869
|
+
return {
|
|
8870
|
+
...mesh,
|
|
8871
|
+
coordinator: mergeEffectiveCoordinatorConfig(repoConfig.coordinator, mesh.coordinator)
|
|
8872
|
+
};
|
|
8873
|
+
}
|
|
8874
|
+
function buildMeshJsonConfigScaffold(mesh) {
|
|
8875
|
+
const scaffold = { version: 1 };
|
|
8876
|
+
const coord = {};
|
|
8877
|
+
const override = mesh.coordinator?.systemPromptOverride;
|
|
8878
|
+
if (typeof override === "string" && override.trim()) coord.systemPromptOverride = override;
|
|
8879
|
+
const append = mesh.coordinator?.systemPromptAppend ?? mesh.coordinator?.systemPromptSuffix;
|
|
8880
|
+
if (typeof append === "string" && append.trim()) coord.systemPromptAppend = append;
|
|
8881
|
+
if (Object.keys(coord).length) scaffold.coordinator = coord;
|
|
8882
|
+
return scaffold;
|
|
8883
|
+
}
|
|
8884
|
+
function serializeMeshJsonConfigScaffold(config) {
|
|
8885
|
+
return JSON.stringify(config, null, 2);
|
|
8886
|
+
}
|
|
8887
|
+
var MESH_JSON_CONFIG_LOCATIONS, MESH_JSON_CONFIG_SCHEMA;
|
|
8888
|
+
var init_mesh_json_config = __esm({
|
|
8889
|
+
"src/config/mesh-json-config.ts"() {
|
|
8890
|
+
"use strict";
|
|
8891
|
+
MESH_JSON_CONFIG_LOCATIONS = [
|
|
8892
|
+
".adhdev/mesh.json",
|
|
8893
|
+
".adhdev/mesh.yaml",
|
|
8894
|
+
".adhdev/mesh.yml"
|
|
8895
|
+
];
|
|
8896
|
+
MESH_JSON_CONFIG_SCHEMA = {
|
|
8897
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
8898
|
+
title: "ADHDev Repo Mesh Declarative Config",
|
|
8899
|
+
type: "object",
|
|
8900
|
+
additionalProperties: false,
|
|
8901
|
+
required: ["version"],
|
|
8902
|
+
properties: {
|
|
8903
|
+
version: { const: 1 },
|
|
8904
|
+
coordinator: {
|
|
8905
|
+
type: "object",
|
|
8906
|
+
additionalProperties: false,
|
|
8907
|
+
properties: {
|
|
8908
|
+
systemPromptOverride: { type: "string" },
|
|
8909
|
+
systemPromptAppend: { type: "string" },
|
|
8910
|
+
maxPromptChars: { type: "number", minimum: 1 }
|
|
8911
|
+
}
|
|
8912
|
+
},
|
|
8913
|
+
operatingNotes: {
|
|
8914
|
+
type: "array",
|
|
8915
|
+
maxItems: 200,
|
|
8916
|
+
items: {
|
|
8917
|
+
type: "object",
|
|
8918
|
+
additionalProperties: false,
|
|
8919
|
+
required: ["text"],
|
|
8920
|
+
properties: {
|
|
8921
|
+
text: { type: "string", minLength: 1 },
|
|
8922
|
+
category: { enum: ["provider_quirk", "pattern_to_avoid", "recovery_lesson"] },
|
|
8923
|
+
createdAt: { type: "string" },
|
|
8924
|
+
sourceCoordinator: { type: "string" }
|
|
8925
|
+
}
|
|
8926
|
+
}
|
|
8927
|
+
},
|
|
8928
|
+
limits: {
|
|
8929
|
+
type: "object",
|
|
8930
|
+
additionalProperties: false,
|
|
8931
|
+
properties: {
|
|
8932
|
+
maxNoteChars: { type: "number", minimum: 1 },
|
|
8933
|
+
maxNotes: { type: "number", minimum: 1 }
|
|
8934
|
+
}
|
|
8935
|
+
}
|
|
8936
|
+
}
|
|
8937
|
+
};
|
|
8938
|
+
}
|
|
8939
|
+
});
|
|
8940
|
+
|
|
8680
8941
|
// src/mesh/mesh-fast-forward.ts
|
|
8681
8942
|
async function fastForwardMeshNode(args) {
|
|
8682
8943
|
const workspace = typeof args.workspace === "string" ? args.workspace.trim() : "";
|
|
@@ -10082,8 +10343,8 @@ var init_mesh_events_utils = __esm({
|
|
|
10082
10343
|
});
|
|
10083
10344
|
|
|
10084
10345
|
// src/mesh/mesh-events-pending.ts
|
|
10085
|
-
import { appendFileSync as appendFileSync2, existsSync as
|
|
10086
|
-
import { join as
|
|
10346
|
+
import { appendFileSync as appendFileSync2, existsSync as existsSync15, readFileSync as readFileSync12, renameSync as renameSync4, statSync as statSync6, unlinkSync as unlinkSync2, writeFileSync as writeFileSync6 } from "fs";
|
|
10347
|
+
import { join as join16 } from "path";
|
|
10087
10348
|
import { randomUUID as randomUUID8 } from "crypto";
|
|
10088
10349
|
function normalizeCoordinatorDaemonIds(coordinatorDaemonId) {
|
|
10089
10350
|
return expandDaemonIdForms(coordinatorDaemonId);
|
|
@@ -10147,9 +10408,9 @@ function getPendingEventsPath(meshId, coordinatorDaemonId) {
|
|
|
10147
10408
|
const safe = meshId.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
10148
10409
|
if (coordinatorDaemonId) {
|
|
10149
10410
|
const safeDaemon = coordinatorDaemonId.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
10150
|
-
return
|
|
10411
|
+
return join16(getLedgerDir(), `${safe}-${safeDaemon}.pending-events.jsonl`);
|
|
10151
10412
|
}
|
|
10152
|
-
return
|
|
10413
|
+
return join16(getLedgerDir(), `${safe}.pending-events.jsonl`);
|
|
10153
10414
|
}
|
|
10154
10415
|
function readPendingMeshCoordinatorEventsFromDisk(meshId, coordinatorDaemonId) {
|
|
10155
10416
|
if (!meshId) return [];
|
|
@@ -10158,9 +10419,9 @@ function readPendingMeshCoordinatorEventsFromDisk(meshId, coordinatorDaemonId) {
|
|
|
10158
10419
|
const paths = primaryDaemonId ? [getPendingEventsPath(meshId, primaryDaemonId), getPendingEventsPath(meshId)] : [getPendingEventsPath(meshId)];
|
|
10159
10420
|
const events = [];
|
|
10160
10421
|
for (const path43 of paths) {
|
|
10161
|
-
if (!
|
|
10422
|
+
if (!existsSync15(path43)) continue;
|
|
10162
10423
|
try {
|
|
10163
|
-
const raw =
|
|
10424
|
+
const raw = readFileSync12(path43, "utf-8");
|
|
10164
10425
|
const parsed = raw.split("\n").filter(Boolean).flatMap((line) => {
|
|
10165
10426
|
try {
|
|
10166
10427
|
return [JSON.parse(line)];
|
|
@@ -10235,9 +10496,9 @@ function reconcilePendingMeshCoordinatorEvents(meshId, events) {
|
|
|
10235
10496
|
}
|
|
10236
10497
|
function trimPendingEventsIfNeeded(path43) {
|
|
10237
10498
|
try {
|
|
10238
|
-
if (!
|
|
10499
|
+
if (!existsSync15(path43)) return;
|
|
10239
10500
|
if (statSync6(path43).size <= MAX_PENDING_EVENTS_BYTES) return;
|
|
10240
|
-
const lines =
|
|
10501
|
+
const lines = readFileSync12(path43, "utf-8").split("\n").filter(Boolean);
|
|
10241
10502
|
if (lines.length <= MAX_PENDING_EVENTS_KEEP) return;
|
|
10242
10503
|
const dropped = lines.slice(0, lines.length - MAX_PENDING_EVENTS_KEEP);
|
|
10243
10504
|
for (const line of dropped) {
|
|
@@ -10321,7 +10582,7 @@ function atomicDrainFile(path43) {
|
|
|
10321
10582
|
return null;
|
|
10322
10583
|
}
|
|
10323
10584
|
try {
|
|
10324
|
-
const content =
|
|
10585
|
+
const content = readFileSync12(tmpPath, "utf-8");
|
|
10325
10586
|
try {
|
|
10326
10587
|
unlinkSync2(tmpPath);
|
|
10327
10588
|
} catch {
|
|
@@ -10344,7 +10605,7 @@ function selectiveDrainFile(path43, predicate) {
|
|
|
10344
10605
|
}
|
|
10345
10606
|
let content;
|
|
10346
10607
|
try {
|
|
10347
|
-
content =
|
|
10608
|
+
content = readFileSync12(tmpPath, "utf-8");
|
|
10348
10609
|
} catch {
|
|
10349
10610
|
try {
|
|
10350
10611
|
unlinkSync2(tmpPath);
|
|
@@ -10375,7 +10636,7 @@ function selectiveDrainFile(path43, predicate) {
|
|
|
10375
10636
|
unlinkSync2(tmpPath);
|
|
10376
10637
|
} catch {
|
|
10377
10638
|
try {
|
|
10378
|
-
if (
|
|
10639
|
+
if (existsSync15(tmpPath) && !existsSync15(path43)) renameSync4(tmpPath, path43);
|
|
10379
10640
|
} catch {
|
|
10380
10641
|
}
|
|
10381
10642
|
return [];
|
|
@@ -10470,7 +10731,7 @@ function clearPendingMeshCoordinatorEvents(meshId, coordinatorDaemonId) {
|
|
|
10470
10731
|
}
|
|
10471
10732
|
const paths = coordinatorDaemonId ? [getPendingEventsPath(meshId, coordinatorDaemonId), getPendingEventsPath(meshId)] : [getPendingEventsPath(meshId)];
|
|
10472
10733
|
for (const path43 of paths) {
|
|
10473
|
-
if (
|
|
10734
|
+
if (existsSync15(path43)) try {
|
|
10474
10735
|
unlinkSync2(path43);
|
|
10475
10736
|
} catch {
|
|
10476
10737
|
}
|
|
@@ -11233,7 +11494,7 @@ var init_provider_cli_shared = __esm({
|
|
|
11233
11494
|
import { exec } from "child_process";
|
|
11234
11495
|
import * as os6 from "os";
|
|
11235
11496
|
import * as path12 from "path";
|
|
11236
|
-
import { existsSync as
|
|
11497
|
+
import { existsSync as existsSync16 } from "fs";
|
|
11237
11498
|
function parseVersion(raw) {
|
|
11238
11499
|
const match = raw.match(/v?(\d+\.\d+(?:\.\d+)?(?:-[a-zA-Z0-9.]+)?)/);
|
|
11239
11500
|
return match ? match[1] : raw.split("\n")[0].slice(0, 100);
|
|
@@ -11257,7 +11518,7 @@ function resolveCommandPath(command) {
|
|
|
11257
11518
|
if (isExplicitCommandPath(trimmed)) {
|
|
11258
11519
|
const expanded = expandHome(trimmed);
|
|
11259
11520
|
const candidate = path12.isAbsolute(expanded) ? expanded : path12.resolve(expanded);
|
|
11260
|
-
return
|
|
11521
|
+
return existsSync16(candidate) ? candidate : null;
|
|
11261
11522
|
}
|
|
11262
11523
|
return null;
|
|
11263
11524
|
}
|
|
@@ -11267,7 +11528,7 @@ async function resolveDetectionPath(command, whichCmd) {
|
|
|
11267
11528
|
const whichResult = await execAsync(`${whichCmd} ${shellQuote(command)}`);
|
|
11268
11529
|
if (whichResult) return whichResult.split("\n")[0];
|
|
11269
11530
|
const resolved = findBinary(command);
|
|
11270
|
-
if (path12.isAbsolute(resolved) &&
|
|
11531
|
+
if (path12.isAbsolute(resolved) && existsSync16(resolved)) return resolved;
|
|
11271
11532
|
return null;
|
|
11272
11533
|
}
|
|
11273
11534
|
function execAsync(cmd, timeoutMs = 5e3) {
|
|
@@ -11485,345 +11746,6 @@ var init_mesh_warmup_deadline = __esm({
|
|
|
11485
11746
|
}
|
|
11486
11747
|
});
|
|
11487
11748
|
|
|
11488
|
-
// src/config/mesh-json-config.ts
|
|
11489
|
-
var mesh_json_config_exports = {};
|
|
11490
|
-
__export(mesh_json_config_exports, {
|
|
11491
|
-
MESH_JSON_CONFIG_LOCATIONS: () => MESH_JSON_CONFIG_LOCATIONS,
|
|
11492
|
-
MESH_JSON_CONFIG_SCHEMA: () => MESH_JSON_CONFIG_SCHEMA,
|
|
11493
|
-
__resetMeshJsonConfigCacheForTests: () => __resetMeshJsonConfigCacheForTests,
|
|
11494
|
-
applyRepoMeshConfig: () => applyRepoMeshConfig,
|
|
11495
|
-
buildMeshJsonConfigScaffold: () => buildMeshJsonConfigScaffold,
|
|
11496
|
-
diffPolicyFromDefault: () => diffPolicyFromDefault,
|
|
11497
|
-
loadMeshJsonConfig: () => loadMeshJsonConfig,
|
|
11498
|
-
loadRepoMeshJsonConfig: () => loadRepoMeshJsonConfig,
|
|
11499
|
-
mergeEffectiveCoordinatorConfig: () => mergeEffectiveCoordinatorConfig,
|
|
11500
|
-
mergeEffectiveMeshPolicy: () => mergeEffectiveMeshPolicy,
|
|
11501
|
-
mergeEffectiveOperatingNotes: () => mergeEffectiveOperatingNotes,
|
|
11502
|
-
normalizeRepoMeshDeclarativeConfig: () => normalizeRepoMeshDeclarativeConfig,
|
|
11503
|
-
serializeMeshJsonConfigScaffold: () => serializeMeshJsonConfigScaffold,
|
|
11504
|
-
validateMeshJsonConfig: () => validateMeshJsonConfig
|
|
11505
|
-
});
|
|
11506
|
-
import { existsSync as existsSync16, readFileSync as readFileSync12, statSync as statSync7 } from "fs";
|
|
11507
|
-
import { join as join18 } from "path";
|
|
11508
|
-
import * as yaml4 from "js-yaml";
|
|
11509
|
-
function isRecord3(value) {
|
|
11510
|
-
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
11511
|
-
}
|
|
11512
|
-
function parseConfigText4(path43, text) {
|
|
11513
|
-
if (/\.json$/i.test(path43)) return JSON.parse(text);
|
|
11514
|
-
return yaml4.load(text);
|
|
11515
|
-
}
|
|
11516
|
-
function normalizeOperatingNote(value) {
|
|
11517
|
-
if (!isRecord3(value)) return null;
|
|
11518
|
-
const text = typeof value.text === "string" ? value.text.trim() : "";
|
|
11519
|
-
if (!text) return null;
|
|
11520
|
-
const category = value.category === "provider_quirk" || value.category === "pattern_to_avoid" || value.category === "recovery_lesson" ? value.category : void 0;
|
|
11521
|
-
return {
|
|
11522
|
-
text,
|
|
11523
|
-
...category ? { category } : {},
|
|
11524
|
-
...typeof value.createdAt === "string" ? { createdAt: value.createdAt } : {},
|
|
11525
|
-
...typeof value.sourceCoordinator === "string" ? { sourceCoordinator: value.sourceCoordinator } : {}
|
|
11526
|
-
};
|
|
11527
|
-
}
|
|
11528
|
-
function normalizeRepoMeshDeclarativeConfig(parsed) {
|
|
11529
|
-
const errors = [];
|
|
11530
|
-
if (!isRecord3(parsed)) return { valid: false, errors: ["config must be an object"] };
|
|
11531
|
-
if (parsed.version !== 1) {
|
|
11532
|
-
return { valid: false, errors: [`version must be 1 (got ${JSON.stringify(parsed.version)})`] };
|
|
11533
|
-
}
|
|
11534
|
-
const config = { version: 1 };
|
|
11535
|
-
if (parsed.policy !== void 0) {
|
|
11536
|
-
if (isRecord3(parsed.policy)) {
|
|
11537
|
-
config.policy = parsed.policy;
|
|
11538
|
-
} else {
|
|
11539
|
-
errors.push("policy must be an object when provided");
|
|
11540
|
-
}
|
|
11541
|
-
}
|
|
11542
|
-
if (parsed.coordinator !== void 0) {
|
|
11543
|
-
if (isRecord3(parsed.coordinator)) {
|
|
11544
|
-
const coord = {};
|
|
11545
|
-
const c = parsed.coordinator;
|
|
11546
|
-
if (typeof c.systemPromptOverride === "string") coord.systemPromptOverride = c.systemPromptOverride;
|
|
11547
|
-
if (typeof c.systemPromptAppend === "string") coord.systemPromptAppend = c.systemPromptAppend;
|
|
11548
|
-
if (Number.isFinite(Number(c.maxPromptChars))) coord.maxPromptChars = Number(c.maxPromptChars);
|
|
11549
|
-
config.coordinator = coord;
|
|
11550
|
-
} else {
|
|
11551
|
-
errors.push("coordinator must be an object when provided");
|
|
11552
|
-
}
|
|
11553
|
-
}
|
|
11554
|
-
if (parsed.operatingNotes !== void 0) {
|
|
11555
|
-
if (Array.isArray(parsed.operatingNotes)) {
|
|
11556
|
-
const notes = parsed.operatingNotes.map(normalizeOperatingNote).filter((n) => n !== null);
|
|
11557
|
-
if (notes.length) config.operatingNotes = notes;
|
|
11558
|
-
} else {
|
|
11559
|
-
errors.push("operatingNotes must be an array when provided");
|
|
11560
|
-
}
|
|
11561
|
-
}
|
|
11562
|
-
if (parsed.limits !== void 0) {
|
|
11563
|
-
if (isRecord3(parsed.limits)) {
|
|
11564
|
-
const limits = {};
|
|
11565
|
-
if (Number.isFinite(Number(parsed.limits.maxNoteChars))) limits.maxNoteChars = Number(parsed.limits.maxNoteChars);
|
|
11566
|
-
if (Number.isFinite(Number(parsed.limits.maxNotes))) limits.maxNotes = Number(parsed.limits.maxNotes);
|
|
11567
|
-
if (Object.keys(limits).length) config.limits = limits;
|
|
11568
|
-
} else {
|
|
11569
|
-
errors.push("limits must be an object when provided");
|
|
11570
|
-
}
|
|
11571
|
-
}
|
|
11572
|
-
return { valid: true, config, errors };
|
|
11573
|
-
}
|
|
11574
|
-
function loadRepoMeshJsonConfig(workspace) {
|
|
11575
|
-
const bases = [];
|
|
11576
|
-
const ws = typeof workspace === "string" ? workspace.trim() : "";
|
|
11577
|
-
if (ws) bases.push(ws);
|
|
11578
|
-
let cwd = "";
|
|
11579
|
-
try {
|
|
11580
|
-
cwd = process.cwd();
|
|
11581
|
-
} catch {
|
|
11582
|
-
}
|
|
11583
|
-
if (cwd && cwd !== ws) bases.push(cwd);
|
|
11584
|
-
for (const base of bases) {
|
|
11585
|
-
for (const relative5 of MESH_JSON_CONFIG_LOCATIONS) {
|
|
11586
|
-
const configPath = join18(base, relative5);
|
|
11587
|
-
if (!existsSync16(configPath)) continue;
|
|
11588
|
-
try {
|
|
11589
|
-
const parsed = parseConfigText4(configPath, readFileSync12(configPath, "utf-8"));
|
|
11590
|
-
const result = normalizeRepoMeshDeclarativeConfig(parsed);
|
|
11591
|
-
if (!result.valid || !result.config) {
|
|
11592
|
-
return { source: relative5, sourceType: "invalid", path: configPath, error: result.errors.join("; ") };
|
|
11593
|
-
}
|
|
11594
|
-
return { config: result.config, source: relative5, sourceType: "repo_file", path: configPath };
|
|
11595
|
-
} catch (error) {
|
|
11596
|
-
return { source: relative5, sourceType: "invalid", path: configPath, error: error?.message || String(error) };
|
|
11597
|
-
}
|
|
11598
|
-
}
|
|
11599
|
-
}
|
|
11600
|
-
return {
|
|
11601
|
-
source: "unavailable",
|
|
11602
|
-
sourceType: "unavailable",
|
|
11603
|
-
error: `No repo mesh config found. Checked: ${MESH_JSON_CONFIG_LOCATIONS.join(", ")}`
|
|
11604
|
-
};
|
|
11605
|
-
}
|
|
11606
|
-
function deepEqual(a, b) {
|
|
11607
|
-
if (a === b) return true;
|
|
11608
|
-
try {
|
|
11609
|
-
return JSON.stringify(a) === JSON.stringify(b);
|
|
11610
|
-
} catch {
|
|
11611
|
-
return false;
|
|
11612
|
-
}
|
|
11613
|
-
}
|
|
11614
|
-
function diffPolicyFromDefault(local) {
|
|
11615
|
-
if (!local || typeof local !== "object") return {};
|
|
11616
|
-
const out = {};
|
|
11617
|
-
const def = mergeAndNormalizePolicy(void 0, void 0);
|
|
11618
|
-
for (const [key, value] of Object.entries(local)) {
|
|
11619
|
-
if (value === void 0) continue;
|
|
11620
|
-
if (!deepEqual(value, def[key])) out[key] = value;
|
|
11621
|
-
}
|
|
11622
|
-
return out;
|
|
11623
|
-
}
|
|
11624
|
-
function mergeEffectiveMeshPolicy(repoPolicy, localPolicy) {
|
|
11625
|
-
const repoMerged = mergeAndNormalizePolicy(void 0, repoPolicy);
|
|
11626
|
-
const localOverrides = diffPolicyFromDefault(localPolicy);
|
|
11627
|
-
return mergeAndNormalizePolicy(repoMerged, localOverrides);
|
|
11628
|
-
}
|
|
11629
|
-
function mergeEffectiveCoordinatorConfig(repoCoord, localCoord) {
|
|
11630
|
-
const out = { ...localCoord || {} };
|
|
11631
|
-
const localOverride = localCoord?.systemPromptOverride?.trim();
|
|
11632
|
-
const repoOverride = repoCoord?.systemPromptOverride?.trim();
|
|
11633
|
-
if (localOverride) {
|
|
11634
|
-
out.systemPromptOverride = localCoord.systemPromptOverride;
|
|
11635
|
-
} else if (repoOverride) {
|
|
11636
|
-
out.systemPromptOverride = repoCoord.systemPromptOverride;
|
|
11637
|
-
} else {
|
|
11638
|
-
delete out.systemPromptOverride;
|
|
11639
|
-
}
|
|
11640
|
-
const repoAppend = repoCoord?.systemPromptAppend?.trim() ? repoCoord.systemPromptAppend.trim() : "";
|
|
11641
|
-
const localAppendRaw = localCoord?.systemPromptAppend ?? localCoord?.systemPromptSuffix;
|
|
11642
|
-
const localAppend = localAppendRaw?.trim() ? localAppendRaw.trim() : "";
|
|
11643
|
-
const stacked = [repoAppend, localAppend].filter(Boolean).join("\n\n");
|
|
11644
|
-
if (stacked) {
|
|
11645
|
-
out.systemPromptAppend = stacked;
|
|
11646
|
-
delete out.systemPromptSuffix;
|
|
11647
|
-
}
|
|
11648
|
-
return out;
|
|
11649
|
-
}
|
|
11650
|
-
function mergeEffectiveOperatingNotes(repoNotes, ledgerNotes) {
|
|
11651
|
-
const usable = (notes) => Array.isArray(notes) ? notes.filter((n) => n && typeof n.text === "string" && n.text.trim()) : [];
|
|
11652
|
-
const repo = usable(repoNotes);
|
|
11653
|
-
const ledger = usable(ledgerNotes);
|
|
11654
|
-
const ledgerTexts = new Set(ledger.map((n) => n.text.trim()));
|
|
11655
|
-
const repoKept = repo.filter((n) => !ledgerTexts.has(n.text.trim()));
|
|
11656
|
-
const merged = [...repoKept, ...ledger];
|
|
11657
|
-
return merged.length ? merged : void 0;
|
|
11658
|
-
}
|
|
11659
|
-
function applyRepoMeshConfig(mesh, repoConfig) {
|
|
11660
|
-
if (!repoConfig) return mesh;
|
|
11661
|
-
return {
|
|
11662
|
-
...mesh,
|
|
11663
|
-
policy: mergeEffectiveMeshPolicy(repoConfig.policy, mesh.policy),
|
|
11664
|
-
coordinator: mergeEffectiveCoordinatorConfig(repoConfig.coordinator, mesh.coordinator)
|
|
11665
|
-
};
|
|
11666
|
-
}
|
|
11667
|
-
function buildMeshJsonConfigScaffold(mesh) {
|
|
11668
|
-
const scaffold = {
|
|
11669
|
-
version: 1,
|
|
11670
|
-
policy: mergeAndNormalizePolicy(void 0, mesh.policy)
|
|
11671
|
-
};
|
|
11672
|
-
const coord = {};
|
|
11673
|
-
const override = mesh.coordinator?.systemPromptOverride;
|
|
11674
|
-
if (typeof override === "string" && override.trim()) coord.systemPromptOverride = override;
|
|
11675
|
-
const append = mesh.coordinator?.systemPromptAppend ?? mesh.coordinator?.systemPromptSuffix;
|
|
11676
|
-
if (typeof append === "string" && append.trim()) coord.systemPromptAppend = append;
|
|
11677
|
-
if (Object.keys(coord).length) scaffold.coordinator = coord;
|
|
11678
|
-
return scaffold;
|
|
11679
|
-
}
|
|
11680
|
-
function serializeMeshJsonConfigScaffold(config) {
|
|
11681
|
-
return JSON.stringify(config, null, 2);
|
|
11682
|
-
}
|
|
11683
|
-
function validateMeshJsonConfig(raw, source = "inline") {
|
|
11684
|
-
const errors = [];
|
|
11685
|
-
if (!isRecord3(raw)) {
|
|
11686
|
-
return { valid: false, errors: [`${source}: config must be an object`] };
|
|
11687
|
-
}
|
|
11688
|
-
const config = {};
|
|
11689
|
-
const policy = raw.policy;
|
|
11690
|
-
const schedulingRaw = isRecord3(policy) ? policy.scheduling : void 0;
|
|
11691
|
-
if (schedulingRaw !== void 0) {
|
|
11692
|
-
if (!isRecord3(schedulingRaw)) {
|
|
11693
|
-
errors.push("policy.scheduling must be an object");
|
|
11694
|
-
} else {
|
|
11695
|
-
const scheduling = {};
|
|
11696
|
-
if (schedulingRaw.distribution !== void 0) {
|
|
11697
|
-
if (typeof schedulingRaw.distribution !== "string" || !["spread", "in_order"].includes(schedulingRaw.distribution.trim())) {
|
|
11698
|
-
errors.push("policy.scheduling.distribution must be 'spread' or 'in_order'");
|
|
11699
|
-
} else {
|
|
11700
|
-
scheduling.distribution = normalizeMeshDistribution(schedulingRaw.distribution);
|
|
11701
|
-
}
|
|
11702
|
-
}
|
|
11703
|
-
if (schedulingRaw.maxParallel !== void 0) {
|
|
11704
|
-
const n = Number(schedulingRaw.maxParallel);
|
|
11705
|
-
if (!Number.isFinite(n) || n < MESH_MAX_PARALLEL_TASKS_MIN || n > MESH_MAX_PARALLEL_TASKS_MAX) {
|
|
11706
|
-
errors.push(`policy.scheduling.maxParallel must be a number in [${MESH_MAX_PARALLEL_TASKS_MIN}, ${MESH_MAX_PARALLEL_TASKS_MAX}]`);
|
|
11707
|
-
} else {
|
|
11708
|
-
scheduling.maxParallel = Math.floor(n);
|
|
11709
|
-
}
|
|
11710
|
-
}
|
|
11711
|
-
if (schedulingRaw.readonlyMultiplier !== void 0) {
|
|
11712
|
-
const n = Number(schedulingRaw.readonlyMultiplier);
|
|
11713
|
-
if (!Number.isFinite(n) || n < 1) {
|
|
11714
|
-
errors.push("policy.scheduling.readonlyMultiplier must be a number >= 1");
|
|
11715
|
-
} else {
|
|
11716
|
-
scheduling.readonlyMultiplier = Math.floor(n);
|
|
11717
|
-
}
|
|
11718
|
-
}
|
|
11719
|
-
for (const key of Object.keys(schedulingRaw)) {
|
|
11720
|
-
if (!["distribution", "maxParallel", "readonlyMultiplier"].includes(key)) {
|
|
11721
|
-
errors.push(`policy.scheduling.${key} is not a recognized field`);
|
|
11722
|
-
}
|
|
11723
|
-
}
|
|
11724
|
-
if (Object.keys(scheduling).length) config.scheduling = scheduling;
|
|
11725
|
-
}
|
|
11726
|
-
}
|
|
11727
|
-
return { valid: errors.length === 0, errors, config: errors.length === 0 ? config : void 0 };
|
|
11728
|
-
}
|
|
11729
|
-
function loadMeshJsonConfig(repoRoot) {
|
|
11730
|
-
if (!repoRoot) {
|
|
11731
|
-
return { source: "unavailable", sourceType: "unavailable", error: "no repo root", sourceKey: "unavailable" };
|
|
11732
|
-
}
|
|
11733
|
-
for (const relative5 of MESH_JSON_CONFIG_LOCATIONS) {
|
|
11734
|
-
const configPath = join18(repoRoot, relative5);
|
|
11735
|
-
if (!existsSync16(configPath)) continue;
|
|
11736
|
-
let mtimeMs = 0;
|
|
11737
|
-
try {
|
|
11738
|
-
mtimeMs = statSync7(configPath).mtimeMs;
|
|
11739
|
-
} catch {
|
|
11740
|
-
mtimeMs = 0;
|
|
11741
|
-
}
|
|
11742
|
-
const cacheKey = configPath;
|
|
11743
|
-
const sourceKey = `file:${configPath}:${mtimeMs}`;
|
|
11744
|
-
const cached3 = cache.get(cacheKey);
|
|
11745
|
-
if (cached3 && cached3.sourceKey === sourceKey) return cached3.result;
|
|
11746
|
-
let result;
|
|
11747
|
-
try {
|
|
11748
|
-
const text = readFileSync12(configPath, "utf-8");
|
|
11749
|
-
const parsed = parseConfigText4(configPath, text);
|
|
11750
|
-
const validation = validateMeshJsonConfig(parsed, relative5);
|
|
11751
|
-
result = validation.valid ? { config: validation.config, source: relative5, sourceType: "repo_file", path: configPath, sourceKey } : { source: relative5, sourceType: "invalid", path: configPath, error: validation.errors.join("; "), sourceKey: `invalid:${configPath}:${mtimeMs}` };
|
|
11752
|
-
} catch (error) {
|
|
11753
|
-
result = { source: relative5, sourceType: "invalid", path: configPath, error: error?.message || String(error), sourceKey: `error:${configPath}` };
|
|
11754
|
-
}
|
|
11755
|
-
cache.set(cacheKey, { sourceKey: result.sourceKey, result });
|
|
11756
|
-
return result;
|
|
11757
|
-
}
|
|
11758
|
-
return {
|
|
11759
|
-
source: "unavailable",
|
|
11760
|
-
sourceType: "unavailable",
|
|
11761
|
-
error: `No .adhdev/mesh config found. Checked: ${MESH_JSON_CONFIG_LOCATIONS.join(", ")}`,
|
|
11762
|
-
sourceKey: "unavailable"
|
|
11763
|
-
};
|
|
11764
|
-
}
|
|
11765
|
-
function __resetMeshJsonConfigCacheForTests() {
|
|
11766
|
-
cache.clear();
|
|
11767
|
-
}
|
|
11768
|
-
var MESH_JSON_CONFIG_LOCATIONS, MESH_JSON_CONFIG_SCHEMA, cache;
|
|
11769
|
-
var init_mesh_json_config = __esm({
|
|
11770
|
-
"src/config/mesh-json-config.ts"() {
|
|
11771
|
-
"use strict";
|
|
11772
|
-
init_repo_mesh_types();
|
|
11773
|
-
MESH_JSON_CONFIG_LOCATIONS = [
|
|
11774
|
-
".adhdev/mesh.json",
|
|
11775
|
-
".adhdev/mesh.yaml",
|
|
11776
|
-
".adhdev/mesh.yml"
|
|
11777
|
-
];
|
|
11778
|
-
MESH_JSON_CONFIG_SCHEMA = {
|
|
11779
|
-
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
11780
|
-
title: "ADHDev Repo Mesh Declarative Config",
|
|
11781
|
-
type: "object",
|
|
11782
|
-
additionalProperties: false,
|
|
11783
|
-
required: ["version"],
|
|
11784
|
-
properties: {
|
|
11785
|
-
version: { const: 1 },
|
|
11786
|
-
// policy is validated/normalized through mergeAndNormalizePolicy at merge
|
|
11787
|
-
// time; the schema here only asserts it is an object.
|
|
11788
|
-
policy: { type: "object" },
|
|
11789
|
-
coordinator: {
|
|
11790
|
-
type: "object",
|
|
11791
|
-
additionalProperties: false,
|
|
11792
|
-
properties: {
|
|
11793
|
-
systemPromptOverride: { type: "string" },
|
|
11794
|
-
systemPromptAppend: { type: "string" },
|
|
11795
|
-
maxPromptChars: { type: "number", minimum: 1 }
|
|
11796
|
-
}
|
|
11797
|
-
},
|
|
11798
|
-
operatingNotes: {
|
|
11799
|
-
type: "array",
|
|
11800
|
-
maxItems: 200,
|
|
11801
|
-
items: {
|
|
11802
|
-
type: "object",
|
|
11803
|
-
additionalProperties: false,
|
|
11804
|
-
required: ["text"],
|
|
11805
|
-
properties: {
|
|
11806
|
-
text: { type: "string", minLength: 1 },
|
|
11807
|
-
category: { enum: ["provider_quirk", "pattern_to_avoid", "recovery_lesson"] },
|
|
11808
|
-
createdAt: { type: "string" },
|
|
11809
|
-
sourceCoordinator: { type: "string" }
|
|
11810
|
-
}
|
|
11811
|
-
}
|
|
11812
|
-
},
|
|
11813
|
-
limits: {
|
|
11814
|
-
type: "object",
|
|
11815
|
-
additionalProperties: false,
|
|
11816
|
-
properties: {
|
|
11817
|
-
maxNoteChars: { type: "number", minimum: 1 },
|
|
11818
|
-
maxNotes: { type: "number", minimum: 1 }
|
|
11819
|
-
}
|
|
11820
|
-
}
|
|
11821
|
-
}
|
|
11822
|
-
};
|
|
11823
|
-
cache = /* @__PURE__ */ new Map();
|
|
11824
|
-
}
|
|
11825
|
-
});
|
|
11826
|
-
|
|
11827
11749
|
// src/mesh/mesh-queue-assignment.ts
|
|
11828
11750
|
import { existsSync as existsSync17 } from "fs";
|
|
11829
11751
|
function __resetIdleAutoFastForwardForTests() {
|
|
@@ -12240,26 +12162,7 @@ function nodeHasActiveAssignment(meshId, nodeId) {
|
|
|
12240
12162
|
function nodeActiveLoad(meshId, nodeId) {
|
|
12241
12163
|
return MeshRuntimeStore.getInstance().nodeActiveAssignmentCount(meshId, nodeId);
|
|
12242
12164
|
}
|
|
12243
|
-
function resolveMeshRepoRootForScheduling(mesh) {
|
|
12244
|
-
const nodes = Array.isArray(mesh?.nodes) ? mesh.nodes : [];
|
|
12245
|
-
const pickRoot = (n) => readNonEmptyString2(n?.repoRoot) || readNonEmptyString2(n?.workspace);
|
|
12246
|
-
const base = nodes.find((n) => n?.isLocalWorktree !== true && pickRoot(n));
|
|
12247
|
-
if (base) return pickRoot(base);
|
|
12248
|
-
const anyNode = nodes.find((n) => pickRoot(n));
|
|
12249
|
-
return anyNode ? pickRoot(anyNode) : "";
|
|
12250
|
-
}
|
|
12251
|
-
function resolveMeshSchedulingOverride(mesh) {
|
|
12252
|
-
const repoRoot = resolveMeshRepoRootForScheduling(mesh);
|
|
12253
|
-
if (!repoRoot) return void 0;
|
|
12254
|
-
try {
|
|
12255
|
-
return loadMeshJsonConfig(repoRoot).config?.scheduling;
|
|
12256
|
-
} catch {
|
|
12257
|
-
return void 0;
|
|
12258
|
-
}
|
|
12259
|
-
}
|
|
12260
12165
|
function resolveSchedulingStrategy(mesh) {
|
|
12261
|
-
const override = resolveMeshSchedulingOverride(mesh);
|
|
12262
|
-
if (override?.distribution) return distributionToStrategy(override.distribution);
|
|
12263
12166
|
return normalizeMeshSchedulingStrategy(mesh?.policy?.schedulingStrategy);
|
|
12264
12167
|
}
|
|
12265
12168
|
function orderEligibleNodes(meshId, strategy, nodes, opts) {
|
|
@@ -12402,11 +12305,8 @@ async function maybeAutoLaunchOneQueueSession(components, meshId, mesh) {
|
|
|
12402
12305
|
const queue = getQueue(meshId);
|
|
12403
12306
|
const pending = queue.filter((task) => task.status === "pending");
|
|
12404
12307
|
if (!pending.length) return false;
|
|
12405
|
-
const
|
|
12406
|
-
const
|
|
12407
|
-
schedulingOverride?.maxParallel ?? mesh?.policy?.maxParallelTasks
|
|
12408
|
-
);
|
|
12409
|
-
const maxReadonlyParallelTasks = resolveMaxReadonlyParallelTasks(maxParallelTasks, schedulingOverride?.readonlyMultiplier);
|
|
12308
|
+
const maxParallelTasks = resolveMaxParallelTasks(mesh?.policy?.maxParallelTasks);
|
|
12309
|
+
const maxReadonlyParallelTasks = resolveMaxReadonlyParallelTasks(maxParallelTasks);
|
|
12410
12310
|
for (const task of pending) {
|
|
12411
12311
|
const isReadonly = isTaskReadonly(task);
|
|
12412
12312
|
if (isReadonly) {
|
|
@@ -12819,7 +12719,6 @@ var init_mesh_queue_assignment = __esm({
|
|
|
12819
12719
|
init_mesh_event_trace();
|
|
12820
12720
|
init_mesh_warmup_deadline();
|
|
12821
12721
|
init_repo_mesh_types();
|
|
12822
|
-
init_mesh_json_config();
|
|
12823
12722
|
init_dist();
|
|
12824
12723
|
init_mesh_events_stale();
|
|
12825
12724
|
init_mesh_events_utils();
|
|
@@ -15035,11 +14934,11 @@ function buildRecentReadDebugSignature(snapshot) {
|
|
|
15035
14934
|
String(snapshot.messageUpdatedAt)
|
|
15036
14935
|
].join("|");
|
|
15037
14936
|
}
|
|
15038
|
-
function shouldEmitRecentReadDebugLog(
|
|
14937
|
+
function shouldEmitRecentReadDebugLog(cache, snapshot) {
|
|
15039
14938
|
const nextSignature = buildRecentReadDebugSignature(snapshot);
|
|
15040
|
-
const previousSignature =
|
|
14939
|
+
const previousSignature = cache.get(snapshot.sessionId);
|
|
15041
14940
|
if (previousSignature === nextSignature) return false;
|
|
15042
|
-
|
|
14941
|
+
cache.set(snapshot.sessionId, nextSignature);
|
|
15043
14942
|
return true;
|
|
15044
14943
|
}
|
|
15045
14944
|
function buildDetectedIdeInfos(detectedIdes, cdpManagers) {
|
|
@@ -24252,6 +24151,29 @@ init_mesh_review_inbox();
|
|
|
24252
24151
|
init_coordinator_registry();
|
|
24253
24152
|
init_refine_config();
|
|
24254
24153
|
init_worktree_bootstrap_config();
|
|
24154
|
+
|
|
24155
|
+
// src/config/repo-settings.ts
|
|
24156
|
+
init_mesh_json_config();
|
|
24157
|
+
init_refine_config();
|
|
24158
|
+
init_worktree_bootstrap_config();
|
|
24159
|
+
init_change_impact_config();
|
|
24160
|
+
function loadRepoSettings(opts) {
|
|
24161
|
+
const workspace = typeof opts.workspace === "string" ? opts.workspace : "";
|
|
24162
|
+
const mesh = opts.mesh;
|
|
24163
|
+
const repoRoot = typeof opts.repoRoot === "string" && opts.repoRoot ? opts.repoRoot : workspace;
|
|
24164
|
+
const meshJson = loadRepoMeshJsonConfig(workspace);
|
|
24165
|
+
return {
|
|
24166
|
+
coordinator: meshJson.config?.coordinator,
|
|
24167
|
+
operatingNotes: meshJson.config?.operatingNotes,
|
|
24168
|
+
limits: meshJson.config?.limits,
|
|
24169
|
+
meshJson,
|
|
24170
|
+
refine: loadMeshRefineConfig(mesh, workspace),
|
|
24171
|
+
worktreeBootstrap: loadMeshWorktreeBootstrapConfig(mesh, workspace),
|
|
24172
|
+
changeImpact: loadChangeImpactConfig(repoRoot)
|
|
24173
|
+
};
|
|
24174
|
+
}
|
|
24175
|
+
|
|
24176
|
+
// src/index.ts
|
|
24255
24177
|
init_mesh_ledger();
|
|
24256
24178
|
init_mesh_fast_forward();
|
|
24257
24179
|
|
|
@@ -24438,7 +24360,7 @@ init_state_store();
|
|
|
24438
24360
|
// src/detection/ide-detector.ts
|
|
24439
24361
|
import { exec as exec3 } from "child_process";
|
|
24440
24362
|
import { promisify as promisify5 } from "util";
|
|
24441
|
-
import { existsSync as existsSync20, statSync as
|
|
24363
|
+
import { existsSync as existsSync20, statSync as statSync8 } from "fs";
|
|
24442
24364
|
import { platform as platform5, homedir as homedir8 } from "os";
|
|
24443
24365
|
import * as path14 from "path";
|
|
24444
24366
|
|
|
@@ -24530,7 +24452,7 @@ function findCliCommand(command) {
|
|
|
24530
24452
|
const fullPath = path14.join(p, trimmed + ext);
|
|
24531
24453
|
try {
|
|
24532
24454
|
if (existsSync20(fullPath)) {
|
|
24533
|
-
const stat2 =
|
|
24455
|
+
const stat2 = statSync8(fullPath);
|
|
24534
24456
|
if (stat2.isFile() && (isWin || stat2.mode & 73)) {
|
|
24535
24457
|
return fullPath;
|
|
24536
24458
|
}
|
|
@@ -48283,6 +48205,21 @@ init_mesh_host_ownership();
|
|
|
48283
48205
|
init_worktree_bootstrap_config();
|
|
48284
48206
|
init_mesh_events();
|
|
48285
48207
|
init_config();
|
|
48208
|
+
async function decideOssCloneSync(ossCtx, worktreeOssSha, sourceSha, rg) {
|
|
48209
|
+
if (!worktreeOssSha || !sourceSha || worktreeOssSha === sourceSha) return "noop";
|
|
48210
|
+
const isAncestor = async (ancestor, descendant) => {
|
|
48211
|
+
try {
|
|
48212
|
+
await rg(ossCtx, ["merge-base", "--is-ancestor", ancestor, descendant], { timeoutMs: 1e4 });
|
|
48213
|
+
return true;
|
|
48214
|
+
} catch (err) {
|
|
48215
|
+
if (err?.exitCode === 1 || err?.code === 1) return false;
|
|
48216
|
+
throw err;
|
|
48217
|
+
}
|
|
48218
|
+
};
|
|
48219
|
+
if (await isAncestor(sourceSha, worktreeOssSha)) return "skip_rewind";
|
|
48220
|
+
if (await isAncestor(worktreeOssSha, sourceSha)) return "advance";
|
|
48221
|
+
return "skip_diverged";
|
|
48222
|
+
}
|
|
48286
48223
|
var meshCrudHandlers = {
|
|
48287
48224
|
list_meshes: async (_ctx, _args) => {
|
|
48288
48225
|
try {
|
|
@@ -48373,7 +48310,8 @@ var meshCrudHandlers = {
|
|
|
48373
48310
|
// entry. This is an export scaffold for the operator to review and commit to
|
|
48374
48311
|
// the repo, NOT an automatic data migration: nothing is written to disk and
|
|
48375
48312
|
// meshes.json is untouched. The returned `scaffold` (object) + `scaffoldJson`
|
|
48376
|
-
// (2-space text) capture the
|
|
48313
|
+
// (2-space text) capture the coordinator prompt override/append (policy is
|
|
48314
|
+
// machine-local and is intentionally NOT exported into mesh.json).
|
|
48377
48315
|
export_mesh_json_config: async (_ctx, args) => {
|
|
48378
48316
|
const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
|
|
48379
48317
|
if (!meshId) return { success: false, error: "meshId required" };
|
|
@@ -48744,7 +48682,7 @@ var meshCrudHandlers = {
|
|
|
48744
48682
|
}
|
|
48745
48683
|
};
|
|
48746
48684
|
const initSubmodules = sourceNode.policy?.initSubmodulesOnClone !== false;
|
|
48747
|
-
const loadedBootstrap =
|
|
48685
|
+
const loadedBootstrap = loadRepoSettings({ workspace: result.worktreePath, mesh }).worktreeBootstrap;
|
|
48748
48686
|
const runningBootstrapState = {
|
|
48749
48687
|
status: "running",
|
|
48750
48688
|
required: loadedBootstrap.config?.required !== false,
|
|
@@ -48778,12 +48716,25 @@ var meshCrudHandlers = {
|
|
|
48778
48716
|
const ossCtx = { workspace: `${result.worktreePath}/oss`, repoRoot: `${result.worktreePath}/oss`, isGitRepo: true };
|
|
48779
48717
|
const worktreeOssHeadOut = await rg(ossCtx, ["rev-parse", "HEAD"], { timeoutMs: 1e4 });
|
|
48780
48718
|
const worktreeOssSha = (typeof worktreeOssHeadOut === "string" ? worktreeOssHeadOut : worktreeOssHeadOut?.stdout ?? "").trim();
|
|
48781
|
-
if (worktreeOssSha !== sourceSha) {
|
|
48719
|
+
if (worktreeOssSha && worktreeOssSha !== sourceSha) {
|
|
48782
48720
|
await rg(ossCtx, ["fetch", `${sourceWorkspace}/oss`, "HEAD"], { timeoutMs: 6e4 });
|
|
48783
|
-
|
|
48784
|
-
|
|
48785
|
-
|
|
48786
|
-
|
|
48721
|
+
let ossAction;
|
|
48722
|
+
try {
|
|
48723
|
+
ossAction = await decideOssCloneSync(ossCtx, worktreeOssSha, sourceSha, rg);
|
|
48724
|
+
} catch (decideErr) {
|
|
48725
|
+
ossAction = "skip_diverged";
|
|
48726
|
+
console.warn(`[mesh] oss submodule sync guard could not resolve ancestry (kept fresh worktree HEAD): ${decideErr?.message ?? decideErr}`);
|
|
48727
|
+
}
|
|
48728
|
+
if (ossAction === "advance") {
|
|
48729
|
+
await rg(ossCtx, ["checkout", sourceSha], { timeoutMs: 1e4 });
|
|
48730
|
+
await rg(worktreeCtx, ["add", "oss"], { timeoutMs: 1e4 });
|
|
48731
|
+
await rg(worktreeCtx, ["commit", "-m", "chore: sync oss to source node HEAD on clone"], { timeoutMs: 1e4 });
|
|
48732
|
+
console.log(`[mesh] Advanced oss submodule to newer source HEAD ${sourceSha.slice(0, 8)} in worktree`);
|
|
48733
|
+
} else if (ossAction === "skip_rewind") {
|
|
48734
|
+
console.warn(`[mesh] Skipped oss submodule rewind on clone: source node oss ${sourceSha.slice(0, 8)} is an ancestor of the fresh worktree oss ${worktreeOssSha.slice(0, 8)} \u2014 kept fresher worktree HEAD`);
|
|
48735
|
+
} else if (ossAction === "skip_diverged") {
|
|
48736
|
+
console.warn(`[mesh] Skipped oss submodule sync on clone: source node oss ${sourceSha.slice(0, 8)} diverged from the fresh worktree oss ${worktreeOssSha.slice(0, 8)} \u2014 kept worktree HEAD (coordinator reconciles)`);
|
|
48737
|
+
}
|
|
48787
48738
|
}
|
|
48788
48739
|
}
|
|
48789
48740
|
} catch (ossErr) {
|
|
@@ -64272,6 +64223,7 @@ export {
|
|
|
64272
64223
|
loadMeshCoordinatorRegistry,
|
|
64273
64224
|
loadMeshRefineConfig,
|
|
64274
64225
|
loadMeshWorktreeBootstrapConfig,
|
|
64226
|
+
loadRepoSettings,
|
|
64275
64227
|
loadState,
|
|
64276
64228
|
logCommand,
|
|
64277
64229
|
machineCoreFromDaemonId,
|