@hmharness/cognitive 0.23.17 → 0.23.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/crowd.d.ts CHANGED
@@ -60,6 +60,20 @@ export declare function absorbCrowdSummary(home: string, summaryFile: string): P
60
60
  error?: string;
61
61
  skipped?: string;
62
62
  }>;
63
+ /** Absorb a crowd pack from an https URL (e.g. the repo's crowd/ directory
64
+ * on raw.githubusercontent). Guards: https-only, 10s timeout, 2MB size cap,
65
+ * and the SAME content-free validation as local files — a fetched body is
66
+ * untrusted input exactly like a shared file. Opt-in by construction: this
67
+ * only runs when the user names the URL.
68
+ * Transport fallback: Node's global fetch fails on some networks where curl
69
+ * works (DNS resolution differences); on fetch failure we retry once via
70
+ * the system curl with the SAME https-only URL. */
71
+ export declare function absorbCrowdUrl(home: string, url: string): Promise<{
72
+ ok: boolean;
73
+ absorbed: number;
74
+ error?: string;
75
+ skipped?: string;
76
+ }>;
63
77
  /** Load the local prior store for world-model seeding (used by the digest
64
78
  * and explore runner). Returns {} when nothing was ever absorbed. */
65
79
  export declare function loadCrowdPriors(home: string): Promise<CrowdPriors>;
package/dist/crowd.js CHANGED
@@ -102,6 +102,10 @@ export async function absorbCrowdSummary(home, summaryFile) {
102
102
  catch (e) {
103
103
  return { ok: false, absorbed: 0, error: 'unreadable file: ' + String(e).slice(0, 80) };
104
104
  }
105
+ return absorbParsedSummary(home, summary);
106
+ }
107
+ /** Shared absorb path for file- and URL-sourced summaries. */
108
+ async function absorbParsedSummary(home, summary) {
105
109
  const mine = environmentFingerprint();
106
110
  if (!fingerprintCompatible(mine, summary.fingerprint)) {
107
111
  return { ok: false, absorbed: 0, skipped: `fingerprint mismatch: summary is ${summary.fingerprint.os}/${summary.fingerprint.arch}, this machine is ${mine.os}/${mine.arch}` };
@@ -150,6 +154,69 @@ export async function absorbCrowdSummary(home, summaryFile) {
150
154
  }).catch(() => undefined);
151
155
  return { ok: true, absorbed };
152
156
  }
157
+ /** Absorb a crowd pack from an https URL (e.g. the repo's crowd/ directory
158
+ * on raw.githubusercontent). Guards: https-only, 10s timeout, 2MB size cap,
159
+ * and the SAME content-free validation as local files — a fetched body is
160
+ * untrusted input exactly like a shared file. Opt-in by construction: this
161
+ * only runs when the user names the URL.
162
+ * Transport fallback: Node's global fetch fails on some networks where curl
163
+ * works (DNS resolution differences); on fetch failure we retry once via
164
+ * the system curl with the SAME https-only URL. */
165
+ export async function absorbCrowdUrl(home, url) {
166
+ let parsed;
167
+ try {
168
+ parsed = new URL(url);
169
+ }
170
+ catch {
171
+ return { ok: false, absorbed: 0, error: 'invalid URL' };
172
+ }
173
+ if (parsed.protocol !== 'https:') {
174
+ return { ok: false, absorbed: 0, error: 'https URLs only (no plain http, no file://)' };
175
+ }
176
+ let text = null;
177
+ let lastError = '';
178
+ try {
179
+ const res = await fetch(url, { signal: AbortSignal.timeout(10_000) });
180
+ if (!res.ok)
181
+ return { ok: false, absorbed: 0, error: `HTTP ${res.status}` };
182
+ const len = Number(res.headers.get('content-length') ?? '0');
183
+ if (len > 2_000_000)
184
+ return { ok: false, absorbed: 0, error: `pack too large (${len} bytes > 2MB cap)` };
185
+ text = await res.text();
186
+ }
187
+ catch (e) {
188
+ lastError = String(e).slice(0, 80);
189
+ }
190
+ if (text === null) {
191
+ // curl fallback (same https-only url; curl is stock on Win10+/Unix and
192
+ // resolves some networks' DNS differently than undici)
193
+ try {
194
+ const { spawnSync } = await import('node:child_process');
195
+ const r = spawnSync('curl', ['-s', '--max-time', '10', url], { encoding: 'utf8', timeout: 15_000, windowsHide: true });
196
+ if (r.status === 0 && r.stdout)
197
+ text = r.stdout;
198
+ else
199
+ lastError = `fetch failed (${lastError}); curl fallback failed (exit ${r.status})`;
200
+ }
201
+ catch (e) {
202
+ lastError = `fetch failed (${lastError}); curl fallback unavailable: ${String(e).slice(0, 60)}`;
203
+ }
204
+ }
205
+ if (text === null)
206
+ return { ok: false, absorbed: 0, error: 'fetch failed: ' + lastError };
207
+ if (text.length > 2_000_000)
208
+ return { ok: false, absorbed: 0, error: 'pack too large (>2MB cap)' };
209
+ try {
210
+ const raw = JSON.parse(text);
211
+ if (!raw || raw.kind !== 'hmharness-crowd-summary' || !Array.isArray(raw.stats) || !raw.fingerprint) {
212
+ return { ok: false, absorbed: 0, error: 'not a crowd summary (kind/version mismatch)' };
213
+ }
214
+ return await absorbParsedSummary(home, raw);
215
+ }
216
+ catch (e) {
217
+ return { ok: false, absorbed: 0, error: 'unparseable body: ' + String(e).slice(0, 80) };
218
+ }
219
+ }
153
220
  /** Load the local prior store for world-model seeding (used by the digest
154
221
  * and explore runner). Returns {} when nothing was ever absorbed. */
155
222
  export async function loadCrowdPriors(home) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hmharness/cognitive",
3
- "version": "0.23.17",
3
+ "version": "0.23.19",
4
4
  "description": "hmharness Cognitive OS core: Environment protocol, World Model, Goal system, Exploration, RLM runtime, five-layer memory, Skill Compiler, Continual Learning control plane, Evolution 2.0 governance, Multi-Agent topology, Transfer lab and GeneralBench schema. Cognitive strategy layer per the HMH Cognitive OS blueprint (2026-09).",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -26,6 +26,6 @@
26
26
  "node": ">=22"
27
27
  },
28
28
  "dependencies": {
29
- "@hmharness/kernel": "0.23.17"
29
+ "@hmharness/kernel": "0.23.19"
30
30
  }
31
31
  }