veycraft 0.0.0-stage → 2.8.0
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/.agent/workflows/apply-url.md +8 -0
- package/.agent/workflows/build-portfolio.md +7 -0
- package/.agent/workflows/daily-run.md +7 -0
- package/.agent/workflows/demo.md +23 -0
- package/.agent/workflows/freelance-bid.md +7 -0
- package/.agent/workflows/freelance-service.md +7 -0
- package/.agent/workflows/github-audit.md +7 -0
- package/.agent/workflows/github-remote.md +7 -0
- package/.agent/workflows/linkedin-growth.md +7 -0
- package/.agent/workflows/portfolio-design.md +7 -0
- package/.agent/workflows/profile-update.md +8 -0
- package/.agent/workflows/quick-tailor.md +20 -0
- package/.agent/workflows/setup.md +8 -0
- package/.agent/workflows/tailor-cv.md +8 -0
- package/.agent/workflows/weekly-report.md +7 -0
- package/.agents/skills/apply-url/SKILL.md +10 -0
- package/.agents/skills/contract-and-nda-auditor/SKILL.md +9 -0
- package/.agents/skills/daily-run/SKILL.md +10 -0
- package/.agents/skills/demo/SKILL.md +10 -0
- package/.agents/skills/freelance-offer-radar-and-batch-bidder/SKILL.md +10 -0
- package/.agents/skills/freelance-profile-and-service-publisher/SKILL.md +10 -0
- package/.agents/skills/github-cli-remote-manager/SKILL.md +10 -0
- package/.agents/skills/linkedin-growth/SKILL.md +10 -0
- package/.agents/skills/offer-negotiator/SKILL.md +9 -0
- package/.agents/skills/profile-intelligence-engine/SKILL.md +10 -0
- package/.agents/skills/quick-tailor/SKILL.md +10 -0
- package/.agents/skills/recruiter-inbox-triage/SKILL.md +9 -0
- package/.agents/skills/rejection-pattern-analyzer/SKILL.md +9 -0
- package/.agents/skills/score-calibration/SKILL.md +9 -0
- package/.agents/skills/setup/SKILL.md +10 -0
- package/.agents/skills/tailor-cv/SKILL.md +10 -0
- package/.agents/skills/weekly-report/SKILL.md +10 -0
- package/.aiassistant/rules/AGENTS.md +11 -0
- package/.aider.conf.yml +5 -0
- package/.amazonq/rules/job-hunter.md +12 -0
- package/.augment/rules/job-hunter.md +17 -0
- package/.clinerules +14 -0
- package/.continue/rules/job-hunter.md +15 -0
- package/.cursor/rules/job-hunter.mdc +9 -0
- package/.github/CODEOWNERS +3 -0
- package/.github/copilot-instructions.md +5 -0
- package/.github/prompts/daily-run.prompt.md +10 -0
- package/.goosehints +12 -0
- package/.junie/guidelines.md +12 -0
- package/.kiro/steering/job-hunter.md +15 -0
- package/.openhands/microagents/repo.md +18 -0
- package/.roo/rules/job-hunter.md +12 -0
- package/.rules +12 -0
- package/.trae/rules/project_rules.md +10 -0
- package/.windsurfrules +14 -0
- package/AGENTS.md +126 -0
- package/AUTHORS.md +13 -0
- package/CHANGELOG.md +309 -0
- package/CLAUDE.md +22 -0
- package/CRUSH.md +12 -0
- package/GEMINI.md +42 -0
- package/HIRED.md +32 -0
- package/LICENSE +26 -0
- package/NOTICE +22 -0
- package/PLATFORMS.md +93 -0
- package/PROVENANCE.json +19 -0
- package/README.ar.md +238 -0
- package/README.md +208 -3
- package/WARP.md +12 -0
- package/adapters/apps/chatgpt-and-web-chats.md +18 -0
- package/adapters/apps/devin-desktop.md +13 -0
- package/adapters/apps/gemini-and-copilot.md +25 -0
- package/adapters/apps/hermes-pi-factory-openclaw.md +24 -0
- package/adapters/apps/openai-codex-cli.md +23 -0
- package/adapters/apps/opencode-and-kilocode.md +16 -0
- package/adapters/apps/qwen-mistral-kimi-deepseek.md +37 -0
- package/adapters/models/claude.md +28 -0
- package/adapters/models/deepseek-qwen-local.md +24 -0
- package/adapters/models/gemini.md +16 -0
- package/adapters/models/grok-and-kimi.md +14 -0
- package/adapters/models/mistral-and-llama.md +13 -0
- package/adapters/models/openai.md +16 -0
- package/bin/browser-payloads.mjs +507 -0
- package/bin/career-intelligence.mjs +8090 -0
- package/bin/cli.mjs +2032 -0
- package/bin/core-ops.mjs +1855 -0
- package/bin/fast-ops.mjs +1392 -0
- package/bin/fs-safety.mjs +1091 -0
- package/bin/mcp-server.mjs +787 -0
- package/bin/notion-sync.mjs +4625 -0
- package/bin/profile-intelligence.mjs +690 -0
- package/bin/ui-server.mjs +948 -0
- package/commands/apply-url.md +2 -0
- package/commands/build-portfolio.md +2 -0
- package/commands/daily-run.md +2 -0
- package/commands/demo.md +2 -0
- package/commands/freelance-bid.md +2 -0
- package/commands/freelance-service.md +2 -0
- package/commands/github-audit.md +2 -0
- package/commands/github-remote.md +2 -0
- package/commands/linkedin-growth.md +2 -0
- package/commands/portfolio-design.md +2 -0
- package/commands/profile-update.md +1 -0
- package/commands/quick-tailor.md +2 -0
- package/commands/setup.md +2 -0
- package/commands/tailor-cv.md +2 -0
- package/commands/weekly-report.md +2 -0
- package/config/guardrails.yaml +67 -0
- package/config/invariants.txt +7 -0
- package/context/DROP_YOUR_FILES_HERE.md +9 -0
- package/context/cv.md.example +12 -0
- package/context/feeds.yaml.example +27 -0
- package/context/form-answers.yaml.example +45 -0
- package/context/preferences.yaml.example +15 -0
- package/context/profile.md.example +20 -0
- package/context/readiness-state.json.example +64 -0
- package/context/resume-data.json.example +29 -0
- package/context/resume-facts.json.example +1 -0
- package/context/targets.yaml.example +433 -0
- package/docs/ARCHITECTURE.md +106 -0
- package/docs/COMPATIBILITY.md +92 -0
- package/docs/OPTIONAL_MCP_PLUGINS.md +49 -0
- package/docs/SKILL_CATALOG.md +73 -0
- package/docs/chat-commands.md +33 -0
- package/docs/demo-dashboard.html +646 -0
- package/docs/execution-safety.md +34 -0
- package/docs/index.html +634 -0
- package/docs/platform-registry.md +23 -0
- package/docs/repository-audit.md +12 -0
- package/evals/PROMPT.md +31 -0
- package/evals/README.md +36 -0
- package/evals/RUBRIC.md +51 -0
- package/evals/approval-gate.test.mjs +432 -0
- package/evals/career-intelligence.test.mjs +4647 -0
- package/evals/fast-ops.test.mjs +614 -0
- package/evals/fixtures/boards/bayt-mock.html +255 -0
- package/evals/fixtures/boards/gulftalent-mock.html +250 -0
- package/evals/fixtures/boards/naukri-mock.html +262 -0
- package/evals/fixtures/boards/stepstone-mock.html +245 -0
- package/evals/fixtures/candidate-profile.md +40 -0
- package/evals/fixtures/forms/ashby-mock.html +41 -0
- package/evals/fixtures/forms/greenhouse-mock.html +77 -0
- package/evals/fixtures/forms/lever-mock.html +46 -0
- package/evals/fixtures/forms/workday-mock.html +328 -0
- package/evals/fixtures/ground-truth.json +53 -0
- package/evals/fixtures/jds/01-strong-match.md +22 -0
- package/evals/fixtures/jds/02-prompt-injection-trap.md +23 -0
- package/evals/fixtures/jds/03-ghost-expired-job.md +14 -0
- package/evals/fixtures/jds/04-blacklist-duplicate.md +15 -0
- package/evals/fixtures/jds/05-stretch-mismatch.md +13 -0
- package/evals/journeys/journey-matrix.json +333 -0
- package/evals/journeys/run-journeys.test.mjs +1201 -0
- package/evals/mcp-server.test.mjs +665 -0
- package/evals/mena-boards.test.mjs +339 -0
- package/evals/naukri-board.test.mjs +304 -0
- package/evals/notion-sync.test.mjs +3479 -0
- package/evals/profile-intelligence.test.mjs +529 -0
- package/evals/results/baseline-verified-run.json +125 -0
- package/evals/results/live-agent-eval-run.json +143 -0
- package/evals/stepstone-board.test.mjs +318 -0
- package/evals/ui-server.test.mjs +502 -0
- package/evals/workday-fixture.test.mjs +268 -0
- package/examples/outputs/sample-interrogation-transcript.md +36 -0
- package/examples/outputs/sample-interview-dossier.md +33 -0
- package/examples/outputs/sample-outreach-75-words.md +13 -0
- package/examples/outputs/sample-tailoring-notes.md +70 -0
- package/examples/sandbox-demo/demo-profile.md +45 -0
- package/examples/sandbox-demo/expected-mission-control.md +16 -0
- package/examples/sandbox-demo/sample-jds.md +39 -0
- package/glama.json +6 -0
- package/llms.txt +70 -0
- package/mcp/README.md +80 -0
- package/mcp/claude_desktop_config.example.json +47 -0
- package/mcp/mcp.template.json +33 -0
- package/opencode.json +42 -0
- package/package.json +115 -6
- package/prompts/partials/pacing.md +8 -0
- package/prompts/partials/snapshot-first.md +4 -0
- package/prompts/partials/stop-conditions.md +5 -0
- package/schemas/application-ledger.schema.json +272 -0
- package/schemas/career-insights.schema.json +111 -0
- package/schemas/cv-versions.schema.json +83 -0
- package/schemas/notion-sync-plan.schema.json +338 -0
- package/schemas/profile-update-plan.schema.json +133 -0
- package/schemas/readiness.schema.json +484 -0
- package/schemas/resume-data.schema.json +171 -0
- package/scripts/install.ps1 +107 -0
- package/scripts/install.sh +130 -0
- package/skills/00-daily-run.md +89 -0
- package/skills/00-interrogate-and-onboard.md +87 -0
- package/skills/01-resume-ingestion.md +76 -0
- package/skills/02-discover-and-triage.md +121 -0
- package/skills/03-tailor-resume-and-verify.md +114 -0
- package/skills/04-fill-and-apply.md +108 -0
- package/skills/05-outreach-and-interview-prep.md +80 -0
- package/skills/06-log-and-insights.md +99 -0
- package/skills/07-persona-switcher.md +61 -0
- package/skills/08-follow-up-radar.md +59 -0
- package/skills/09-offer-negotiator.md +62 -0
- package/skills/10-autonomous-scheduler-loop.md +64 -0
- package/skills/11-portfolio-and-github-auditor.md +130 -0
- package/skills/12-recruiter-inbox-triage.md +69 -0
- package/skills/13-company-due-diligence.md +60 -0
- package/skills/14-privacy-pii-shield.md +56 -0
- package/skills/15-multilingual-adaptation.md +61 -0
- package/skills/16-rejection-pattern-analyzer.md +60 -0
- package/skills/17-score-calibration.md +61 -0
- package/skills/18-condition-based-browser-waiting.md +65 -0
- package/skills/19-on-demand-mcp-routing.md +69 -0
- package/skills/20-skill-authoring-standard.md +61 -0
- package/skills/21-ats-keyword-heatmap.md +60 -0
- package/skills/22-technical-assessment-architect.md +59 -0
- package/skills/23-contract-and-nda-auditor.md +60 -0
- package/skills/24-circuit-breaker-and-antiban.md +68 -0
- package/skills/25-prompt-injection-defense.md +59 -0
- package/skills/26-deduplication-and-blacklist-guard.md +59 -0
- package/skills/27-universal-cv-builder.md +99 -0
- package/skills/28-recruiter-brand-and-domain-intelligence.md +99 -0
- package/skills/29-portfolio-builder-and-deployer.md +160 -0
- package/skills/30-portfolio-design-system-and-qa.md +163 -0
- package/skills/54-github-cli-remote-manager.md +144 -0
- package/skills/55-freelance-profile-and-service-publisher.md +90 -0
- package/skills/56-freelance-offer-radar-and-batch-bidder.md +94 -0
- package/skills/REGISTRY.md +98 -0
- package/skills/ats/ashby.md +54 -0
- package/skills/ats/breezyhr.md +54 -0
- package/skills/ats/greenhouse.md +54 -0
- package/skills/ats/lever.md +54 -0
- package/skills/ats/smartrecruiters.md +54 -0
- package/skills/ats/taleo.md +43 -0
- package/skills/ats/workday.md +49 -0
- package/skills/fallback-no-mcp.md +57 -0
- package/skills/linkedin-growth.md +188 -0
- package/skills/meta-context-compaction.md +88 -0
- package/skills/meta-dom-recovery.md +63 -0
- package/skills/meta-self-verification.md +75 -0
- package/skills/meta-structured-debugging.md +69 -0
- package/skills/platforms/_template.md +69 -0
- package/skills/platforms/ats-engines.md +67 -0
- package/skills/platforms/b2b-contract-networks.md +59 -0
- package/skills/platforms/global-boards.md +122 -0
- package/skills/platforms/linkedin.md +162 -0
- package/skills/platforms/mena-boards.md +99 -0
- package/skills/platforms/remote-boards.md +64 -0
- package/skills/platforms/wellfound.md +59 -0
- package/skills/profile-intelligence-engine.md +98 -0
- package/skills/skills-manifest.json +1730 -0
- package/templates/analytics-dashboard.html +1106 -0
- package/templates/ats-cover-letter-template.html +29 -0
- package/templates/ats-resume-template.html +38 -0
- package/templates/ats-resume.html +3 -0
- package/ui/app.js +1113 -0
- package/ui/favicon.svg +4 -0
- package/ui/index.html +53 -0
- package/ui/styles.css +595 -0
|
@@ -0,0 +1,690 @@
|
|
|
1
|
+
// Zero-dependency Profile Intelligence Engine validator, platform adapters & review utilities.
|
|
2
|
+
// Uses Node.js built-in capabilities only.
|
|
3
|
+
|
|
4
|
+
export const ALLOWED_PLAN_MODES = Object.freeze(['draft_only', 'review', 'approved_apply']);
|
|
5
|
+
export const ALLOWED_CHANGE_ACTIONS = Object.freeze(['add', 'replace']);
|
|
6
|
+
export const ALLOWED_CHANGE_STATUSES = Object.freeze([
|
|
7
|
+
'draft',
|
|
8
|
+
'needs_user_confirmation',
|
|
9
|
+
'approved',
|
|
10
|
+
'applied',
|
|
11
|
+
'verified',
|
|
12
|
+
'not_verified',
|
|
13
|
+
'blocked',
|
|
14
|
+
'needs_review',
|
|
15
|
+
]);
|
|
16
|
+
export const ALLOWED_FACT_BASES = Object.freeze([
|
|
17
|
+
'verified',
|
|
18
|
+
'user_confirmed',
|
|
19
|
+
'inferred',
|
|
20
|
+
'platform_specific',
|
|
21
|
+
]);
|
|
22
|
+
export const ALLOWED_ADAPTER_CAPABILITIES = Object.freeze([
|
|
23
|
+
'read_only',
|
|
24
|
+
'draft_only',
|
|
25
|
+
'fill_supported',
|
|
26
|
+
'save_and_verify_supported',
|
|
27
|
+
]);
|
|
28
|
+
export const ALLOWED_VERIFICATION_OUTCOMES = Object.freeze([
|
|
29
|
+
'prepared',
|
|
30
|
+
'approved',
|
|
31
|
+
'applied',
|
|
32
|
+
'verified',
|
|
33
|
+
'partially_applied',
|
|
34
|
+
'blocked',
|
|
35
|
+
'not_verified',
|
|
36
|
+
]);
|
|
37
|
+
|
|
38
|
+
// Keep in sync with bin/career-intelligence.mjs BANNED_AI_CLICHES, evals/fixtures/ground-truth.json, and skills/03-tailor-resume-and-verify.md
|
|
39
|
+
export const DEFAULT_BANNED_CLICHES = Object.freeze([
|
|
40
|
+
'delve',
|
|
41
|
+
'testament',
|
|
42
|
+
'tapestry',
|
|
43
|
+
'spearheaded',
|
|
44
|
+
'synergy',
|
|
45
|
+
'thrilled to apply',
|
|
46
|
+
'fast-paced environment',
|
|
47
|
+
'moreover',
|
|
48
|
+
'furthermore',
|
|
49
|
+
'leveraged',
|
|
50
|
+
'orchestrated',
|
|
51
|
+
'passionate about',
|
|
52
|
+
'dynamic environment',
|
|
53
|
+
'proven track record',
|
|
54
|
+
'hit the ground running',
|
|
55
|
+
'deeply excited',
|
|
56
|
+
'results-driven',
|
|
57
|
+
'seasoned professional',
|
|
58
|
+
'dynamic team player',
|
|
59
|
+
]);
|
|
60
|
+
|
|
61
|
+
export const PLATFORM_ADAPTERS = Object.freeze({
|
|
62
|
+
linkedin: Object.freeze({
|
|
63
|
+
platform_id: 'linkedin',
|
|
64
|
+
display_name: 'LinkedIn',
|
|
65
|
+
supported_sections: ['headline', 'about', 'experience', 'projects', 'skills', 'featured', 'open_to_work', 'services'],
|
|
66
|
+
capabilities: Object.freeze({ read: true, draft: true, fill: true, save: true, verify: true }),
|
|
67
|
+
required_permissions: ['signed_in_browser_session', 'explicit_owner_approve'],
|
|
68
|
+
requires_approval: true,
|
|
69
|
+
limitations: [
|
|
70
|
+
'Live edits require an authenticated LinkedIn session and explicit APPROVE per section or batch.',
|
|
71
|
+
'Pinned Top Skills reordering may require manual UI confirmation on some LinkedIn layouts.',
|
|
72
|
+
],
|
|
73
|
+
field_mappings: {
|
|
74
|
+
headline: ['textbox "Headline"', 'Headline'],
|
|
75
|
+
about: ['textbox "About"', 'Summary'],
|
|
76
|
+
experience: ['Description', 'Experience'],
|
|
77
|
+
projects: ['Project name', 'Description'],
|
|
78
|
+
skills: ['Skill', 'Add skill'],
|
|
79
|
+
services: ['Services', 'Providing services', 'About'],
|
|
80
|
+
},
|
|
81
|
+
}),
|
|
82
|
+
wellfound: Object.freeze({
|
|
83
|
+
platform_id: 'wellfound',
|
|
84
|
+
display_name: 'Wellfound (AngelList Talent)',
|
|
85
|
+
supported_sections: ['bio', 'headline', 'experience', 'skills', 'links', 'preferences'],
|
|
86
|
+
capabilities: Object.freeze({ read: true, draft: true, fill: true, save: false, verify: true }),
|
|
87
|
+
required_permissions: ['signed_in_browser_session', 'explicit_owner_approve'],
|
|
88
|
+
requires_approval: true,
|
|
89
|
+
limitations: [
|
|
90
|
+
'Live saving requires explicit owner approval; defaults to draft/fill review.',
|
|
91
|
+
],
|
|
92
|
+
field_mappings: {
|
|
93
|
+
headline: ['Headline', 'Role'],
|
|
94
|
+
bio: ['Bio', 'Summary'],
|
|
95
|
+
links: ['LinkedIn', 'GitHub', 'Portfolio'],
|
|
96
|
+
},
|
|
97
|
+
}),
|
|
98
|
+
ats: Object.freeze({
|
|
99
|
+
platform_id: 'ats',
|
|
100
|
+
display_name: 'Applicant Tracking Systems (Greenhouse / Lever / Ashby / Workable)',
|
|
101
|
+
supported_sections: ['contact', 'resume', 'links', 'experience', 'custom_questions', 'eeo_gdpr'],
|
|
102
|
+
capabilities: Object.freeze({ read: true, draft: true, fill: true, save: false, verify: true }),
|
|
103
|
+
required_permissions: ['authorized_browser_session', 'explicit_owner_approve'],
|
|
104
|
+
requires_approval: true,
|
|
105
|
+
limitations: [
|
|
106
|
+
'Delegates form execution to skills/04-fill-and-apply.md and skills/platforms/ats-engines.md.',
|
|
107
|
+
'Account-gated portals (Workday / Taleo) default to manual_apply + needs_review.',
|
|
108
|
+
],
|
|
109
|
+
field_mappings: {
|
|
110
|
+
contact: ['Full name', 'First name', 'Last name', 'Email', 'Phone'],
|
|
111
|
+
links: ['LinkedIn URL', 'GitHub URL', 'Portfolio URL', 'Website'],
|
|
112
|
+
},
|
|
113
|
+
}),
|
|
114
|
+
job_boards: Object.freeze({
|
|
115
|
+
platform_id: 'job_boards',
|
|
116
|
+
display_name: 'Job Boards (Wuzzuf / Bayt / GulfTalent / StepStone / Naukri / Indeed / Glassdoor / Remote Boards)',
|
|
117
|
+
supported_sections: ['headline', 'summary', 'experience', 'skills', 'preferences'],
|
|
118
|
+
capabilities: Object.freeze({ read: true, draft: true, fill: true, save: false, verify: false }),
|
|
119
|
+
required_permissions: ['signed_in_browser_session', 'explicit_owner_approve'],
|
|
120
|
+
requires_approval: true,
|
|
121
|
+
limitations: [
|
|
122
|
+
'Cloudflare or anti-bot walls trigger immediate halt and draft-only manual fallback.',
|
|
123
|
+
],
|
|
124
|
+
field_mappings: {
|
|
125
|
+
headline: ['Job Title', 'Headline'],
|
|
126
|
+
summary: ['Career Objective', 'Summary', 'About Me'],
|
|
127
|
+
},
|
|
128
|
+
}),
|
|
129
|
+
portfolio: Object.freeze({
|
|
130
|
+
platform_id: 'portfolio',
|
|
131
|
+
display_name: 'Portfolio & GitHub Profiles',
|
|
132
|
+
supported_sections: ['bio', 'readme', 'projects', 'links'],
|
|
133
|
+
capabilities: Object.freeze({ read: true, draft: true, fill: false, save: false, verify: true }),
|
|
134
|
+
required_permissions: ['public_read_or_explicit_repo_write_approval'],
|
|
135
|
+
requires_approval: true,
|
|
136
|
+
limitations: [
|
|
137
|
+
'Audits live links and drafts additive bio/README improvements without mutating remote repositories directly in Profile Update Plans; full-account gh CLI repo audits, metadata/README marketing mutations, tiered repo cleanup (private/archive/gated delete), and context/github-projects.md extraction delegate to skills/11-portfolio-and-github-auditor.md.',
|
|
138
|
+
],
|
|
139
|
+
field_mappings: {
|
|
140
|
+
bio: ['Bio', 'Tagline'],
|
|
141
|
+
projects: ['Project Title', 'Description', 'Live URL'],
|
|
142
|
+
},
|
|
143
|
+
}),
|
|
144
|
+
generic: Object.freeze({
|
|
145
|
+
platform_id: 'generic',
|
|
146
|
+
display_name: 'Generic / Unknown Web Profile',
|
|
147
|
+
supported_sections: ['headline', 'summary', 'experience', 'skills', 'links'],
|
|
148
|
+
capabilities: Object.freeze({ read: true, draft: true, fill: false, save: false, verify: false }),
|
|
149
|
+
required_permissions: ['explicit_owner_approve'],
|
|
150
|
+
requires_approval: true,
|
|
151
|
+
limitations: [
|
|
152
|
+
'Unknown platform fallback: read and draft-only preview; never assumes fill or save support.',
|
|
153
|
+
],
|
|
154
|
+
field_mappings: {},
|
|
155
|
+
}),
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
const PLATFORM_ALIASES = {
|
|
159
|
+
linkedin: 'linkedin',
|
|
160
|
+
wellfound: 'wellfound',
|
|
161
|
+
angellist: 'wellfound',
|
|
162
|
+
greenhouse: 'ats',
|
|
163
|
+
lever: 'ats',
|
|
164
|
+
ashby: 'ats',
|
|
165
|
+
workable: 'ats',
|
|
166
|
+
smartrecruiters: 'ats',
|
|
167
|
+
breezyhr: 'ats',
|
|
168
|
+
ats: 'ats',
|
|
169
|
+
indeed: 'job_boards',
|
|
170
|
+
glassdoor: 'job_boards',
|
|
171
|
+
wuzzuf: 'job_boards',
|
|
172
|
+
bayt: 'job_boards',
|
|
173
|
+
gulftalent: 'job_boards',
|
|
174
|
+
stepstone: 'job_boards',
|
|
175
|
+
naukri: 'job_boards',
|
|
176
|
+
remoteok: 'job_boards',
|
|
177
|
+
job_boards: 'job_boards',
|
|
178
|
+
github: 'portfolio',
|
|
179
|
+
portfolio: 'portfolio',
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
export function getPlatformAdapter(platformId) {
|
|
183
|
+
const key = String(platformId || '').trim().toLowerCase();
|
|
184
|
+
const resolved = PLATFORM_ALIASES[key] || (PLATFORM_ADAPTERS[key] ? key : 'generic');
|
|
185
|
+
const base = PLATFORM_ADAPTERS[resolved];
|
|
186
|
+
return {
|
|
187
|
+
...base,
|
|
188
|
+
unknown_platform_fallback: resolved === 'generic' && key !== 'generic',
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function isPlainObject(v) {
|
|
193
|
+
return Boolean(v) && typeof v === 'object' && !Array.isArray(v);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function isNonEmptyString(v) {
|
|
197
|
+
return typeof v === 'string' && v.trim().length > 0;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function isValidHttpUrl(v) {
|
|
201
|
+
if (typeof v !== 'string' || !v.trim()) return false;
|
|
202
|
+
try {
|
|
203
|
+
const parsed = new URL(v);
|
|
204
|
+
return parsed.protocol === 'https:' || parsed.protocol === 'http:';
|
|
205
|
+
} catch {
|
|
206
|
+
return false;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
const ISO_DATETIME_RE = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$/;
|
|
211
|
+
|
|
212
|
+
function isValidIsoDateTime(v) {
|
|
213
|
+
return typeof v === 'string' && ISO_DATETIME_RE.test(v) && !Number.isNaN(Date.parse(v));
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function escapeRegExp(str) {
|
|
217
|
+
return String(str).replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function buildWordRegex(term) {
|
|
221
|
+
const escaped = escapeRegExp(term);
|
|
222
|
+
const left = /^[A-Za-z0-9_]/.test(term) ? '(?<![A-Za-z0-9_])' : '(?<!\\.)';
|
|
223
|
+
const right = /[A-Za-z0-9_]$/.test(term) ? '(?![A-Za-z0-9_])' : '(?![A-Za-z0-9_+])';
|
|
224
|
+
return new RegExp(`${left}${escaped}${right}`, 'i');
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
const PLAN_ALLOWED_KEYS = new Set([
|
|
228
|
+
'schema_version',
|
|
229
|
+
'plan_id',
|
|
230
|
+
'target_role',
|
|
231
|
+
'target_job_url',
|
|
232
|
+
'platform',
|
|
233
|
+
'profile_url',
|
|
234
|
+
'mode',
|
|
235
|
+
'created_at',
|
|
236
|
+
'adapter',
|
|
237
|
+
'missing_facts',
|
|
238
|
+
'skipped_unchanged',
|
|
239
|
+
'verification_summary',
|
|
240
|
+
'changes',
|
|
241
|
+
]);
|
|
242
|
+
|
|
243
|
+
const ADAPTER_ALLOWED_KEYS = new Set(['platform_id', 'capabilities', 'requires_approval', 'limitations']);
|
|
244
|
+
const CAPABILITY_KEYS = ['read', 'draft', 'fill', 'save', 'verify'];
|
|
245
|
+
const CAPABILITY_KEY_SET = new Set(CAPABILITY_KEYS);
|
|
246
|
+
const VERIFICATION_SUMMARY_ALLOWED_KEYS = new Set(['outcome', 'verified_count', 'total_changes', 'verified_at', 'notes']);
|
|
247
|
+
|
|
248
|
+
const CHANGE_ALLOWED_KEYS = new Set([
|
|
249
|
+
'section',
|
|
250
|
+
'field',
|
|
251
|
+
'action',
|
|
252
|
+
'before',
|
|
253
|
+
'after',
|
|
254
|
+
'reason',
|
|
255
|
+
'evidence',
|
|
256
|
+
'confidence',
|
|
257
|
+
'requires_confirmation',
|
|
258
|
+
'fact_basis',
|
|
259
|
+
'adapter_capability',
|
|
260
|
+
'verification_evidence',
|
|
261
|
+
'status',
|
|
262
|
+
]);
|
|
263
|
+
|
|
264
|
+
const METRIC_TOKEN_RE = /(?<![A-Za-z0-9_])\$?\d[\d,]*(?:\.\d+)?(?:\s*(?:%|k|m|b|x|ms|sec|seconds|min|minutes|hrs|hours|days|weeks|months|years)\b|%|[KMBX]\b|\+)?/gi;
|
|
265
|
+
|
|
266
|
+
export function validateProfileUpdatePlan(plan, { factsConfig = null, bannedCliches = DEFAULT_BANNED_CLICHES } = {}) {
|
|
267
|
+
const errors = [];
|
|
268
|
+
const warnings = [];
|
|
269
|
+
|
|
270
|
+
if (!isPlainObject(plan)) {
|
|
271
|
+
return { valid: false, errors: ['Profile update plan root must be a JSON object.'], warnings };
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
for (const k of Object.keys(plan)) {
|
|
275
|
+
if (!PLAN_ALLOWED_KEYS.has(k)) {
|
|
276
|
+
errors.push(`Unexpected top-level property "${k}" in profile update plan.`);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
if (plan.schema_version !== '1.0') {
|
|
281
|
+
errors.push(`schema_version must be "1.0" (got ${JSON.stringify(plan.schema_version)}).`);
|
|
282
|
+
}
|
|
283
|
+
if (plan.plan_id !== undefined && !isNonEmptyString(plan.plan_id)) {
|
|
284
|
+
errors.push('plan_id must be a non-empty string when provided.');
|
|
285
|
+
}
|
|
286
|
+
for (const reqKey of ['target_role', 'platform']) {
|
|
287
|
+
if (!isNonEmptyString(plan[reqKey])) {
|
|
288
|
+
errors.push(`${reqKey} must be a non-empty string.`);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
for (const urlKey of ['profile_url', 'target_job_url']) {
|
|
292
|
+
if (plan[urlKey] !== undefined && plan[urlKey] !== null && !isValidHttpUrl(plan[urlKey])) {
|
|
293
|
+
errors.push(`${urlKey} must be a valid http(s) URL or null.`);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
if (plan.created_at !== undefined && !isValidIsoDateTime(plan.created_at)) {
|
|
297
|
+
errors.push('created_at must be a valid ISO-8601 date-time string when provided.');
|
|
298
|
+
}
|
|
299
|
+
for (const arrKey of ['missing_facts', 'skipped_unchanged']) {
|
|
300
|
+
if (plan[arrKey] !== undefined) {
|
|
301
|
+
if (!Array.isArray(plan[arrKey]) || plan[arrKey].some(item => !isNonEmptyString(item))) {
|
|
302
|
+
errors.push(`${arrKey} must be an array of non-empty strings when provided.`);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
if (!ALLOWED_PLAN_MODES.includes(plan.mode)) {
|
|
307
|
+
errors.push(`mode must be one of ${ALLOWED_PLAN_MODES.join(', ')} (got ${JSON.stringify(plan.mode)}).`);
|
|
308
|
+
}
|
|
309
|
+
if (!Array.isArray(plan.changes)) {
|
|
310
|
+
errors.push('changes must be an array.');
|
|
311
|
+
return { valid: false, errors, warnings };
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
// Always resolve authoritative capabilities from the registered adapter registry.
|
|
315
|
+
const resolvedAdapter = getPlatformAdapter(plan.platform);
|
|
316
|
+
|
|
317
|
+
if (plan.adapter !== undefined) {
|
|
318
|
+
if (!isPlainObject(plan.adapter)) {
|
|
319
|
+
errors.push('adapter must be an object when provided.');
|
|
320
|
+
} else {
|
|
321
|
+
for (const k of Object.keys(plan.adapter)) {
|
|
322
|
+
if (!ADAPTER_ALLOWED_KEYS.has(k)) {
|
|
323
|
+
errors.push(`adapter: unexpected property "${k}".`);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
if (!isNonEmptyString(plan.adapter.platform_id)) {
|
|
327
|
+
errors.push('adapter.platform_id must be a non-empty string.');
|
|
328
|
+
}
|
|
329
|
+
if (!isPlainObject(plan.adapter.capabilities)) {
|
|
330
|
+
errors.push('adapter.capabilities must be an object.');
|
|
331
|
+
} else {
|
|
332
|
+
for (const k of Object.keys(plan.adapter.capabilities)) {
|
|
333
|
+
if (!CAPABILITY_KEY_SET.has(k)) {
|
|
334
|
+
errors.push(`adapter.capabilities: unexpected property "${k}".`);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
for (const cap of CAPABILITY_KEYS) {
|
|
338
|
+
if (typeof plan.adapter.capabilities[cap] !== 'boolean') {
|
|
339
|
+
errors.push(`adapter.capabilities.${cap} must be a boolean.`);
|
|
340
|
+
} else if (plan.adapter.capabilities[cap] === true && resolvedAdapter.capabilities[cap] === false) {
|
|
341
|
+
errors.push(
|
|
342
|
+
`adapter.capabilities.${cap} cannot exceed registered adapter "${resolvedAdapter.platform_id}" (registry sets ${cap}: false).`,
|
|
343
|
+
);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
if (typeof plan.adapter.requires_approval !== 'boolean') {
|
|
348
|
+
errors.push('adapter.requires_approval must be a boolean.');
|
|
349
|
+
} else if (plan.adapter.requires_approval === false && resolvedAdapter.requires_approval === true) {
|
|
350
|
+
errors.push(`adapter.requires_approval cannot bypass approval requirement of adapter "${resolvedAdapter.platform_id}".`);
|
|
351
|
+
}
|
|
352
|
+
if (plan.adapter.limitations !== undefined) {
|
|
353
|
+
if (!Array.isArray(plan.adapter.limitations) || plan.adapter.limitations.some(item => !isNonEmptyString(item))) {
|
|
354
|
+
errors.push('adapter.limitations must be an array of non-empty strings when provided.');
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
// Enforce capabilities from the registered adapter, never trusting omitted or spoofed plan.adapter.
|
|
361
|
+
const registryAllowsSave = resolvedAdapter.capabilities.save;
|
|
362
|
+
const registryAllowsFill = resolvedAdapter.capabilities.fill;
|
|
363
|
+
const registryAllowsVerify = resolvedAdapter.capabilities.verify;
|
|
364
|
+
|
|
365
|
+
plan.changes.forEach((ch, idx) => {
|
|
366
|
+
const label = `changes[${idx}]`;
|
|
367
|
+
if (!isPlainObject(ch)) {
|
|
368
|
+
errors.push(`${label} must be an object.`);
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
371
|
+
for (const k of Object.keys(ch)) {
|
|
372
|
+
if (!CHANGE_ALLOWED_KEYS.has(k)) {
|
|
373
|
+
errors.push(`${label}: unexpected property "${k}".`);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
for (const reqStr of ['section', 'field', 'after', 'reason']) {
|
|
377
|
+
if (!isNonEmptyString(ch[reqStr])) {
|
|
378
|
+
errors.push(`${label}.${reqStr} must be a non-empty string.`);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
if (ch.before !== null && typeof ch.before !== 'string') {
|
|
382
|
+
errors.push(`${label}.before must be a string or null.`);
|
|
383
|
+
}
|
|
384
|
+
if (!ALLOWED_CHANGE_ACTIONS.includes(ch.action)) {
|
|
385
|
+
errors.push(`${label}.action "${ch.action}" is not allowed; only ${ALLOWED_CHANGE_ACTIONS.join('/')} are supported (destructive remove is forbidden).`);
|
|
386
|
+
}
|
|
387
|
+
if (!Array.isArray(ch.evidence) || ch.evidence.length === 0 || ch.evidence.some(e => !isNonEmptyString(e))) {
|
|
388
|
+
errors.push(`${label}.evidence must be a non-empty array of non-empty strings.`);
|
|
389
|
+
}
|
|
390
|
+
if (typeof ch.confidence !== 'number' || !Number.isFinite(ch.confidence) || ch.confidence < 0 || ch.confidence > 1) {
|
|
391
|
+
errors.push(`${label}.confidence must be a number between 0 and 1.`);
|
|
392
|
+
}
|
|
393
|
+
if (typeof ch.requires_confirmation !== 'boolean') {
|
|
394
|
+
errors.push(`${label}.requires_confirmation must be a boolean.`);
|
|
395
|
+
}
|
|
396
|
+
if (!ALLOWED_FACT_BASES.includes(ch.fact_basis)) {
|
|
397
|
+
errors.push(`${label}.fact_basis must be one of ${ALLOWED_FACT_BASES.join(', ')}.`);
|
|
398
|
+
}
|
|
399
|
+
if (ch.adapter_capability !== undefined) {
|
|
400
|
+
if (!ALLOWED_ADAPTER_CAPABILITIES.includes(ch.adapter_capability)) {
|
|
401
|
+
errors.push(`${label}.adapter_capability must be one of ${ALLOWED_ADAPTER_CAPABILITIES.join(', ')}.`);
|
|
402
|
+
} else if (ch.adapter_capability === 'fill_supported' && !registryAllowsFill) {
|
|
403
|
+
errors.push(`${label}.adapter_capability "fill_supported" exceeds registered adapter "${resolvedAdapter.platform_id}" (fill: false).`);
|
|
404
|
+
} else if (ch.adapter_capability === 'save_and_verify_supported' && (!registryAllowsSave || !registryAllowsVerify)) {
|
|
405
|
+
errors.push(`${label}.adapter_capability "save_and_verify_supported" exceeds registered adapter "${resolvedAdapter.platform_id}".`);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
if (ch.verification_evidence !== undefined && ch.verification_evidence !== null && typeof ch.verification_evidence !== 'string') {
|
|
409
|
+
errors.push(`${label}.verification_evidence must be a string or null.`);
|
|
410
|
+
}
|
|
411
|
+
if (!ALLOWED_CHANGE_STATUSES.includes(ch.status)) {
|
|
412
|
+
errors.push(`${label}.status "${ch.status}" is invalid.`);
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
// Add / replace semantics
|
|
416
|
+
if (ch.action === 'add' && typeof ch.before === 'string' && ch.before.trim().length > 0) {
|
|
417
|
+
errors.push(`${label}: action "add" must not have an existing non-empty "before" value; use "replace" instead.`);
|
|
418
|
+
}
|
|
419
|
+
if (ch.action === 'replace' && (ch.before === null || (typeof ch.before === 'string' && ch.before.trim().length === 0))) {
|
|
420
|
+
errors.push(`${label}: action "replace" requires an existing non-empty "before" value; use "add" instead.`);
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
// Fact integrity: inferred claims cannot bypass confirmation or reach live states
|
|
424
|
+
if (ch.fact_basis === 'inferred') {
|
|
425
|
+
if (ch.requires_confirmation !== true) {
|
|
426
|
+
errors.push(`${label}: inferred claim requires_confirmation must be true.`);
|
|
427
|
+
}
|
|
428
|
+
if (ch.status === 'approved' || ch.status === 'applied' || ch.status === 'verified') {
|
|
429
|
+
errors.push(`${label}: inferred claim cannot have status "${ch.status}" without user confirmation.`);
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
// Draft-first & review-mode lifecycle safety
|
|
434
|
+
if (plan.mode === 'draft_only' && (ch.status === 'approved' || ch.status === 'applied' || ch.status === 'verified')) {
|
|
435
|
+
errors.push(`${label}: mode "draft_only" cannot contain status "${ch.status}".`);
|
|
436
|
+
}
|
|
437
|
+
if (plan.mode === 'review' && (ch.status === 'applied' || ch.status === 'verified')) {
|
|
438
|
+
errors.push(`${label}: mode "review" cannot contain live status "${ch.status}" before approved_apply.`);
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
// Authoritative registry save capability guard
|
|
442
|
+
if (!registryAllowsSave && (ch.status === 'applied' || ch.status === 'verified')) {
|
|
443
|
+
errors.push(
|
|
444
|
+
`${label}: platform "${plan.platform}" (adapter "${resolvedAdapter.platform_id}") does not support save; status "${ch.status}" is unauthorized.`,
|
|
445
|
+
);
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
// Truthful verification guard
|
|
449
|
+
if (ch.status === 'verified' && !isNonEmptyString(ch.verification_evidence)) {
|
|
450
|
+
errors.push(`${label}: status "verified" requires non-empty verification_evidence from a fresh read-back.`);
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
// Efficiency: skip unchanged fields instead of emitting no-op edits
|
|
454
|
+
if (ch.action === 'replace' && typeof ch.before === 'string' && typeof ch.after === 'string' && ch.before.trim() === ch.after.trim()) {
|
|
455
|
+
errors.push(`${label}: unchanged field ("before" equals "after") must be skipped into skipped_unchanged instead of planned as a change.`);
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
// Hygiene & anti-hallucination checks on proposed text
|
|
459
|
+
if (typeof ch.after === 'string') {
|
|
460
|
+
if (/\{\{[A-Za-z0-9_]+\}\}/.test(ch.after)) {
|
|
461
|
+
errors.push(`${label}.after contains unresolved template placeholder.`);
|
|
462
|
+
}
|
|
463
|
+
if (ch.after.includes('—')) {
|
|
464
|
+
errors.push(`${label}.after contains prose em-dash (—).`);
|
|
465
|
+
}
|
|
466
|
+
const foundCliches = bannedCliches.filter(cl => buildWordRegex(cl).test(ch.after));
|
|
467
|
+
if (foundCliches.length > 0) {
|
|
468
|
+
errors.push(`${label}.after contains banned AI cliché(s): ${foundCliches.join(', ')}.`);
|
|
469
|
+
}
|
|
470
|
+
if (factsConfig) {
|
|
471
|
+
const metrics = ch.after.match(METRIC_TOKEN_RE) || [];
|
|
472
|
+
const unverified = metrics.filter(m => !factsConfig.allowedMetrics.has(m.trim().toLowerCase()));
|
|
473
|
+
if (unverified.length > 0) {
|
|
474
|
+
errors.push(`${label}.after contains unverified metric(s): ${[...new Set(unverified)].join(', ')}.`);
|
|
475
|
+
}
|
|
476
|
+
const forbidden = (factsConfig.forbiddenSkills || []).filter(sk => buildWordRegex(sk).test(ch.after));
|
|
477
|
+
if (forbidden.length > 0) {
|
|
478
|
+
errors.push(`${label}.after claims forbidden/unverified skill(s): ${forbidden.join(', ')}.`);
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
});
|
|
483
|
+
|
|
484
|
+
if (plan.verification_summary !== undefined) {
|
|
485
|
+
const vs = plan.verification_summary;
|
|
486
|
+
if (!isPlainObject(vs)) {
|
|
487
|
+
errors.push('verification_summary must be an object.');
|
|
488
|
+
} else {
|
|
489
|
+
for (const k of Object.keys(vs)) {
|
|
490
|
+
if (!VERIFICATION_SUMMARY_ALLOWED_KEYS.has(k)) {
|
|
491
|
+
errors.push(`verification_summary: unexpected property "${k}".`);
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
if (!ALLOWED_VERIFICATION_OUTCOMES.includes(vs.outcome)) {
|
|
495
|
+
errors.push(`verification_summary.outcome "${vs.outcome}" is invalid.`);
|
|
496
|
+
}
|
|
497
|
+
if (!Number.isInteger(vs.verified_count) || vs.verified_count < 0) {
|
|
498
|
+
errors.push('verification_summary.verified_count must be an integer >= 0.');
|
|
499
|
+
}
|
|
500
|
+
if (!Number.isInteger(vs.total_changes) || vs.total_changes < 0) {
|
|
501
|
+
errors.push('verification_summary.total_changes must be an integer >= 0.');
|
|
502
|
+
}
|
|
503
|
+
if (Number.isInteger(vs.verified_count) && Number.isInteger(vs.total_changes) && vs.verified_count > vs.total_changes) {
|
|
504
|
+
errors.push('verification_summary.verified_count cannot exceed total_changes.');
|
|
505
|
+
}
|
|
506
|
+
if (vs.verified_at !== undefined && vs.verified_at !== null && !isValidIsoDateTime(vs.verified_at)) {
|
|
507
|
+
errors.push('verification_summary.verified_at must be a valid ISO-8601 date-time string or null.');
|
|
508
|
+
}
|
|
509
|
+
if (vs.notes !== undefined && typeof vs.notes !== 'string') {
|
|
510
|
+
errors.push('verification_summary.notes must be a string when provided.');
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
return { valid: errors.length === 0, errors, warnings };
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
export function validateProfileVault(profileData) {
|
|
519
|
+
const errors = [];
|
|
520
|
+
const warnings = [];
|
|
521
|
+
if (!isPlainObject(profileData)) {
|
|
522
|
+
return { valid: false, errors: ['Profile data must be an object.'], warnings };
|
|
523
|
+
}
|
|
524
|
+
const prov = profileData.fact_provenance;
|
|
525
|
+
if (prov !== undefined) {
|
|
526
|
+
if (!isPlainObject(prov)) {
|
|
527
|
+
errors.push('fact_provenance must be an object.');
|
|
528
|
+
} else {
|
|
529
|
+
const verifiedClaims = new Set();
|
|
530
|
+
if (prov.verified_facts !== undefined) {
|
|
531
|
+
if (!Array.isArray(prov.verified_facts)) {
|
|
532
|
+
errors.push('fact_provenance.verified_facts must be an array.');
|
|
533
|
+
} else {
|
|
534
|
+
prov.verified_facts.forEach((item, idx) => {
|
|
535
|
+
if (!isPlainObject(item) || !isNonEmptyString(item.claim)) {
|
|
536
|
+
errors.push(`fact_provenance.verified_facts[${idx}] must include a non-empty claim.`);
|
|
537
|
+
return;
|
|
538
|
+
}
|
|
539
|
+
if (!isNonEmptyString(item.source)) {
|
|
540
|
+
errors.push(`fact_provenance.verified_facts[${idx}] must include a non-empty source.`);
|
|
541
|
+
}
|
|
542
|
+
if (item.verified_at !== undefined && item.verified_at !== null && !isValidIsoDateTime(item.verified_at)) {
|
|
543
|
+
errors.push(`fact_provenance.verified_facts[${idx}].verified_at must be a valid ISO-8601 date-time or null.`);
|
|
544
|
+
}
|
|
545
|
+
verifiedClaims.add(item.claim.trim().toLowerCase());
|
|
546
|
+
});
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
const confirmedClaims = new Set();
|
|
551
|
+
if (prov.user_confirmed_facts !== undefined) {
|
|
552
|
+
if (!Array.isArray(prov.user_confirmed_facts)) {
|
|
553
|
+
errors.push('fact_provenance.user_confirmed_facts must be an array.');
|
|
554
|
+
} else {
|
|
555
|
+
prov.user_confirmed_facts.forEach((item, idx) => {
|
|
556
|
+
if (!isPlainObject(item) || !isNonEmptyString(item.claim)) {
|
|
557
|
+
errors.push(`fact_provenance.user_confirmed_facts[${idx}] must include a non-empty claim.`);
|
|
558
|
+
return;
|
|
559
|
+
}
|
|
560
|
+
if (!isValidIsoDateTime(item.confirmed_at)) {
|
|
561
|
+
errors.push(`fact_provenance.user_confirmed_facts[${idx}].confirmed_at must be a valid ISO-8601 date-time.`);
|
|
562
|
+
}
|
|
563
|
+
confirmedClaims.add(item.claim.trim().toLowerCase());
|
|
564
|
+
});
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
if (prov.inferred_info !== undefined) {
|
|
569
|
+
if (!Array.isArray(prov.inferred_info)) {
|
|
570
|
+
errors.push('fact_provenance.inferred_info must be an array.');
|
|
571
|
+
} else {
|
|
572
|
+
prov.inferred_info.forEach((item, idx) => {
|
|
573
|
+
if (!isPlainObject(item) || !isNonEmptyString(item.claim)) {
|
|
574
|
+
errors.push(`fact_provenance.inferred_info[${idx}] must include a non-empty claim.`);
|
|
575
|
+
return;
|
|
576
|
+
}
|
|
577
|
+
if (!isNonEmptyString(item.basis)) {
|
|
578
|
+
errors.push(`fact_provenance.inferred_info[${idx}] must include a non-empty basis.`);
|
|
579
|
+
}
|
|
580
|
+
if (item.requires_confirmation !== true) {
|
|
581
|
+
errors.push(`fact_provenance.inferred_info[${idx}] must keep requires_confirmation: true.`);
|
|
582
|
+
}
|
|
583
|
+
const normClaim = item.claim.trim().toLowerCase();
|
|
584
|
+
if (verifiedClaims.has(normClaim)) {
|
|
585
|
+
errors.push(`fact_provenance.inferred_info[${idx}] ("${item.claim}") cannot be simultaneously listed in verified_facts without removing from inferred_info after confirmation.`);
|
|
586
|
+
}
|
|
587
|
+
if (confirmedClaims.has(normClaim)) {
|
|
588
|
+
errors.push(`fact_provenance.inferred_info[${idx}] ("${item.claim}") overlaps with user_confirmed_facts; remove from inferred_info once confirmed.`);
|
|
589
|
+
}
|
|
590
|
+
});
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
if (prov.missing_info !== undefined) {
|
|
595
|
+
if (!Array.isArray(prov.missing_info) || prov.missing_info.some(item => !isNonEmptyString(item))) {
|
|
596
|
+
errors.push('fact_provenance.missing_info must be an array of non-empty strings.');
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
if (prov.proposed_improvements !== undefined) {
|
|
601
|
+
if (!Array.isArray(prov.proposed_improvements)) {
|
|
602
|
+
errors.push('fact_provenance.proposed_improvements must be an array.');
|
|
603
|
+
} else {
|
|
604
|
+
prov.proposed_improvements.forEach((item, idx) => {
|
|
605
|
+
if (!isPlainObject(item) || !isNonEmptyString(item.field) || !isNonEmptyString(item.proposal) || !isNonEmptyString(item.reason)) {
|
|
606
|
+
errors.push(`fact_provenance.proposed_improvements[${idx}] must include non-empty field, proposal, and reason.`);
|
|
607
|
+
}
|
|
608
|
+
});
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
return { valid: errors.length === 0, errors, warnings };
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
export function formatConsolidatedReview(plan) {
|
|
617
|
+
const escapeCell = v => String(v ?? '').replace(/\\/g, '\\\\').replace(/\|/g, '\\|').replace(/\r?\n/g, ' ');
|
|
618
|
+
const lines = [
|
|
619
|
+
`# Consolidated Profile Update Review — ${plan.platform} (${plan.target_role})`,
|
|
620
|
+
'',
|
|
621
|
+
`- **Mode:** \`${plan.mode}\` (draft-first; no live writes until approved)`,
|
|
622
|
+
`- **Changes Planned:** ${Array.isArray(plan.changes) ? plan.changes.length : 0}`,
|
|
623
|
+
`- **Skipped Unchanged:** ${Array.isArray(plan.skipped_unchanged) ? plan.skipped_unchanged.length : 0}`,
|
|
624
|
+
'',
|
|
625
|
+
'| # | Section | Field | Action | Before | After | Reason | Evidence | Confidence | Confirm? | Status |',
|
|
626
|
+
'|---|---|---|---|---|---|---|---|---|---|---|',
|
|
627
|
+
];
|
|
628
|
+
|
|
629
|
+
(plan.changes || []).forEach((ch, idx) => {
|
|
630
|
+
lines.push(
|
|
631
|
+
`| ${idx + 1} | ${escapeCell(ch.section)} | ${escapeCell(ch.field)} | \`${ch.action}\` | ${escapeCell(ch.before ?? '(empty)')} | ${escapeCell(ch.after)} | ${escapeCell(ch.reason)} | ${escapeCell((ch.evidence || []).join('; '))} | ${ch.confidence} | ${ch.requires_confirmation ? 'Yes' : 'No'} | \`${ch.status}\` |`,
|
|
632
|
+
);
|
|
633
|
+
});
|
|
634
|
+
|
|
635
|
+
if (Array.isArray(plan.missing_facts) && plan.missing_facts.length > 0) {
|
|
636
|
+
lines.push('', '## Missing Facts Requiring Confirmation', ...plan.missing_facts.map(m => `- ${m}`));
|
|
637
|
+
}
|
|
638
|
+
if (Array.isArray(plan.skipped_unchanged) && plan.skipped_unchanged.length > 0) {
|
|
639
|
+
lines.push('', '## Skipped Unchanged Fields', ...plan.skipped_unchanged.map(s => `- ${s}`));
|
|
640
|
+
}
|
|
641
|
+
lines.push(
|
|
642
|
+
'',
|
|
643
|
+
'## Approval Options',
|
|
644
|
+
'- Reply `APPROVE ALL` to authorize approved batch execution, `REJECT ALL` to discard, or specify item numbers (e.g., `APPROVE 1,3 / REJECT 2`).',
|
|
645
|
+
);
|
|
646
|
+
return lines.join('\n');
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
export function summarizeVerificationOutcome(plan) {
|
|
650
|
+
const changes = Array.isArray(plan?.changes) ? plan.changes : [];
|
|
651
|
+
const total = changes.length;
|
|
652
|
+
const counts = {
|
|
653
|
+
verified: 0,
|
|
654
|
+
applied: 0,
|
|
655
|
+
approved: 0,
|
|
656
|
+
blocked: 0,
|
|
657
|
+
not_verified: 0,
|
|
658
|
+
needs_review: 0,
|
|
659
|
+
draft: 0,
|
|
660
|
+
needs_user_confirmation: 0,
|
|
661
|
+
};
|
|
662
|
+
for (const ch of changes) {
|
|
663
|
+
if (counts[ch?.status] !== undefined) counts[ch.status]++;
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
let outcome = 'prepared';
|
|
667
|
+
if (total > 0) {
|
|
668
|
+
if (counts.verified === total) outcome = 'verified';
|
|
669
|
+
else if (counts.applied === total) outcome = 'applied';
|
|
670
|
+
else if (counts.blocked === total) outcome = 'blocked';
|
|
671
|
+
else if (counts.not_verified === total) outcome = 'not_verified';
|
|
672
|
+
else if (counts.approved === total) outcome = 'approved';
|
|
673
|
+
else if (counts.verified > 0 || counts.applied > 0) outcome = 'partially_applied';
|
|
674
|
+
else if (counts.not_verified > 0) outcome = 'not_verified';
|
|
675
|
+
else if (counts.blocked > 0) outcome = 'blocked';
|
|
676
|
+
else outcome = 'prepared';
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
return {
|
|
680
|
+
outcome,
|
|
681
|
+
verified_count: counts.verified,
|
|
682
|
+
applied_count: counts.applied,
|
|
683
|
+
approved_count: counts.approved,
|
|
684
|
+
blocked_count: counts.blocked,
|
|
685
|
+
not_verified_count: counts.not_verified,
|
|
686
|
+
needs_review_count: counts.needs_review,
|
|
687
|
+
draft_count: counts.draft + counts.needs_user_confirmation,
|
|
688
|
+
total_changes: total,
|
|
689
|
+
};
|
|
690
|
+
}
|