@profullstack/gov-contracts 0.0.0-stage → 0.1.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/LICENSE +9 -0
- package/README.md +63 -2
- package/bin/gov-contracts.js +170 -0
- package/package.json +47 -4
- package/src/ai.js +46 -0
- package/src/app.js +266 -0
- package/src/auth.js +109 -0
- package/src/fit.js +178 -0
- package/src/http.js +86 -0
- package/src/index.js +9 -0
- package/src/mcp.js +117 -0
- package/src/pages.js +325 -0
- package/src/pipeline.js +118 -0
- package/src/propose.js +260 -0
- package/src/safety.js +48 -0
- package/src/server.js +15 -0
- package/src/service.js +27 -0
- package/src/sources/digest.js +119 -0
- package/src/sources/index.js +59 -0
- package/src/sources/lacounty.js +100 -0
- package/src/sources/sam.js +178 -0
- package/src/store.js +352 -0
- package/src/version.js +3 -0
package/src/pages.js
ADDED
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Server-rendered pages (no client framework). The queue cards follow myna's
|
|
3
|
+
* manual hand-off cards: what to do, the exact text to paste, a link to open,
|
|
4
|
+
* and Done / Dismiss with a note.
|
|
5
|
+
*/
|
|
6
|
+
import { footerHtml } from '@profullstack/footer';
|
|
7
|
+
import { HUMAN_ONLY } from './safety.js';
|
|
8
|
+
import { SITE } from './auth.js';
|
|
9
|
+
import { VERSION } from './version.js';
|
|
10
|
+
|
|
11
|
+
const HOST = new URL(SITE).host;
|
|
12
|
+
export const h = (v) => String(v ?? '').replace(/[&<>"']/g, (ch) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' })[ch]);
|
|
13
|
+
|
|
14
|
+
let pitFooter = { html: '', at: 0 };
|
|
15
|
+
/** pit.world network footer (pit.world, *.pit.world and Moshpit names). Server-side, cached 1 h, 3 s timeout, nothing on error. */
|
|
16
|
+
async function pitWorldFooter() {
|
|
17
|
+
if (process.env.GOV_OFFLINE === '1') return '';
|
|
18
|
+
if (Date.now() - pitFooter.at < 3600_000) return pitFooter.html;
|
|
19
|
+
try {
|
|
20
|
+
const r = await fetch(`https://pit.world/snippets/footer.html?site=${encodeURIComponent(HOST)}`, { signal: AbortSignal.timeout(3000) });
|
|
21
|
+
if (r.ok) pitFooter = { html: await r.text(), at: Date.now() };
|
|
22
|
+
else pitFooter.at = Date.now() - 3000_000;
|
|
23
|
+
} catch {
|
|
24
|
+
pitFooter.at = Date.now() - 3000_000;
|
|
25
|
+
}
|
|
26
|
+
return pitFooter.html;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
let ringFooter = { html: '', at: 0 };
|
|
30
|
+
/** Site links + the Profullstack webring row (server-rendered). */
|
|
31
|
+
async function siteFooter() {
|
|
32
|
+
if (ringFooter.html && Date.now() - ringFooter.at < 900_000) return ringFooter.html;
|
|
33
|
+
const fallback = '<footer class="foot"><p>gov.procurement · <a href="/docs">Docs</a> · <a href="/llms.txt">llms.txt</a></p></footer>';
|
|
34
|
+
if (process.env.GOV_OFFLINE === '1') return fallback;
|
|
35
|
+
try {
|
|
36
|
+
const html = await footerHtml({
|
|
37
|
+
site: SITE,
|
|
38
|
+
name: 'gov.procurement',
|
|
39
|
+
since: 2026,
|
|
40
|
+
links: [
|
|
41
|
+
{ label: 'Docs', href: '/docs' },
|
|
42
|
+
{ label: 'MCP', href: '/docs#mcp' },
|
|
43
|
+
{ label: 'llms.txt', href: '/llms.txt' },
|
|
44
|
+
{ label: 'Source', href: 'https://github.com/profullstack/gov-contracts' },
|
|
45
|
+
],
|
|
46
|
+
});
|
|
47
|
+
ringFooter = { html, at: Date.now() };
|
|
48
|
+
} catch {
|
|
49
|
+
ringFooter = { html: fallback, at: Date.now() - 600_000 };
|
|
50
|
+
}
|
|
51
|
+
return ringFooter.html;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const CSS = `
|
|
55
|
+
:root{--bg:#0c0f14;--fg:#e8edf4;--mute:#97a3b3;--acc:#ffb547;--acc2:#6cc6ff;--card:#141922;--line:#263041;--ok:#5be08a;--bad:#ff7a7a}
|
|
56
|
+
@media (prefers-color-scheme: light){:root{--bg:#f7f8fb;--fg:#121722;--mute:#566173;--acc:#b86b00;--acc2:#0b6fb0;--card:#fff;--line:#dde3ec;--ok:#167a3e;--bad:#b42323}}
|
|
57
|
+
*{box-sizing:border-box}html{-webkit-text-size-adjust:100%}
|
|
58
|
+
body{margin:0;background:var(--bg);color:var(--fg);font:16px/1.55 system-ui,-apple-system,Segoe UI,Roboto,sans-serif}
|
|
59
|
+
a{color:var(--acc2)}code,pre,textarea{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:13.5px}
|
|
60
|
+
header.top,main{max-width:1100px;margin:0 auto;padding:0 16px}
|
|
61
|
+
header.top{display:flex;justify-content:space-between;align-items:center;gap:12px;flex-wrap:wrap;padding-top:16px;padding-bottom:6px}
|
|
62
|
+
.brand{font-weight:800;font-size:20px;text-decoration:none;color:var(--fg)}.brand span{color:var(--acc)}
|
|
63
|
+
nav a{margin-left:14px;text-decoration:none}
|
|
64
|
+
h1{font-size:clamp(26px,4.6vw,42px);line-height:1.12;margin:26px 0 10px}h2{margin:28px 0 10px}
|
|
65
|
+
.lede{color:var(--mute);font-size:18px;max-width:780px}
|
|
66
|
+
.pill{display:inline-block;border:1px solid var(--line);border-radius:999px;padding:1px 9px;font-size:12px;color:var(--mute);margin-right:4px}
|
|
67
|
+
.pill.fit{color:var(--bg);background:var(--acc);border-color:var(--acc);font-weight:700}
|
|
68
|
+
.stats{display:grid;grid-template-columns:repeat(auto-fit,minmax(150px,1fr));gap:12px;margin:18px 0}
|
|
69
|
+
.stat{background:var(--card);border:1px solid var(--line);border-radius:12px;padding:12px}.stat b{display:block;font-size:26px}.stat span{color:var(--mute);font-size:13px}
|
|
70
|
+
table{border-collapse:collapse;width:100%;font-size:14px}td,th{border-bottom:1px solid var(--line);padding:8px;text-align:left;vertical-align:top}th{color:var(--mute);font-weight:600}
|
|
71
|
+
.tw{overflow-x:auto}
|
|
72
|
+
.cards{display:grid;gap:14px;margin:16px 0}
|
|
73
|
+
.card{background:var(--card);border:1px solid var(--line);border-radius:14px;padding:16px}
|
|
74
|
+
.card .eyebrow{font-size:12px;letter-spacing:.06em;text-transform:uppercase;color:var(--acc);font-weight:700}
|
|
75
|
+
.card h3{margin:4px 0 8px;font-size:18px}.card .meta{color:var(--mute);font-size:13px;margin-bottom:8px}
|
|
76
|
+
.card ol,.card ul{margin:6px 0 10px 20px;padding:0}
|
|
77
|
+
.card textarea{width:100%;min-height:180px;background:var(--bg);color:var(--fg);border:1px solid var(--line);border-radius:10px;padding:10px}
|
|
78
|
+
.row{display:flex;flex-wrap:wrap;gap:8px;align-items:center;margin-top:8px}
|
|
79
|
+
button,.btn{background:var(--card);color:var(--fg);border:1px solid var(--line);border-radius:9px;padding:8px 13px;font:inherit;cursor:pointer;text-decoration:none;display:inline-block}
|
|
80
|
+
.btn.primary,button.primary{background:var(--acc);color:#111;border-color:var(--acc);font-weight:700}
|
|
81
|
+
input[type=text],input[type=search],select{background:var(--card);color:var(--fg);border:1px solid var(--line);border-radius:9px;padding:8px 10px;font:inherit}
|
|
82
|
+
.note{color:var(--mute);font-size:14px}.warn{border-left:4px solid var(--acc);padding:8px 12px;background:var(--card);border-radius:8px}
|
|
83
|
+
.err{color:var(--bad)}.ok{color:var(--ok)}
|
|
84
|
+
pre{background:var(--card);border:1px solid var(--line);border-radius:10px;padding:14px;overflow:auto;white-space:pre-wrap}
|
|
85
|
+
.foot{max-width:1100px;margin:40px auto 0;padding:0 16px;color:var(--mute)}
|
|
86
|
+
`;
|
|
87
|
+
|
|
88
|
+
async function layout({ title, description, path = '/', signedIn = null }, body) {
|
|
89
|
+
const [site, pit] = await Promise.all([siteFooter(), pitWorldFooter()]);
|
|
90
|
+
const auth = signedIn ? `<a href="/queue">Queue</a><a href="/signout">Sign out</a>` : `<a href="/signin?next=/queue">Sign in with CoinPay</a>`;
|
|
91
|
+
return `<!doctype html>
|
|
92
|
+
<html lang="en">
|
|
93
|
+
<head>
|
|
94
|
+
<meta charset="utf-8">
|
|
95
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
96
|
+
<title>${h(title)}</title>
|
|
97
|
+
<meta name="description" content="${h(description)}">
|
|
98
|
+
<link rel="canonical" href="${h(SITE.replace(/\/$/, '') + path)}">
|
|
99
|
+
<meta property="og:title" content="${h(title)}"><meta property="og:description" content="${h(description)}"><meta property="og:site_name" content="gov.procurement">
|
|
100
|
+
<meta name="theme-color" content="#0c0f14">
|
|
101
|
+
<link rel="manifest" href="/manifest.webmanifest">
|
|
102
|
+
<link rel="icon" href="/icon.svg" type="image/svg+xml">
|
|
103
|
+
<link rel="alternate" type="text/plain" href="/llms.txt" title="llms.txt">
|
|
104
|
+
<style>${CSS}</style>
|
|
105
|
+
<script type="module" data-webmcp src="https://cdn.jsdelivr.net/npm/@profullstack/webmcp@0.2.1/src/embed.js" data-mcp="/mcp" data-pages='{"home":"/","solicitations":"/solicitations","docs":"/docs"}'></script>
|
|
106
|
+
</head>
|
|
107
|
+
<body>
|
|
108
|
+
<header class="top"><a class="brand" href="/">gov<span>.procurement</span></a><nav><a href="/solicitations">Solicitations</a><a href="/docs">Docs</a>${auth}</nav></header>
|
|
109
|
+
<main>${body}</main>
|
|
110
|
+
${site}
|
|
111
|
+
${pit}
|
|
112
|
+
<script>if('serviceWorker' in navigator)navigator.serviceWorker.register('/sw.js').catch(()=>{});</script>
|
|
113
|
+
</body>
|
|
114
|
+
</html>`;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** Tiny markdown for card bodies: paragraphs, numbered and bullet lists. */
|
|
118
|
+
export function mdLite(text) {
|
|
119
|
+
const out = [];
|
|
120
|
+
let list = null;
|
|
121
|
+
const close = () => { if (list) { out.push(`</${list}>`); list = null; } };
|
|
122
|
+
for (const raw of String(text || '').split('\n')) {
|
|
123
|
+
const line = raw.trim();
|
|
124
|
+
const num = /^\d+\.\s+(.*)$/.exec(line);
|
|
125
|
+
const bul = /^[-*]\s+(.*)$/.exec(line);
|
|
126
|
+
if (num) { if (list !== 'ol') { close(); out.push('<ol>'); list = 'ol'; } out.push(`<li>${h(num[1])}</li>`); }
|
|
127
|
+
else if (bul) { if (list !== 'ul') { close(); out.push('<ul>'); list = 'ul'; } out.push(`<li>${h(bul[1])}</li>`); }
|
|
128
|
+
else if (!line) close();
|
|
129
|
+
else { close(); out.push(`<p>${h(line)}</p>`); }
|
|
130
|
+
}
|
|
131
|
+
close();
|
|
132
|
+
return out.join('');
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const fitPill = (s) => (s.fit_score != null ? `<span class="pill fit" title="fit score">${h(s.fit_score)}</span>` : '');
|
|
136
|
+
const due = (d) => (d ? h(String(d).slice(0, 10)) : '');
|
|
137
|
+
|
|
138
|
+
function solTable(rows, { showFit }) {
|
|
139
|
+
if (!rows.length) return '<p class="note">Nothing here yet. The first ingest runs a minute after start; sources refresh every 6 hours.</p>';
|
|
140
|
+
return `<div class="tw"><table><thead><tr>${showFit ? '<th>Fit</th>' : ''}<th>Solicitation</th><th>Buyer</th><th>Due</th><th>Source</th></tr></thead><tbody>${rows
|
|
141
|
+
.map((s) => `<tr>${showFit ? `<td>${fitPill(s) || `<span class="pill">${h(s.status)}</span>`}</td>` : ''}<td><a href="/s/${encodeURIComponent(s.id)}">${h(s.title)}</a>${s.number ? `<div class="note">${h(s.number)}</div>` : ''}</td><td>${h(s.agency || '')}<div class="note">${h(s.level || '')}${s.region ? ' · ' + h(s.region) : ''}</div></td><td>${due(s.due_at)}</td><td>${h(s.source)}</td></tr>`)
|
|
142
|
+
.join('')}</tbody></table></div>`;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export async function homePage({ stats, top, signedIn, isOperator, error }) {
|
|
146
|
+
const body = `
|
|
147
|
+
${error ? `<p class="warn err">${h(error)}</p>` : ''}
|
|
148
|
+
<h1>Government contracts, read and drafted. Submitted by a person.</h1>
|
|
149
|
+
<p class="lede">gov.procurement watches federal, state, county and city bid sources, reads each RFP, scores how well it fits what we do (software, security, automation, hardware rental), drafts a compliant proposal and puts every step that needs a human into one queue: price it, sign the forms, register on the portal, review and submit.</p>
|
|
150
|
+
<div class="stats">
|
|
151
|
+
<div class="stat"><b>${h(stats.open_solicitations)}</b><span>open solicitations</span></div>
|
|
152
|
+
<div class="stat"><b>${h(stats.by_status?.scored || 0)}</b><span>scored, not drafted</span></div>
|
|
153
|
+
<div class="stat"><b>${h(stats.drafts)}</b><span>proposal drafts</span></div>
|
|
154
|
+
<div class="stat"><b>${h(stats.interventions_open)}</b><span>waiting on a person</span></div>
|
|
155
|
+
</div>
|
|
156
|
+
<p class="warn"><b>Never automatic:</b> ${Object.values(HUMAN_ONLY).join('; ')}. Those are queue cards only.</p>
|
|
157
|
+
<h2>${isOperator ? 'Best fits' : 'Recently found'}</h2>
|
|
158
|
+
${solTable(top, { showFit: isOperator })}
|
|
159
|
+
<p><a class="btn" href="/solicitations">All open solicitations</a> ${signedIn ? '<a class="btn primary" href="/queue">Open the queue</a>' : '<a class="btn primary" href="/signin?next=/queue">Sign in with CoinPay</a>'}</p>
|
|
160
|
+
<h2>Every surface</h2>
|
|
161
|
+
<p>HTTP API at <code>/api/v1</code>, MCP at <code>/mcp</code>, CLI and TUI: <code>npx @profullstack/gov-contracts</code> (or <code>curl -fsSL ${h(SITE)}install.sh | sh</code>), and this page installs as an app. Public reads are free (60 a minute); past that a $1 USDC day pass over CoinPay / x402.</p>`;
|
|
162
|
+
return layout({ title: 'gov.procurement: government contract opportunities, read and drafted', description: 'Find federal, state and local government contract opportunities, read the RFP, score the fit and draft a proposal. Every submission stays a human step.', signedIn }, body);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export async function solicitationsPage({ rows, q, level, source, signedIn, isOperator }) {
|
|
166
|
+
const opt = (v, cur, label) => `<option value="${h(v)}"${v === cur ? ' selected' : ''}>${h(label)}</option>`;
|
|
167
|
+
const body = `<h1>Open solicitations</h1>
|
|
168
|
+
<form class="row" method="get" action="/solicitations">
|
|
169
|
+
<input type="search" name="q" value="${h(q || '')}" placeholder="software, permit, cybersecurity..." aria-label="Search">
|
|
170
|
+
<select name="level" aria-label="Level">${opt('', level || '', 'Any level')}${['federal', 'state', 'county', 'city'].map((l) => opt(l, level, l)).join('')}</select>
|
|
171
|
+
<select name="source" aria-label="Source">${opt('', source || '', 'Any source')}${['sam', 'lacounty', 'digest'].map((l) => opt(l, source, l)).join('')}</select>
|
|
172
|
+
<button class="primary">Search</button></form>
|
|
173
|
+
${solTable(rows, { showFit: isOperator })}`;
|
|
174
|
+
return layout({ title: 'Open solicitations · gov.procurement', description: 'Open government contract opportunities.', path: '/solicitations', signedIn }, body);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export async function solicitationPage({ s, docs, proposal, isOperator, signedIn }) {
|
|
178
|
+
const contacts = (s.contacts || []).map((c) => `${h(c.name || '')}${c.email ? ` <${h(c.email)}>` : ''}${c.phone ? ` ${h(c.phone)}` : ''}`).join('<br>');
|
|
179
|
+
const fit = isOperator && s.fit
|
|
180
|
+
? `<div class="card"><div class="eyebrow">Fit ${h(s.fit_score)}/100 · ${h(s.fit.verdict || '')} · ${h(s.fit.method || '')}</div><p>${h(s.fit.summary || '')}</p>
|
|
181
|
+
${s.fit.why?.length ? `<b>Why</b><ul>${s.fit.why.map((x) => `<li>${h(x)}</li>`).join('')}</ul>` : ''}
|
|
182
|
+
${s.fit.risks?.length ? `<b>Risks</b><ul>${s.fit.risks.map((x) => `<li>${h(x)}</li>`).join('')}</ul>` : ''}
|
|
183
|
+
${s.fit.requirements?.length ? `<b>Requirements</b><ul>${s.fit.requirements.map((x) => `<li>${h(x)}</li>`).join('')}</ul>` : ''}
|
|
184
|
+
${s.fit.forms?.length ? `<b>Forms</b><ul>${s.fit.forms.map((x) => `<li>${h(x)}</li>`).join('')}</ul>` : ''}</div>`
|
|
185
|
+
: '';
|
|
186
|
+
const draftBtn = isOperator ? `<form method="post" action="/s/${encodeURIComponent(s.id)}/draft" class="row"><button class="primary">${proposal ? 'Draft again' : 'Draft a proposal'}</button>${proposal ? `<a class="btn" href="/p/${h(proposal.id)}">Proposal v${h(proposal.version)} (${h(proposal.status)})</a>` : ''}</form>` : '';
|
|
187
|
+
const body = `<p class="note"><a href="/solicitations">Solicitations</a> / ${h(s.source)}</p>
|
|
188
|
+
<h1>${h(s.title)}</h1>
|
|
189
|
+
<p><span class="pill">${h(s.level || '')}</span><span class="pill">${h(s.notice_type || 'notice')}</span>${s.set_aside ? `<span class="pill">${h(s.set_aside)}</span>` : ''}${s.naics ? `<span class="pill">NAICS ${h(s.naics)}</span>` : ''}</p>
|
|
190
|
+
<table><tbody>
|
|
191
|
+
<tr><th>Buyer</th><td>${h(s.agency || '')}</td></tr>
|
|
192
|
+
<tr><th>Number</th><td>${h(s.number || 'n/a')}</td></tr>
|
|
193
|
+
<tr><th>Due</th><td>${h(s.due_at || 'n/a')}</td></tr>
|
|
194
|
+
<tr><th>Official page</th><td>${s.url ? `<a href="${h(s.url)}" rel="noopener" target="_blank">${h(s.url)}</a>` : 'Not linked: find it on the buyer\'s procurement page.'}</td></tr>
|
|
195
|
+
${contacts ? `<tr><th>Contacts</th><td>${contacts}</td></tr>` : ''}
|
|
196
|
+
</tbody></table>
|
|
197
|
+
${fit}${draftBtn}
|
|
198
|
+
<h2>Notice</h2><pre>${h((s.description || '').slice(0, 8000))}</pre>
|
|
199
|
+
${docs.length ? `<h2>Documents read</h2><ul>${docs.map((d) => `<li>${d.url ? `<a href="${h(d.url)}" rel="noopener" target="_blank">${h(d.name || d.url)}</a>` : h(d.name || '')} <span class="note">${h(d.kind)}${d.text_chars ? ` · ${h(d.text_chars)} chars read` : ''}${d.error ? ` · <span class="err">${h(d.error)}</span>` : ''}</span></li>`).join('')}</ul>` : ''}`;
|
|
200
|
+
return layout({ title: `${s.title} · gov.procurement`, description: `${s.agency || ''} solicitation ${s.number || ''}, due ${s.due_at || 'n/a'}.`, path: `/s/${encodeURIComponent(s.id)}`, signedIn }, body);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const KIND_LABEL = {
|
|
204
|
+
submit_proposal: 'Review and submit',
|
|
205
|
+
set_price: 'Set the price',
|
|
206
|
+
sign_or_certify: 'Sign / certify',
|
|
207
|
+
register_vendor: 'Vendor registration',
|
|
208
|
+
decide_bid: 'Bid or no bid',
|
|
209
|
+
configure_source: 'Source setup',
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
export function cardHtml(iv) {
|
|
213
|
+
const resolved = iv.status !== 'open';
|
|
214
|
+
return `<article class="card" id="iv-${h(iv.id)}">
|
|
215
|
+
<div class="eyebrow">${h(KIND_LABEL[iv.kind] || iv.kind)}${iv.due_at ? ` · due ${due(iv.due_at)}` : ''}${iv.fit_score != null ? ` · fit ${h(iv.fit_score)}` : ''}${resolved ? ` · ${h(iv.status)}` : ''}</div>
|
|
216
|
+
<h3>${h(iv.title)}</h3>
|
|
217
|
+
${iv.agency ? `<div class="meta">${h(iv.agency)}${iv.number ? ` · ${h(iv.number)}` : ''}${iv.solicitation_id ? ` · <a href="/s/${encodeURIComponent(iv.solicitation_id)}">solicitation</a>` : ''}${iv.proposal_id ? ` · <a href="/p/${h(iv.proposal_id)}">proposal</a>` : ''}</div>` : ''}
|
|
218
|
+
${mdLite(iv.body)}
|
|
219
|
+
${iv.copy_text ? `<textarea readonly id="copy-${h(iv.id)}" aria-label="Text to copy">${h(iv.copy_text)}</textarea><div class="note">${h(iv.copy_text.length)} characters</div>` : ''}
|
|
220
|
+
<div class="row">
|
|
221
|
+
${iv.copy_text ? `<button type="button" data-copy="copy-${h(iv.id)}">Copy</button>` : ''}
|
|
222
|
+
${iv.open_url ? `<a class="btn" href="${h(iv.open_url)}" target="_blank" rel="noopener">Open</a>` : ''}
|
|
223
|
+
${iv.kind === 'decide_bid' && !resolved ? `<form method="post" action="/s/${encodeURIComponent(iv.solicitation_id)}/draft"><button class="primary">Draft it</button></form>` : ''}
|
|
224
|
+
</div>
|
|
225
|
+
${resolved ? `<p class="note">${h(iv.status)} ${iv.resolved_at ? h(iv.resolved_at.slice(0, 16).replace('T', ' ')) : ''}${iv.note ? `: ${h(iv.note)}` : ''}</p>
|
|
226
|
+
<form method="post" action="/queue/${h(iv.id)}"><input type="hidden" name="status" value="open"><button>Reopen</button></form>` : `<form method="post" action="/queue/${h(iv.id)}" class="row">
|
|
227
|
+
<input type="text" name="note" placeholder="${iv.kind === 'submit_proposal' ? 'Confirmation number' : iv.kind === 'register_vendor' ? 'UEI / vendor number' : 'Note'}" aria-label="Note" style="flex:1;min-width:200px">
|
|
228
|
+
<button class="primary" name="status" value="done">Mark done</button><button name="status" value="dismissed">Dismiss</button></form>`}
|
|
229
|
+
</article>`;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
const COPY_JS = `<script>document.addEventListener('click',e=>{const b=e.target.closest('[data-copy]');if(!b)return;const t=document.getElementById(b.dataset.copy);navigator.clipboard.writeText(t.value).then(()=>{b.textContent='Copied';setTimeout(()=>b.textContent='Copy',1500)})});</script>`;
|
|
233
|
+
|
|
234
|
+
export async function queuePage({ items, status, counts, account }) {
|
|
235
|
+
const tab = (v, label) => `<a class="btn${status === v ? ' primary' : ''}" href="/queue?status=${v}">${label}${counts[v] != null ? ` (${counts[v]})` : ''}</a>`;
|
|
236
|
+
const body = `<h1>Interventions</h1>
|
|
237
|
+
<p class="lede">Everything the system cannot do on its own. Signed in as ${h(account?.name || 'operator')}.</p>
|
|
238
|
+
<div class="row">${tab('open', 'Open')}${tab('done', 'Done')}${tab('dismissed', 'Dismissed')}${tab('all', 'All')}</div>
|
|
239
|
+
<div class="cards">${items.length ? items.map(cardHtml).join('') : '<p class="note">Nothing waiting on you.</p>'}</div>${COPY_JS}`;
|
|
240
|
+
return layout({ title: 'Queue · gov.procurement', description: 'Human intervention queue.', path: '/queue', signedIn: account }, body);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
export async function proposalPage({ p, s, account }) {
|
|
244
|
+
const body = `<p class="note"><a href="/s/${encodeURIComponent(s.id)}">${h(s.title)}</a> / proposal v${h(p.version)}</p>
|
|
245
|
+
<h1>Proposal draft v${h(p.version)} <span class="pill">${h(p.status)}</span></h1>
|
|
246
|
+
<p class="note">${h(p.body?.method === 'template' ? 'Template (no AI answer)' : `AI draft${p.provider ? ` via ${p.provider}` : ''}`)} · ${h(p.created_at.slice(0, 16).replace('T', ' '))} · <a href="/p/${h(p.id)}.md">Download .md</a></p>
|
|
247
|
+
<div class="row"><button type="button" data-copy="pmd">Copy markdown</button></div>
|
|
248
|
+
<textarea id="pmd" readonly style="width:100%;min-height:70vh;background:var(--card);color:var(--fg);border:1px solid var(--line);border-radius:10px;padding:12px">${h(p.markdown)}</textarea>${COPY_JS}`;
|
|
249
|
+
return layout({ title: `Proposal: ${s.title}`, description: 'Proposal draft', path: `/p/${p.id}`, signedIn: account }, body);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
export async function messagePage({ title, message, signedIn, status = 200 }) {
|
|
253
|
+
return { status, html: await layout({ title: `${title} · gov.procurement`, description: title, signedIn }, `<h1>${h(title)}</h1><p class="lede">${message}</p>`) };
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
export const MCP_TOOLS_DOC = [
|
|
257
|
+
['search_solicitations', 'Open solicitations by keyword, level, source; best fit first.'],
|
|
258
|
+
['get_solicitation', 'One solicitation with its documents (and fit, for operators).'],
|
|
259
|
+
['list_sources', 'Datamart contract sources joined with what gov-contracts reads.'],
|
|
260
|
+
['stats', 'Counts by status, source and level; last runs.'],
|
|
261
|
+
['list_interventions', 'Operator: the human queue.'],
|
|
262
|
+
['get_proposal', 'Operator: a proposal draft as markdown.'],
|
|
263
|
+
['resolve_intervention', 'Operator: mark a card done or dismissed (records what a PERSON did).'],
|
|
264
|
+
['draft_proposal', 'Operator: queue a (re)draft for a solicitation.'],
|
|
265
|
+
['ingest_digest', 'Operator: add the solicitations listed in a forwarded bid digest.'],
|
|
266
|
+
];
|
|
267
|
+
|
|
268
|
+
export async function docsPage({ signedIn }) {
|
|
269
|
+
const body = `<h1>Docs</h1>
|
|
270
|
+
<p class="lede">gov.procurement is the hosted @profullstack/gov-contracts (v${h(VERSION)}). It reads public bid sources, never writes to them, and never submits, registers, signs, prices or emails anyone.</p>
|
|
271
|
+
<h2 id="pipeline">Pipeline</h2>
|
|
272
|
+
<ol><li><b>Ingest</b> every 6 h: SAM.gov opportunities (federal), County of Los Angeles open solicitations; forwarded bid digests on demand. Where to look comes from Datamart's contracts registry (<code>contracts_sources</code>).</li>
|
|
273
|
+
<li><b>Read</b>: the full notice, NAICS, set-aside, contacts, and the text of up to 3 public PDF attachments.</li>
|
|
274
|
+
<li><b>Fit</b>: a keyword pre-filter, then a model (c0mpute first, OpenAI/Claude fallback) scores 0-100 against our capabilities and lists requirements, forms and registrations.</li>
|
|
275
|
+
<li><b>Draft</b> (fit 60+): cover letter, technical approach, compliance matrix, forms checklist, pricing structure with every number blank.</li>
|
|
276
|
+
<li><b>Queue</b>: register on the portal, set the price, sign/certify forms, review and submit by hand. 40-59 asks a person "worth a bid?".</li></ol>
|
|
277
|
+
<h2 id="api">HTTP API</h2>
|
|
278
|
+
<pre>GET /api/v1/solicitations?q=&level=&source=&limit=&order=fit|due|new
|
|
279
|
+
GET /api/v1/solicitations/:id
|
|
280
|
+
GET /api/v1/sources
|
|
281
|
+
GET /api/v1/stats
|
|
282
|
+
# operator (Authorization: Bearer <OPERATOR_API_KEY> or a signed-in operator)
|
|
283
|
+
GET /api/v1/interventions?status=open|done|dismissed|all
|
|
284
|
+
POST /api/v1/interventions/:id {"status":"done"|"dismissed"|"open","note":"..."}
|
|
285
|
+
GET /api/v1/proposals/:id (?format=md)
|
|
286
|
+
POST /api/v1/solicitations/:id/draft
|
|
287
|
+
POST /api/v1/ingest/digest {"text":"...forwarded digest body..."}
|
|
288
|
+
POST /api/v1/run/:job ingest-sam | ingest-lacounty | work</pre>
|
|
289
|
+
<h2 id="mcp">MCP</h2>
|
|
290
|
+
<p>Streamable HTTP at <code>${h(SITE)}mcp</code>. Operator tools need the Bearer key on the connection.</p>
|
|
291
|
+
<table><tbody>${MCP_TOOLS_DOC.map(([n, d]) => `<tr><td><code>${n}</code></td><td>${h(d)}</td></tr>`).join('')}</tbody></table>
|
|
292
|
+
<h2 id="cli">CLI and TUI</h2>
|
|
293
|
+
<pre>npx @profullstack/gov-contracts search software --level county
|
|
294
|
+
gov-contracts show sam:<id>
|
|
295
|
+
gov-contracts queue # needs GOV_CONTRACTS_KEY
|
|
296
|
+
gov-contracts done <card-id> "confirmation 12345"
|
|
297
|
+
gov-contracts digest < digest.txt
|
|
298
|
+
gov-contracts tui # work the queue in a terminal
|
|
299
|
+
gov-contracts mcp # stdio MCP bridge to ${h(SITE)}mcp</pre>
|
|
300
|
+
<h2 id="limits">Limits and payment</h2>
|
|
301
|
+
<p>Free: 60 requests a minute per caller. Past that, a $1 day pass in USDC over CoinPay or x402. Operator calls are not metered.</p>`;
|
|
302
|
+
return layout({ title: 'Docs · gov.procurement', description: 'API, MCP, CLI and TUI for gov.procurement.', path: '/docs', signedIn }, body);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
export const MANIFEST = {
|
|
306
|
+
name: 'gov.procurement',
|
|
307
|
+
short_name: 'gov.procurement',
|
|
308
|
+
description: 'Government contract opportunities, read and drafted; every submission stays a human step.',
|
|
309
|
+
start_url: '/queue',
|
|
310
|
+
scope: '/',
|
|
311
|
+
display: 'standalone',
|
|
312
|
+
background_color: '#0c0f14',
|
|
313
|
+
theme_color: '#0c0f14',
|
|
314
|
+
icons: [{ src: '/icon.svg', sizes: 'any', type: 'image/svg+xml', purpose: 'any maskable' }],
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
export const ICON = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><rect width="64" height="64" rx="14" fill="#0c0f14"/><path d="M32 10 54 20v4H10v-4zM14 27h6v18h-6zm11 0h6v18h-6zm11 0h6v18h-6zm11 0h6v18h-6zM10 48h44v6H10z" fill="#ffb547"/></svg>`;
|
|
318
|
+
|
|
319
|
+
/** Network-first for pages (so the queue is never stale), cache fallback offline. */
|
|
320
|
+
export const SW = `const C='gc-v${VERSION}';
|
|
321
|
+
self.addEventListener('install',e=>{self.skipWaiting();e.waitUntil(caches.open(C).then(c=>c.addAll(['/','/icon.svg','/manifest.webmanifest'])))});
|
|
322
|
+
self.addEventListener('activate',e=>e.waitUntil(caches.keys().then(ks=>Promise.all(ks.filter(k=>k!==C).map(k=>caches.delete(k)))).then(()=>self.clients.claim())));
|
|
323
|
+
self.addEventListener('fetch',e=>{const r=e.request;if(r.method!=='GET'||new URL(r.url).origin!==location.origin)return;
|
|
324
|
+
const p=new URL(r.url).pathname;const priv=/^\\/(api|queue|p|mcp|auth|signin|signout)(\\/|$)/.test(p);
|
|
325
|
+
e.respondWith(fetch(r).then(res=>{if(res.ok&&!priv){const cp=res.clone();caches.open(C).then(c=>c.put(r,cp))}return res}).catch(()=>caches.match(r).then(m=>m||caches.match('/'))))});`;
|
package/src/pipeline.js
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The pipeline: ingest -> read the RFP -> score the fit -> draft -> queue.
|
|
3
|
+
* Scheduled by @profullstack/scraper-daemon (local engine, run records in the
|
|
4
|
+
* app's own SQLite: one process, no Redis on c0mpute Apps).
|
|
5
|
+
*/
|
|
6
|
+
import { createDaemon, sqliteStore } from '@profullstack/scraper-daemon';
|
|
7
|
+
import { makeAi } from './ai.js';
|
|
8
|
+
import { ADAPTERS, adapterFor } from './sources/index.js';
|
|
9
|
+
import { parseDigest } from './sources/digest.js';
|
|
10
|
+
import { draftProposal, queueDecision } from './propose.js';
|
|
11
|
+
import { scoreFit } from './fit.js';
|
|
12
|
+
import { USER_AGENT } from './http.js';
|
|
13
|
+
import {
|
|
14
|
+
documentsFor, dueFor, findFeedTwin, getSolicitation, logRun, openDb, saveDocument, setSolicitation, upsertSolicitation,
|
|
15
|
+
} from './store.js';
|
|
16
|
+
|
|
17
|
+
export const DRAFT_MIN = () => Number(process.env.DRAFT_MIN_FIT || 60);
|
|
18
|
+
export const DECIDE_MIN = () => Number(process.env.DECIDE_MIN_FIT || 40);
|
|
19
|
+
|
|
20
|
+
/** Store a batch of solicitations; counts of new/updated/same. */
|
|
21
|
+
export function store(list) {
|
|
22
|
+
const counts = { new: 0, updated: 0, same: 0 };
|
|
23
|
+
for (const s of list) counts[upsertSolicitation(s)]++;
|
|
24
|
+
return counts;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export async function ingestSource(name) {
|
|
28
|
+
const a = adapterFor(name);
|
|
29
|
+
if (!a?.ingest) throw new Error(`no scheduled ingest for ${name}`);
|
|
30
|
+
try {
|
|
31
|
+
const list = await a.ingest();
|
|
32
|
+
const counts = store(list);
|
|
33
|
+
logRun(`ingest:${name}`, true, { seen: list.length, ...counts });
|
|
34
|
+
return { source: name, seen: list.length, ...counts };
|
|
35
|
+
} catch (e) {
|
|
36
|
+
logRun(`ingest:${name}`, false, String(e?.message || e).slice(0, 300));
|
|
37
|
+
throw e;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Forwarded digest text -> solicitations. */
|
|
42
|
+
export async function ingestDigest(text, { ai = makeAi() } = {}) {
|
|
43
|
+
const { parser, solicitations } = await parseDigest(text, { ai });
|
|
44
|
+
// A bid we already read from the buyer's own feed is not added twice.
|
|
45
|
+
const twins = solicitations.map((s) => findFeedTwin(s.title)?.id).filter(Boolean);
|
|
46
|
+
const fresh = solicitations.filter((s) => !findFeedTwin(s.title));
|
|
47
|
+
const counts = store(fresh);
|
|
48
|
+
logRun('ingest:digest', true, { parser, seen: solicitations.length, already_in_feeds: twins.length, ...counts });
|
|
49
|
+
return { parser, seen: solicitations.length, already_in_feeds: twins.length, ...counts, ids: [...fresh.map((s) => `${s.source}:${s.ext_id}`), ...twins] };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Read one solicitation's documents. */
|
|
53
|
+
export async function readOne(sol) {
|
|
54
|
+
const a = adapterFor(sol.source);
|
|
55
|
+
const { docs, fields } = await a.readDocs(sol);
|
|
56
|
+
for (const d of docs) saveDocument(sol.id, d);
|
|
57
|
+
setSolicitation(sol.id, { ...fields, status: 'read', error: null });
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Score one solicitation; drafts or asks a person depending on the score. */
|
|
61
|
+
export async function scoreOne(sol, { ai = makeAi() } = {}) {
|
|
62
|
+
const docs = documentsFor(sol.id);
|
|
63
|
+
const fit = await scoreFit(sol, docs, { ai });
|
|
64
|
+
setSolicitation(sol.id, { fit, fit_score: fit.score, status: 'scored' });
|
|
65
|
+
const fresh = getSolicitation(sol.id);
|
|
66
|
+
if (fit.method === 'ai' && fit.score >= DECIDE_MIN() && fit.score < DRAFT_MIN()) queueDecision(fresh);
|
|
67
|
+
if (fit.method !== 'ai' && fit.score >= DECIDE_MIN()) queueDecision(fresh);
|
|
68
|
+
return fit;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export async function draftOne(sol, { ai = makeAi() } = {}) {
|
|
72
|
+
return draftProposal(sol, documentsFor(sol.id), { ai });
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Solicitations scored high enough by a model, not drafted yet. */
|
|
76
|
+
function readyToDraft(limit) {
|
|
77
|
+
return openDb().prepare(`SELECT id FROM solicitations WHERE status = 'scored' AND fit_score >= ? AND json_extract(fit, '$.method') = 'ai'
|
|
78
|
+
AND (due_at IS NULL OR due_at >= ?) ORDER BY fit_score DESC, due_at ASC LIMIT ?`).all(DRAFT_MIN(), new Date().toISOString().slice(0, 10), limit).map((r) => getSolicitation(r.id));
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** One pass of the work loop: read a few, score one, draft one. */
|
|
82
|
+
export async function workTick({ read = 3, score = 1, draft = 1 } = {}) {
|
|
83
|
+
const done = { read: 0, scored: 0, drafted: 0, errors: 0 };
|
|
84
|
+
for (const s of dueFor('new', read)) {
|
|
85
|
+
try { await readOne(s); done.read++; } catch (e) { done.errors++; setSolicitation(s.id, { status: 'error', error: String(e?.message || e).slice(0, 300) }); }
|
|
86
|
+
}
|
|
87
|
+
const ai = makeAi();
|
|
88
|
+
for (const s of dueFor('read', score)) {
|
|
89
|
+
try { await scoreOne(s, { ai }); done.scored++; } catch (e) { done.errors++; setSolicitation(s.id, { error: String(e?.message || e).slice(0, 300) }); }
|
|
90
|
+
}
|
|
91
|
+
for (const s of readyToDraft(draft)) {
|
|
92
|
+
try { await draftOne(s, { ai }); done.drafted++; } catch (e) { done.errors++; setSolicitation(s.id, { error: String(e?.message || e).slice(0, 300) }); }
|
|
93
|
+
}
|
|
94
|
+
if (done.read || done.scored || done.drafted || done.errors) logRun('work', done.errors === 0, done);
|
|
95
|
+
return done;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
let daemon = null;
|
|
99
|
+
|
|
100
|
+
/** Start the scheduled updater (ingest every 6 h per source, work loop every minute). */
|
|
101
|
+
export function startDaemon() {
|
|
102
|
+
if (daemon || process.env.DAEMON_DISABLED === '1') return daemon;
|
|
103
|
+
daemon = createDaemon({
|
|
104
|
+
name: 'gov-contracts',
|
|
105
|
+
store: sqliteStore(openDb(), { prefix: 'daemon' }),
|
|
106
|
+
concurrency: 2,
|
|
107
|
+
fetch: { userAgent: USER_AGENT, delayMs: 2000 },
|
|
108
|
+
});
|
|
109
|
+
for (const [name, a] of Object.entries(ADAPTERS)) {
|
|
110
|
+
if (!a.scheduled) continue;
|
|
111
|
+
daemon.job({ name: `ingest-${name}`, every: a.every, staleAfter: '1d', run: () => ingestSource(name) });
|
|
112
|
+
}
|
|
113
|
+
daemon.job({ name: 'work', every: process.env.WORK_EVERY || '1m', staleAfter: '2h', run: () => workTick() });
|
|
114
|
+
daemon.start();
|
|
115
|
+
return daemon;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export const getDaemon = () => daemon;
|