thumbgate 1.39.0 → 1.40.1
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/.agents/skills/craft-playbook-gate/SKILL.md +51 -0
- package/.agents/skills/qwenwork-policy-group-honesty-not-clone/SKILL.md +36 -0
- package/.claude-plugin/plugin.json +1 -1
- package/.well-known/llms.txt +2 -2
- package/.well-known/mcp/server-card.json +1 -1
- package/README.md +11 -5
- package/adapters/claude/.mcp.json +6 -2
- package/adapters/codex/config.toml +5 -0
- package/adapters/forge/forge.yaml +4 -4
- package/adapters/future-agi/.mcp.json +1 -1
- package/adapters/future-agi/config.toml +1 -1
- package/adapters/future-agi/opencode.json +1 -1
- package/adapters/herdr/herdr-plugin.toml +2 -2
- package/adapters/mcp/server-stdio.js +104 -7
- package/adapters/opencode/opencode.json +1 -1
- package/adapters/strands/strands-middleware.js +31 -4
- package/bin/cli.js +191 -54
- package/config/brand-standards.json +131 -0
- package/config/gates/default.json +18 -1
- package/config/github-about.json +1 -1
- package/config/mcp-allowlists.json +16 -3
- package/config/merge-quality-checks.json +3 -1
- package/config/post-deploy-marketing-pages.json +4 -4
- package/config/schemas/task-outcome-receipt.schema.json +9 -0
- package/hooks/hooks.json +24 -0
- package/openapi/openapi.yaml +7 -3
- package/package.json +87 -33
- package/public/about.html +2 -2
- package/public/admin.html +771 -0
- package/public/agent-manager.html +3 -3
- package/public/agents-cost-savings.html +1 -1
- package/public/ai-malpractice-prevention.html +12 -12
- package/public/architecture.html +0 -1
- package/public/assets/diagrams/decision.svg +3 -3
- package/public/assets/diagrams/hero-thumbs.svg +2 -4
- package/public/blog/2026-10-05-why-3-days-of-triage-wont-save-ai-speed-code.html +1 -1
- package/public/blog/2026-10-09-your-code-got-a-third-author-governance.html +1 -1
- package/public/blog/git-at-agent-scale.html +2 -2
- package/public/blog/inside-your-boundary.html +1 -1
- package/public/blog/process-over-outcome-gates.html +1 -1
- package/public/case-studies.html +5 -6
- package/public/codex-enterprise.html +1 -1
- package/public/codex-plugin.html +1 -1
- package/public/dashboard.html +775 -483
- package/public/diagnostic.html +15 -10
- package/public/enterprise-governance.html +26 -174
- package/public/eval-scorecard.html +3 -4
- package/public/eval-scorecard.json +2 -2
- package/public/evaluations.html +0 -1
- package/public/founders.html +3 -3
- package/public/gaming-playbook.html +4 -4
- package/public/guide.html +3 -5
- package/public/index.html +302 -97
- package/public/install.html +16 -10
- package/public/js/buyer-intent.js +49 -8
- package/public/lessons.html +246 -83
- package/public/numbers.html +32 -33
- package/public/operator-framework.html +44 -72
- package/public/peter.html +3 -3
- package/public/platform-partners.html +1 -1
- package/public/pricing.html +163 -66
- package/public/pro.html +3 -1
- package/public/project-switcher.js +76 -0
- package/public/whitepaper.html +1 -2
- package/scripts/action-receipts.js +393 -0
- package/scripts/activation-quickstart.js +15 -3
- package/scripts/activation-tracker.js +280 -3
- package/scripts/agent-action-inventory.js +235 -143
- package/scripts/agent-operations-planner.js +1 -1
- package/scripts/agent-readiness.js +36 -6
- package/scripts/agentic-prompt-pipelines.js +901 -0
- package/scripts/analytics-window.js +7 -1
- package/scripts/async-job-runner.js +66 -11
- package/scripts/audit-trail.js +37 -24
- package/scripts/auto-promote-gates.js +37 -27
- package/scripts/auto-wire-hooks.js +64 -25
- package/scripts/backfill-lesson-scopes.js +122 -0
- package/scripts/billing.js +889 -132
- package/scripts/bot-detection.js +112 -0
- package/scripts/brand-standards-gate.js +571 -0
- package/scripts/chatgpt-ads-readiness-pack.js +1 -1
- package/scripts/cli-demo.js +5 -27
- package/scripts/cli-schema.js +25 -1
- package/scripts/commercial-offer.js +2 -2
- package/scripts/contextfs.js +9 -3
- package/scripts/craft-playbook-gate.js +550 -0
- package/scripts/cross-encoder-reranker.js +4 -0
- package/scripts/dashboard-chat.js +11 -0
- package/scripts/dashboard.js +574 -167
- package/scripts/decision-journal.js +7 -4
- package/scripts/docker-sandbox-planner.js +3 -3
- package/scripts/export-dpo-pairs.js +12 -7
- package/scripts/failure-diagnostics.js +11 -0
- package/scripts/feedback-aggregate.js +4 -0
- package/scripts/feedback-attribution.js +6 -4
- package/scripts/feedback-history-distiller.js +18 -6
- package/scripts/feedback-loop.js +255 -89
- package/scripts/feedback-paths.js +8 -1
- package/scripts/feedback-sanitizer.js +5 -0
- package/scripts/feedback-scope.js +106 -0
- package/scripts/feedback-session.js +8 -2
- package/scripts/filesystem-search.js +13 -8
- package/scripts/financial-control-plane.js +707 -45
- package/scripts/gate-stats.js +38 -5
- package/scripts/gates-engine.js +1326 -240
- package/scripts/generate-eval-scorecard.js +0 -1
- package/scripts/gitlab-sdlc-prompts.js +397 -0
- package/scripts/harness-tool-names.js +31 -5
- package/scripts/hook-runtime.js +10 -0
- package/scripts/hybrid-feedback-context.js +7 -2
- package/scripts/intervention-policy.js +2 -1
- package/scripts/lesson-canonical.js +2 -2
- package/scripts/lesson-db.js +55 -14
- package/scripts/lesson-graph.js +2 -1
- package/scripts/lesson-retrieval.js +95 -9
- package/scripts/lesson-search.js +86 -22
- package/scripts/lesson-synthesis.js +21 -5
- package/scripts/mabl-failure-honesty.js +273 -0
- package/scripts/mailer/index.js +17 -1
- package/scripts/mailer/resend-mailer.js +213 -179
- package/scripts/migrate-project-scope.js +209 -0
- package/scripts/model-distress-detector.js +3 -3
- package/scripts/operational-integrity.js +436 -3
- package/scripts/override-audit.js +2 -0
- package/scripts/owner-admin.js +338 -0
- package/scripts/pr-manager.js +194 -1
- package/scripts/product-feedback.js +35 -0
- package/scripts/progressive-signoff.js +260 -0
- package/scripts/project-catalog.js +243 -0
- package/scripts/project-dashboard.js +61 -0
- package/scripts/project-evidence.js +172 -0
- package/scripts/project-identity.js +182 -0
- package/scripts/project-scope.js +381 -0
- package/scripts/prompt-eval.js +1 -1
- package/scripts/prompt-guard.js +446 -52
- package/scripts/proof-report.js +232 -0
- package/scripts/provider-action-normalizer.js +14 -6
- package/scripts/qwenwork-policy-group.js +413 -0
- package/scripts/rate-limiter.js +41 -0
- package/scripts/secret-redaction.js +171 -25
- package/scripts/secret-scanner.js +101 -42
- package/scripts/self-protection.js +2 -2
- package/scripts/seo-gsd.js +14 -14
- package/scripts/session-context-dedupe.js +66 -0
- package/scripts/settings-hierarchy.js +4 -2
- package/scripts/statusline-meta.js +34 -23
- package/scripts/tailscale-october-access.js +416 -0
- package/scripts/task-outcomes.js +58 -2
- package/scripts/telemetry-analytics.js +260 -16
- package/scripts/thumbgate-search.js +23 -9
- package/scripts/tool-kpi-tracker.js +5 -2
- package/scripts/tool-registry.js +42 -1
- package/scripts/triage-savings-calculator.js +1 -1
- package/scripts/vector-store.js +4 -1
- package/scripts/verified-lessons.js +270 -0
- package/scripts/verify-marketing-pages-deployed.js +2 -2
- package/scripts/workflow-sentinel.js +29 -10
- package/server.json +2 -2
- package/src/api/server.js +2478 -470
- package/src/feedback.js +21 -0
- package/src/hermes-sync-plane.js +2 -1
- package/src/index.js +2 -0
- package/src/lesson-search.js +9 -0
- package/src/mckinsey-top-company-ai-coding.js +493 -0
- package/src/mcp/email-triage-server/index.js +973 -0
- package/src/mcp/email-triage-server/package.json +12 -0
- package/src/mcp/server.js +3 -0
- package/src/mcp-writeguard.js +772 -11
- package/src/openshell-lovable-engine.js +1475 -0
- package/src/task-outcome.js +3 -0
- package/config/evals/agent-safety-eval.json +0 -447
- package/config/evals/retrieval-ranking-golden.json +0 -522
- package/config/progressive/01-wire-only.json +0 -11
- package/config/progressive/02-dashboard-empty-ok.json +0 -10
- package/config/progressive/03-one-lesson.json +0 -10
- package/config/progressive/04-warn-fires.json +0 -11
- package/config/progressive/05-strict-optional.json +0 -11
- package/config/progressive/README.md +0 -15
- package/public/assets/diagrams/agent-integration.png +0 -0
- package/public/assets/diagrams/thumbgate-architecture.png +0 -0
package/scripts/contextfs.js
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
* - Evaluator: record pack outcome for learning loop
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
+
const { tenantDataScope, assertScopedDataPath } = require('./feedback-scope');
|
|
11
12
|
const fs = require('fs');
|
|
12
13
|
const path = require('path');
|
|
13
14
|
const crypto = require('crypto');
|
|
@@ -25,13 +26,15 @@ function getFeedbackBaseDir() {
|
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
function getContextFsRoot() {
|
|
29
|
+
const scope = tenantDataScope();
|
|
30
|
+
if (scope) return assertScopedDataPath(path.join(scope.feedbackDir, 'contextfs'));
|
|
28
31
|
const feedbackDir = getFeedbackBaseDir();
|
|
29
32
|
if (process.env.THUMBGATE_CONTEXTFS_DIR) return process.env.THUMBGATE_CONTEXTFS_DIR;
|
|
30
33
|
return feedbackDir.endsWith('contextfs') ? feedbackDir : path.join(feedbackDir, 'contextfs');
|
|
31
34
|
}
|
|
32
35
|
|
|
33
36
|
function contextFsPath(...segments) {
|
|
34
|
-
return path.join(getContextFsRoot(), ...segments);
|
|
37
|
+
return assertScopedDataPath(path.join(getContextFsRoot(), ...segments));
|
|
35
38
|
}
|
|
36
39
|
|
|
37
40
|
const NAMESPACES = {
|
|
@@ -130,21 +133,24 @@ function toSlug(input) {
|
|
|
130
133
|
}
|
|
131
134
|
|
|
132
135
|
function writeJson(filePath, payload) {
|
|
136
|
+
assertScopedDataPath(filePath);
|
|
133
137
|
ensureDir(path.dirname(filePath));
|
|
134
138
|
fs.writeFileSync(filePath, `${JSON.stringify(payload, null, 2)}\n`);
|
|
135
139
|
}
|
|
136
140
|
|
|
137
141
|
function appendJsonl(filePath, payload) {
|
|
142
|
+
assertScopedDataPath(filePath);
|
|
138
143
|
ensureDir(path.dirname(filePath));
|
|
139
144
|
fs.appendFileSync(filePath, `${JSON.stringify(payload)}\n`);
|
|
140
145
|
}
|
|
141
146
|
|
|
142
147
|
function listJsonFiles(dirPath) {
|
|
148
|
+
assertScopedDataPath(dirPath);
|
|
143
149
|
if (!fs.existsSync(dirPath)) return [];
|
|
144
150
|
const files = fs.readdirSync(dirPath, { withFileTypes: true });
|
|
145
151
|
const out = [];
|
|
146
152
|
files.forEach((entry) => {
|
|
147
|
-
const fullPath = path.join(dirPath, entry.name);
|
|
153
|
+
const fullPath = assertScopedDataPath(path.join(dirPath, entry.name));
|
|
148
154
|
if (entry.isDirectory()) {
|
|
149
155
|
out.push(...listJsonFiles(fullPath));
|
|
150
156
|
return;
|
|
@@ -851,7 +857,7 @@ function loadMemexIndex() {
|
|
|
851
857
|
function dereferenceEntry(entry) {
|
|
852
858
|
if (!entry || !entry.stableRef) return null;
|
|
853
859
|
try {
|
|
854
|
-
return JSON.parse(fs.readFileSync(entry.stableRef, 'utf-8'));
|
|
860
|
+
return JSON.parse(fs.readFileSync(assertScopedDataPath(entry.stableRef), 'utf-8'));
|
|
855
861
|
} catch {
|
|
856
862
|
return null;
|
|
857
863
|
}
|
|
@@ -0,0 +1,550 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Local playbook gate stolen from Rachel Woods (2026-10).
|
|
6
|
+
*
|
|
7
|
+
* Her idea: one atomic deliverable has a trigger, inputs, steps, and an
|
|
8
|
+
* output; the first cycle keeps a person on judgment; a spontaneous win is
|
|
9
|
+
* locked into the text; the playbook lives outside the model UI; a structural
|
|
10
|
+
* self-edit needs a human; a stack is done only after each child is verified.
|
|
11
|
+
*
|
|
12
|
+
* This file does not write a playbook, call a model, spawn an agent, or talk
|
|
13
|
+
* to a task service. Source: https://www.youtube.com/watch?v=CMkwClAm2TI
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
const crypto = require('node:crypto');
|
|
17
|
+
const fs = require('node:fs');
|
|
18
|
+
const path = require('node:path');
|
|
19
|
+
|
|
20
|
+
const SOURCE_URL = 'https://www.youtube.com/watch?v=CMkwClAm2TI';
|
|
21
|
+
const CRAFT_STAGES = ['clear', 'realistic', 'setup', 'feedback', 'rollout'];
|
|
22
|
+
const TRIGGER_KINDS = new Set(['schedule', 'calendar', 'webhook', 'hook', 'manual']);
|
|
23
|
+
const GENERIC_TRIGGER_WORDS = new Set([
|
|
24
|
+
'feedback',
|
|
25
|
+
'review',
|
|
26
|
+
'help',
|
|
27
|
+
'playbook',
|
|
28
|
+
'run',
|
|
29
|
+
'default',
|
|
30
|
+
'automate',
|
|
31
|
+
'agent',
|
|
32
|
+
]);
|
|
33
|
+
const VAGUE_DETAILS = new Set([
|
|
34
|
+
'handle it',
|
|
35
|
+
'do the work',
|
|
36
|
+
'automate the role',
|
|
37
|
+
'figure it out',
|
|
38
|
+
]);
|
|
39
|
+
const REFUSED_HOMES = new Set(['claude-project', 'chatgpt-gpt', 'gemini-gem', 'vendor-ui']);
|
|
40
|
+
const REFUSED_MODES = new Set(['subagent', 'asana', 'clickup', 'claude-subagent']);
|
|
41
|
+
const TRIGGER_WORD = /^[a-z][a-z0-9-]{2,32}$/;
|
|
42
|
+
const PLAYBOOK_PATH = /^[a-z0-9][a-z0-9/_-]*\.(md|json)$/;
|
|
43
|
+
const ROLE_SCOPE = /\b(entire role|whole department)\b/i;
|
|
44
|
+
|
|
45
|
+
function plainObject(value) {
|
|
46
|
+
return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function nonEmptyString(value) {
|
|
50
|
+
return typeof value === 'string' && value.trim() !== '';
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function hold(kind, code, message, extra) {
|
|
54
|
+
return {
|
|
55
|
+
ok: false,
|
|
56
|
+
code,
|
|
57
|
+
decision: extra && extra.decision ? extra.decision : 'hold',
|
|
58
|
+
mayApply: false,
|
|
59
|
+
wrote: false,
|
|
60
|
+
requiresApproval: Boolean(extra && extra.requiresApproval),
|
|
61
|
+
blockers: [{ code, message }],
|
|
62
|
+
kind,
|
|
63
|
+
message,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function accept(kind, code, decision, message, mayApply) {
|
|
68
|
+
return {
|
|
69
|
+
ok: true,
|
|
70
|
+
code,
|
|
71
|
+
decision,
|
|
72
|
+
mayApply: mayApply === true,
|
|
73
|
+
wrote: false,
|
|
74
|
+
requiresApproval: false,
|
|
75
|
+
blockers: [],
|
|
76
|
+
kind,
|
|
77
|
+
message,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function canonicalize(value) {
|
|
82
|
+
if (Array.isArray(value)) return value.map(canonicalize);
|
|
83
|
+
if (!plainObject(value)) return value;
|
|
84
|
+
const out = {};
|
|
85
|
+
for (const key of Object.keys(value).sort()) {
|
|
86
|
+
out[key] = canonicalize(value[key]);
|
|
87
|
+
}
|
|
88
|
+
return out;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function backupDigest(value) {
|
|
92
|
+
return crypto.createHash('sha256').update(JSON.stringify(canonicalize(value)), 'utf8').digest('hex');
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function checkTriggerWord(word) {
|
|
96
|
+
if (typeof word !== 'string' || !TRIGGER_WORD.test(word)) {
|
|
97
|
+
return {
|
|
98
|
+
ok: false,
|
|
99
|
+
code: 'trigger_word_shape',
|
|
100
|
+
message: 'A trigger word is lowercase letters, digits, and hyphens, from 3 to 33 characters.',
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
if (GENERIC_TRIGGER_WORDS.has(word)) {
|
|
104
|
+
return {
|
|
105
|
+
ok: false,
|
|
106
|
+
code: 'trigger_word_generic',
|
|
107
|
+
message: `Trigger word "${word}" is too generic. Use a distinct name such as nitpicking.`,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
return { ok: true };
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function stepDetails(steps) {
|
|
114
|
+
if (!Array.isArray(steps)) return [];
|
|
115
|
+
return steps
|
|
116
|
+
.filter((step) => plainObject(step) && typeof step.detail === 'string')
|
|
117
|
+
.map((step) => step.detail);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function evaluateOutline(doc) {
|
|
121
|
+
if (!nonEmptyString(doc.id)) {
|
|
122
|
+
return hold('outline', 'id_required', 'An outline needs an id.');
|
|
123
|
+
}
|
|
124
|
+
if (!nonEmptyString(doc.deliverable)) {
|
|
125
|
+
return hold('outline', 'deliverable_required', 'An outline needs one deliverable.');
|
|
126
|
+
}
|
|
127
|
+
if (doc.scope === 'role' || doc.scope === 'department' || ROLE_SCOPE.test(doc.deliverable)) {
|
|
128
|
+
return hold('outline', 'scope_refused', 'Start with one deliverable. A role or a department is not version 1.');
|
|
129
|
+
}
|
|
130
|
+
if (!TRIGGER_KINDS.has(doc.triggerKind)) {
|
|
131
|
+
return hold('outline', 'trigger_kind', 'triggerKind must be schedule, calendar, webhook, hook, or manual.');
|
|
132
|
+
}
|
|
133
|
+
if (!nonEmptyString(doc.trigger)) {
|
|
134
|
+
return hold('outline', 'trigger_required', 'An outline needs the event that starts the work.');
|
|
135
|
+
}
|
|
136
|
+
if (!Array.isArray(doc.inputs)) {
|
|
137
|
+
return hold('outline', 'inputs_must_be_a_list', 'Inputs must be a list of the exact data the playbook reads.');
|
|
138
|
+
}
|
|
139
|
+
if (doc.inputs.length === 0 || doc.inputs.some((item) => !nonEmptyString(item))) {
|
|
140
|
+
return hold('outline', 'inputs_required', 'Inputs must list at least one non-empty source.');
|
|
141
|
+
}
|
|
142
|
+
if (!Array.isArray(doc.steps) || doc.steps.length === 0) {
|
|
143
|
+
return hold('outline', 'steps_required', 'An outline needs at least one step.');
|
|
144
|
+
}
|
|
145
|
+
const seen = new Set();
|
|
146
|
+
for (const step of doc.steps) {
|
|
147
|
+
if (!plainObject(step) || !nonEmptyString(step.id) || !nonEmptyString(step.detail)) {
|
|
148
|
+
return hold('outline', 'step_shape', 'Each step needs an id and a detail.');
|
|
149
|
+
}
|
|
150
|
+
if (seen.has(step.id)) {
|
|
151
|
+
return hold('outline', 'step_id_duplicate', `Step id "${step.id}" is used more than once.`);
|
|
152
|
+
}
|
|
153
|
+
seen.add(step.id);
|
|
154
|
+
if (VAGUE_DETAILS.has(step.detail.trim().toLowerCase())) {
|
|
155
|
+
return hold('outline', 'step_vague', `Step "${step.id}" does not say what to do.`);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
if (!nonEmptyString(doc.output)) {
|
|
159
|
+
return hold('outline', 'output_required', 'An outline needs an output that says what done looks like.');
|
|
160
|
+
}
|
|
161
|
+
if (!nonEmptyString(doc.escalation)) {
|
|
162
|
+
return hold('outline', 'escalation_required', 'An outline needs a separate escalation for the cases a person still sees.');
|
|
163
|
+
}
|
|
164
|
+
const word = checkTriggerWord(doc.triggerWord);
|
|
165
|
+
if (!word.ok) return hold('outline', word.code, word.message);
|
|
166
|
+
const stored = storageHold('outline', doc);
|
|
167
|
+
if (stored) return stored;
|
|
168
|
+
return accept('outline', 'outline_ready', 'accept', 'The outline is one deliverable stored in git.');
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function storageHold(kind, doc) {
|
|
172
|
+
if (doc.home == null || doc.home === '') {
|
|
173
|
+
return hold(kind, 'home_required', 'An outline needs a home. ThumbGate stores playbooks in git.');
|
|
174
|
+
}
|
|
175
|
+
if (doc.home !== 'git' || REFUSED_HOMES.has(doc.home)) {
|
|
176
|
+
return hold(kind, 'home_refused', 'The playbook home is git. A vendor chat UI is not the source of truth.');
|
|
177
|
+
}
|
|
178
|
+
if (doc.path == null || doc.path === '') {
|
|
179
|
+
return hold(kind, 'path_required', 'An outline needs a relative path inside the repo.');
|
|
180
|
+
}
|
|
181
|
+
if (typeof doc.path !== 'string' || doc.path.split(/[/\\]/).includes('..') || !PLAYBOOK_PATH.test(doc.path)) {
|
|
182
|
+
return hold(kind, 'path_refused', 'The path must be a relative .md or .json file inside the repo.');
|
|
183
|
+
}
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function stagesAreOrdered(stages) {
|
|
188
|
+
let seenOpen = false;
|
|
189
|
+
for (const name of CRAFT_STAGES) {
|
|
190
|
+
const done = stages[name] === true;
|
|
191
|
+
if (done && seenOpen) return false;
|
|
192
|
+
if (!done) seenOpen = true;
|
|
193
|
+
}
|
|
194
|
+
return true;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function checkHumanSteps(humanSteps, required) {
|
|
198
|
+
if (!Array.isArray(humanSteps)) {
|
|
199
|
+
return {
|
|
200
|
+
ok: false,
|
|
201
|
+
code: required ? 'human_steps_required' : 'human_step_shape',
|
|
202
|
+
message: required
|
|
203
|
+
? 'Cycle 1 needs at least one named human step and why it is still a person.'
|
|
204
|
+
: 'humanSteps must be a list when it is set.',
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
if (required && humanSteps.length === 0) {
|
|
208
|
+
return {
|
|
209
|
+
ok: false,
|
|
210
|
+
code: 'human_steps_required',
|
|
211
|
+
message: 'Cycle 1 needs at least one named human step and why it is still a person.',
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
for (const step of humanSteps) {
|
|
215
|
+
if (!plainObject(step) || !nonEmptyString(step.id) || !nonEmptyString(step.reason)) {
|
|
216
|
+
return {
|
|
217
|
+
ok: false,
|
|
218
|
+
code: 'human_step_shape',
|
|
219
|
+
message: 'Each human step needs an id and a reason.',
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
return { ok: true };
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function evaluateCraft(doc) {
|
|
227
|
+
if (!Number.isInteger(doc.cycle) || doc.cycle < 1) {
|
|
228
|
+
return hold('craft', 'cycle_invalid', 'cycle must be an integer of 1 or more.');
|
|
229
|
+
}
|
|
230
|
+
if (Object.prototype.hasOwnProperty.call(doc, 'zeroTouch') && typeof doc.zeroTouch !== 'boolean') {
|
|
231
|
+
return hold('craft', 'zero_touch_type', 'zeroTouch must be boolean true or false.');
|
|
232
|
+
}
|
|
233
|
+
if (doc.stages != null && !plainObject(doc.stages)) {
|
|
234
|
+
return hold('craft', 'stages_shape', 'stages must be an object.');
|
|
235
|
+
}
|
|
236
|
+
const stages = plainObject(doc.stages) ? doc.stages : {};
|
|
237
|
+
if (!stagesAreOrdered(stages)) {
|
|
238
|
+
return hold('craft', 'stage_order', 'A later CRAFT stage is marked done while an earlier stage is not.');
|
|
239
|
+
}
|
|
240
|
+
if (doc.cycle === 1) {
|
|
241
|
+
if (doc.zeroTouch === true) {
|
|
242
|
+
return hold('craft', 'zero_touch_refused', 'Cycle 1 keeps a person on the judgment steps.');
|
|
243
|
+
}
|
|
244
|
+
const shaped = checkHumanSteps(doc.humanSteps, true);
|
|
245
|
+
if (!shaped.ok) return hold('craft', shaped.code, shaped.message);
|
|
246
|
+
return accept('craft', 'in_loop', 'in_loop', 'Cycle 1 stays in the loop.');
|
|
247
|
+
}
|
|
248
|
+
if (doc.zeroTouch === true) {
|
|
249
|
+
for (const name of CRAFT_STAGES) {
|
|
250
|
+
if (stages[name] !== true) {
|
|
251
|
+
return hold('craft', 'stages_incomplete', 'Zero-touch needs every CRAFT stage done in order.');
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
if (!Array.isArray(doc.humanSteps) || doc.humanSteps.length !== 0) {
|
|
255
|
+
return hold('craft', 'human_steps_remain', 'Zero-touch needs humanSteps to be an empty list.');
|
|
256
|
+
}
|
|
257
|
+
const feedback = doc.feedback;
|
|
258
|
+
if (!plainObject(feedback) || feedback.errorsReviewed !== true) {
|
|
259
|
+
return hold('craft', 'errors_not_reviewed', 'Zero-touch needs feedback.errorsReviewed to be true.');
|
|
260
|
+
}
|
|
261
|
+
const wins = feedback.lockedWins;
|
|
262
|
+
if (!Array.isArray(wins) || wins.length === 0 || wins.some((win) => !nonEmptyString(win))) {
|
|
263
|
+
return hold('craft', 'wins_not_locked', 'Zero-touch needs each locked win as text.');
|
|
264
|
+
}
|
|
265
|
+
const details = stepDetails(doc.steps);
|
|
266
|
+
for (const win of wins) {
|
|
267
|
+
if (!details.some((detail) => detail.includes(win))) {
|
|
268
|
+
return hold('craft', 'win_not_in_steps', 'A locked win counts only when a step already contains that text.');
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
return accept('craft', 'zero_touch', 'zero_touch', 'A later cycle closed the human steps and locked the wins into the steps.');
|
|
272
|
+
}
|
|
273
|
+
if (doc.humanSteps != null) {
|
|
274
|
+
const shaped = checkHumanSteps(doc.humanSteps, false);
|
|
275
|
+
if (!shaped.ok) return hold('craft', shaped.code, shaped.message);
|
|
276
|
+
}
|
|
277
|
+
return accept('craft', 'in_loop', 'in_loop', 'This cycle stays in the loop.');
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
function relativeBackupPath(value) {
|
|
281
|
+
if (!nonEmptyString(value)) return false;
|
|
282
|
+
if (path.isAbsolute(value)) return false;
|
|
283
|
+
if (value.includes('\\')) return false;
|
|
284
|
+
if (value.split('/').includes('..')) return false;
|
|
285
|
+
return true;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
function structural(playbook) {
|
|
289
|
+
const steps = Array.isArray(playbook.steps) ? playbook.steps : [];
|
|
290
|
+
const humanSteps = Array.isArray(playbook.humanSteps) ? playbook.humanSteps : [];
|
|
291
|
+
return {
|
|
292
|
+
triggerKind: playbook.triggerKind == null ? null : playbook.triggerKind,
|
|
293
|
+
trigger: playbook.trigger == null ? null : playbook.trigger,
|
|
294
|
+
inputs: playbook.inputs == null ? null : playbook.inputs,
|
|
295
|
+
output: playbook.output == null ? null : playbook.output,
|
|
296
|
+
escalation: playbook.escalation == null ? null : playbook.escalation,
|
|
297
|
+
stepIds: steps.map((step) => (plainObject(step) ? step.id ?? null : null)),
|
|
298
|
+
stepEscalate: steps.map((step) => Boolean(plainObject(step) && step.escalate === true)),
|
|
299
|
+
humanStepIds: humanSteps.map((step) => (plainObject(step) ? step.id ?? null : null)),
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
function isMajor(before, after) {
|
|
304
|
+
return JSON.stringify(canonicalize(structural(before))) !== JSON.stringify(canonicalize(structural(after)));
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
function claimedWinsInSteps(doc, after) {
|
|
308
|
+
if (!Object.prototype.hasOwnProperty.call(doc, 'lockedWins') || doc.lockedWins == null) return null;
|
|
309
|
+
const wins = doc.lockedWins;
|
|
310
|
+
if (!Array.isArray(wins) || wins.some((win) => !nonEmptyString(win))) {
|
|
311
|
+
return hold('edit', 'wins_not_locked', 'Claimed wins must be non-empty strings.');
|
|
312
|
+
}
|
|
313
|
+
if (wins.length === 0) return null;
|
|
314
|
+
const details = stepDetails(after.steps);
|
|
315
|
+
for (const win of wins) {
|
|
316
|
+
if (!details.some((detail) => detail.includes(win))) {
|
|
317
|
+
return hold('edit', 'win_not_in_steps', 'A claimed win counts only when the new steps contain that text.');
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
return null;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
function evaluateEdit(doc) {
|
|
324
|
+
if (!plainObject(doc.before) || !plainObject(doc.after)) {
|
|
325
|
+
return hold('edit', 'playbook_required', 'An edit needs before and after playbook objects.');
|
|
326
|
+
}
|
|
327
|
+
const backup = doc.backup;
|
|
328
|
+
if (!plainObject(backup) || typeof backup.sha256 !== 'string' || !relativeBackupPath(backup.path)) {
|
|
329
|
+
return hold('edit', 'backup_required', 'A self-edit needs a local backup path and a sha256 of the previous playbook.');
|
|
330
|
+
}
|
|
331
|
+
const livePath = nonEmptyString(doc.before.path) ? doc.before.path : (nonEmptyString(doc.after.path) ? doc.after.path : '');
|
|
332
|
+
if (livePath && backup.path === livePath) {
|
|
333
|
+
return hold('edit', 'backup_required', 'The backup path must be a different file from the playbook.');
|
|
334
|
+
}
|
|
335
|
+
if (backup.sha256.toLowerCase() !== backupDigest(doc.before)) {
|
|
336
|
+
return hold('edit', 'backup_required', 'The backup hash does not match the previous playbook.');
|
|
337
|
+
}
|
|
338
|
+
if (JSON.stringify(canonicalize(doc.before)) === JSON.stringify(canonicalize(doc.after))) {
|
|
339
|
+
return hold('edit', 'unchanged', 'The playbook did not change, so there is nothing to apply.', { decision: 'unchanged' });
|
|
340
|
+
}
|
|
341
|
+
const wins = claimedWinsInSteps(doc, doc.after);
|
|
342
|
+
if (wins) return wins;
|
|
343
|
+
const stored = storageHold('edit', doc.after);
|
|
344
|
+
if (stored) return stored;
|
|
345
|
+
if (isMajor(doc.before, doc.after)) {
|
|
346
|
+
if (doc.approved !== true || !nonEmptyString(doc.approvedBy)) {
|
|
347
|
+
return hold(
|
|
348
|
+
'edit',
|
|
349
|
+
'approval_required',
|
|
350
|
+
'A change to the trigger, steps, or escalation needs approved true and a named approvedBy.',
|
|
351
|
+
{ requiresApproval: true, decision: 'approval_required' },
|
|
352
|
+
);
|
|
353
|
+
}
|
|
354
|
+
return accept('edit', 'approved_major', 'approved_major', 'The structural change is approved and the previous playbook is backed up.', true);
|
|
355
|
+
}
|
|
356
|
+
if (!nonEmptyString(doc.feedbackRef)) {
|
|
357
|
+
return hold('edit', 'feedback_ref_required', 'A detail tweak needs a feedback reference.');
|
|
358
|
+
}
|
|
359
|
+
return accept('edit', 'minor', 'minor', 'The detail tweak is backed up and tied to feedback.', true);
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
function evaluateVocabulary(doc) {
|
|
363
|
+
if (!Array.isArray(doc.registry) || doc.registry.length === 0) {
|
|
364
|
+
return hold('vocabulary', 'registry_required', 'A vocabulary needs at least one trigger word.');
|
|
365
|
+
}
|
|
366
|
+
const seen = new Set();
|
|
367
|
+
for (const entry of doc.registry) {
|
|
368
|
+
if (!plainObject(entry) || !nonEmptyString(entry.id)) {
|
|
369
|
+
return hold('vocabulary', 'registry_shape', 'Each vocabulary entry needs an id and a trigger word.');
|
|
370
|
+
}
|
|
371
|
+
const word = checkTriggerWord(entry.triggerWord);
|
|
372
|
+
if (!word.ok) return hold('vocabulary', word.code, word.message);
|
|
373
|
+
if (seen.has(entry.triggerWord)) {
|
|
374
|
+
return hold('vocabulary', 'trigger_word_collision', `Trigger word "${entry.triggerWord}" is already used.`);
|
|
375
|
+
}
|
|
376
|
+
seen.add(entry.triggerWord);
|
|
377
|
+
}
|
|
378
|
+
return accept('vocabulary', 'vocabulary_ready', 'accept', 'Each trigger word names one playbook.');
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
function evaluateStack(doc) {
|
|
382
|
+
if (Object.prototype.hasOwnProperty.call(doc, 'mode') && doc.mode !== 'local-board') {
|
|
383
|
+
const named = typeof doc.mode === 'string' ? doc.mode : '';
|
|
384
|
+
return hold(
|
|
385
|
+
'stack',
|
|
386
|
+
'mode_refused',
|
|
387
|
+
named && REFUSED_MODES.has(named.toLowerCase())
|
|
388
|
+
? `Mode "${named}" is refused. This check does not spawn agents or call a task service.`
|
|
389
|
+
: 'mode must be local-board when it is set.',
|
|
390
|
+
);
|
|
391
|
+
}
|
|
392
|
+
if (!nonEmptyString(doc.managerId)) {
|
|
393
|
+
return hold('stack', 'manager_required', 'A stack needs a managerId.');
|
|
394
|
+
}
|
|
395
|
+
if (!Array.isArray(doc.children) || doc.children.length < 2 || doc.children.some((id) => !nonEmptyString(id))) {
|
|
396
|
+
return hold('stack', 'not_a_stack', 'A stack needs at least two child playbooks.');
|
|
397
|
+
}
|
|
398
|
+
if (new Set(doc.children).size !== doc.children.length) {
|
|
399
|
+
return hold('stack', 'duplicate_child', 'Child playbook ids must be unique.');
|
|
400
|
+
}
|
|
401
|
+
if (doc.children.includes(doc.managerId)) {
|
|
402
|
+
return hold('stack', 'stack_self_child', 'The manager cannot be one of its own children.');
|
|
403
|
+
}
|
|
404
|
+
if (!Array.isArray(doc.tasks)) {
|
|
405
|
+
return hold('stack', 'stack_incomplete', 'A stack needs one task per child.');
|
|
406
|
+
}
|
|
407
|
+
const seen = new Map();
|
|
408
|
+
for (const task of doc.tasks) {
|
|
409
|
+
if (!plainObject(task) || !nonEmptyString(task.playbookId) || !nonEmptyString(task.id)) {
|
|
410
|
+
return hold('stack', 'task_shape', 'Each task needs an id and a playbookId.');
|
|
411
|
+
}
|
|
412
|
+
if (!doc.children.includes(task.playbookId)) {
|
|
413
|
+
return hold('stack', 'unknown_child', `Task playbook "${task.playbookId}" is not a child of this stack.`);
|
|
414
|
+
}
|
|
415
|
+
if (seen.has(task.playbookId)) {
|
|
416
|
+
return hold('stack', 'duplicate_task', `Child "${task.playbookId}" has more than one task.`);
|
|
417
|
+
}
|
|
418
|
+
seen.set(task.playbookId, task);
|
|
419
|
+
}
|
|
420
|
+
for (const child of doc.children) {
|
|
421
|
+
if (!seen.has(child)) {
|
|
422
|
+
return hold('stack', 'stack_incomplete', `Child "${child}" has no task.`);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
for (const child of doc.children) {
|
|
426
|
+
const task = seen.get(child);
|
|
427
|
+
if (task.status !== 'done') {
|
|
428
|
+
return hold('stack', 'stack_open', `Child "${child}" is not done.`);
|
|
429
|
+
}
|
|
430
|
+
if (!nonEmptyString(task.output)) {
|
|
431
|
+
return hold('stack', 'stack_missing_output', `Child "${child}" has no output.`);
|
|
432
|
+
}
|
|
433
|
+
if (task.verified !== true) {
|
|
434
|
+
return hold('stack', 'stack_unverified', `Child "${child}" is not verified.`);
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
return accept('stack', 'stack_done', 'stack_done', 'Every child task is done, has output, and is verified.');
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
function evaluate(doc) {
|
|
441
|
+
if (!plainObject(doc)) {
|
|
442
|
+
return hold(null, 'kind_required', 'A playbook check needs kind: outline, craft, edit, vocabulary, or stack.');
|
|
443
|
+
}
|
|
444
|
+
if (doc.kind === 'outline') return evaluateOutline(doc);
|
|
445
|
+
if (doc.kind === 'craft') return evaluateCraft(doc);
|
|
446
|
+
if (doc.kind === 'edit') return evaluateEdit(doc);
|
|
447
|
+
if (doc.kind === 'vocabulary') return evaluateVocabulary(doc);
|
|
448
|
+
if (doc.kind === 'stack') return evaluateStack(doc);
|
|
449
|
+
return hold(null, 'kind_required', 'kind must be outline, craft, edit, vocabulary, or stack.');
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
function ideaMap() {
|
|
453
|
+
return {
|
|
454
|
+
source: SOURCE_URL,
|
|
455
|
+
notOurMeasurement: true,
|
|
456
|
+
taken: [
|
|
457
|
+
'One deliverable has a trigger, inputs, steps, an output, and a separate escalation.',
|
|
458
|
+
'CRAFT runs clear, realistic, setup, feedback, then rollout. Cycle 1 keeps a named human step.',
|
|
459
|
+
'A spontaneous win counts only when its text is inside a step.',
|
|
460
|
+
'Playbooks live in git. A self-edit needs a backup hash of the previous playbook.',
|
|
461
|
+
'A change to the trigger, the steps, or the escalation needs a named approval.',
|
|
462
|
+
'nitpicking is a distinct trigger word. A stack is done only when every child is verified.',
|
|
463
|
+
],
|
|
464
|
+
refused: [
|
|
465
|
+
'Vendor-UI storage (claude-project, chatgpt-gpt, gemini-gem, vendor-ui).',
|
|
466
|
+
'Line-count or percent self-approval.',
|
|
467
|
+
'Spawning subagents.',
|
|
468
|
+
'Asana or ClickUp API calls.',
|
|
469
|
+
'Zero-touch on cycle 1.',
|
|
470
|
+
'An empty document that passes by default.',
|
|
471
|
+
],
|
|
472
|
+
};
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
function printJson(value) {
|
|
476
|
+
process.stdout.write(`${JSON.stringify(value, null, 2)}\n`);
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
function usage() {
|
|
480
|
+
process.stderr.write(
|
|
481
|
+
'Usage: node scripts/craft-playbook-gate.js [--map-only | outline | craft | edit | vocabulary | stack]\n'
|
|
482
|
+
+ ' Reads one JSON object from stdin. Writes nothing.\n',
|
|
483
|
+
);
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
function main(argv, stdin) {
|
|
487
|
+
const args = argv.slice(2);
|
|
488
|
+
if (args.includes('--help') || args.includes('-h')) {
|
|
489
|
+
usage();
|
|
490
|
+
return 0;
|
|
491
|
+
}
|
|
492
|
+
if (args.includes('--map-only')) {
|
|
493
|
+
printJson(ideaMap());
|
|
494
|
+
return 0;
|
|
495
|
+
}
|
|
496
|
+
if (args.some((arg) => arg.startsWith('--'))) {
|
|
497
|
+
usage();
|
|
498
|
+
return 2;
|
|
499
|
+
}
|
|
500
|
+
if (args.length > 1) {
|
|
501
|
+
usage();
|
|
502
|
+
return 2;
|
|
503
|
+
}
|
|
504
|
+
let doc;
|
|
505
|
+
try {
|
|
506
|
+
doc = JSON.parse(stdin || '');
|
|
507
|
+
} catch {
|
|
508
|
+
process.stderr.write('stdin must be one JSON object.\n');
|
|
509
|
+
return 2;
|
|
510
|
+
}
|
|
511
|
+
if (!plainObject(doc)) {
|
|
512
|
+
process.stderr.write('stdin must be one JSON object.\n');
|
|
513
|
+
return 2;
|
|
514
|
+
}
|
|
515
|
+
if (args.length === 1) {
|
|
516
|
+
const command = args[0];
|
|
517
|
+
if (!['outline', 'craft', 'edit', 'vocabulary', 'stack'].includes(command)) {
|
|
518
|
+
usage();
|
|
519
|
+
return 2;
|
|
520
|
+
}
|
|
521
|
+
if (doc.kind == null) doc.kind = command;
|
|
522
|
+
else if (doc.kind !== command) {
|
|
523
|
+
process.stderr.write('The command does not match kind.\n');
|
|
524
|
+
return 2;
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
const evaluated = evaluate(doc);
|
|
528
|
+
printJson(evaluated);
|
|
529
|
+
return evaluated.ok ? 0 : 1;
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
module.exports = {
|
|
533
|
+
SOURCE_URL,
|
|
534
|
+
CRAFT_STAGES,
|
|
535
|
+
GENERIC_TRIGGER_WORDS,
|
|
536
|
+
evaluate,
|
|
537
|
+
ideaMap,
|
|
538
|
+
backupDigest,
|
|
539
|
+
main,
|
|
540
|
+
};
|
|
541
|
+
|
|
542
|
+
function skipsStdin(argv) {
|
|
543
|
+
const args = argv.slice(2);
|
|
544
|
+
return args.includes('--help') || args.includes('-h') || args.includes('--map-only');
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
if (process.argv[1] && path.resolve(process.argv[1]) === path.resolve(__filename)) {
|
|
548
|
+
const stdin = skipsStdin(process.argv) ? '' : fs.readFileSync(0, 'utf8');
|
|
549
|
+
process.exit(main(process.argv, stdin));
|
|
550
|
+
}
|
|
@@ -391,6 +391,8 @@ async function retrieveWithReranking(toolName, actionContext, options = {}) {
|
|
|
391
391
|
metadataFilters: options.metadataFilters,
|
|
392
392
|
queryRewrite: options.queryRewrite,
|
|
393
393
|
includeRetrievalMeta: options.includeRetrievalMeta,
|
|
394
|
+
cwd: options.cwd,
|
|
395
|
+
project: options.project,
|
|
394
396
|
embedder: options.embedder,
|
|
395
397
|
embedderId: options.embedderId,
|
|
396
398
|
});
|
|
@@ -416,6 +418,8 @@ function retrieveWithRerankingSync(toolName, actionContext, options = {}) {
|
|
|
416
418
|
metadataFilters: options.metadataFilters,
|
|
417
419
|
queryRewrite: options.queryRewrite,
|
|
418
420
|
includeRetrievalMeta: options.includeRetrievalMeta,
|
|
421
|
+
cwd: options.cwd,
|
|
422
|
+
project: options.project,
|
|
419
423
|
});
|
|
420
424
|
if (candidates.length === 0) return [];
|
|
421
425
|
|
|
@@ -170,6 +170,7 @@ function retrieveLessonContext(question, opts = {}) {
|
|
|
170
170
|
const res = searchLessons(String(question || ''), {
|
|
171
171
|
limit: MAX_CONTEXT_LESSONS,
|
|
172
172
|
feedbackDir: opts.feedbackDir,
|
|
173
|
+
...(opts.projectKey != null ? { projectKey: opts.projectKey } : {}),
|
|
173
174
|
});
|
|
174
175
|
const rows = res?.results || res?.lessons || [];
|
|
175
176
|
return rows.slice(0, MAX_CONTEXT_LESSONS).map((x) => lessonToContextItem(x));
|
|
@@ -274,6 +275,9 @@ async function retrieveHybridLessonContext(question, opts = {}) {
|
|
|
274
275
|
|
|
275
276
|
// Retrieve relevant stored lessons and optional raw feedback vector matches.
|
|
276
277
|
async function retrieveContext(question, opts = {}) {
|
|
278
|
+
// The hybrid and vector indexes are account-wide and carry no project key, so a
|
|
279
|
+
// project-scoped question only reads the project-filtered lesson search.
|
|
280
|
+
if (opts.projectKey != null) return dedupeContextItems(retrieveLessonContext(question, opts));
|
|
277
281
|
const hybrid = await retrieveHybridLessonContext(question, opts);
|
|
278
282
|
const lessons = hybrid.length ? hybrid : retrieveLessonContext(question, opts);
|
|
279
283
|
const vectors = await retrieveVectorContext(question, opts);
|
|
@@ -624,8 +628,15 @@ async function answerDataQuestion(question, opts = {}) { // NOSONAR
|
|
|
624
628
|
},
|
|
625
629
|
});
|
|
626
630
|
|
|
631
|
+
const resolvedModel = structured.model || route.model;
|
|
632
|
+
const privacyRoute = route.provider === 'local'
|
|
633
|
+
? 'Local, no cloud'
|
|
634
|
+
: `BYO model (${route.provider})`;
|
|
627
635
|
return {
|
|
628
636
|
...structured,
|
|
637
|
+
model: resolvedModel,
|
|
638
|
+
provider: route.provider,
|
|
639
|
+
privacyRoute,
|
|
629
640
|
qualityTier: quality.qualityTier,
|
|
630
641
|
semanticClaimsAllowed: quality.semanticClaimsAllowed,
|
|
631
642
|
degradedReasons: quality.degradedReasons,
|