@badger_badger/badger_hq 1.5.1 → 1.7.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/CHANGELOG.md CHANGED
@@ -1,5 +1,49 @@
1
1
  # badger_hq
2
2
 
3
+ ## 1.7.0
4
+
5
+ ### Minor Changes
6
+
7
+ - e85a4c8: Monitor tasks as a batch of sources.
8
+
9
+ - `AgentTaskSchema.sources` (`AgentTaskSourceSchema[]`, default `[]`): the sources attached to a Monitor task other than its `target` — `{ platform, url, label? }`, http(s) only, no internal source id.
10
+ Each also carries `lastCapturedAt?`, `dueAt?` (under current urgency; absent when parked) and `accessProblem?`.
11
+ - `AgentAssignmentVersionSchema.sourcesUpdatedAt?`: the latest change to a Monitor task's attached sources, so a visit refreshes agents without bumping the task version.
12
+ - `MONITOR_TASK_MAX_SOURCES` (20): the most sources one Monitor task may have attached (enforced by hero-service).
13
+ - `Source.visitIntervalMs?`: the activity-based wait set by the last visit, before urgency.
14
+ - Source schedule helpers (pure, browser-safe): `effectiveDueAt` applies current urgency (`URGENCY_FACTOR`: emergency ×0.5; mission priority critical ×0.5, high ×0.75, medium ×1, low ×1.5) to the base interval, clamped to 1–72 h; `effectiveInterval` (that interval, for `overdueLevel`); `overdueLevel` (`none` / `late` / `missed` after one more interval; `OverdueLevelSchema`); `baseVisitInterval`, `urgencyFactor`, `clampInterval`.
15
+ A source without `visitIntervalMs` (scheduled before it existed) falls back to its last `nextVisitAt − lastCollectedAt` gap, which already includes the urgency of that visit and is not scaled again.
16
+ - Sources index `{ orgId, taskIds }` (multikey): the sources attached to a task.
17
+
18
+ Wire-compatible: existing documents and payloads still parse. The inferred `AgentTask` type now always has `sources`, so code that builds `AgentTask` objects must set it (`[]` when none).
19
+
20
+ ## 1.6.0
21
+
22
+ ### Minor Changes
23
+
24
+ - d6d284c: Two task kinds with their own shape.
25
+
26
+ - `Task.target?` (`TaskTargetSchema`): the one source a task points at — `{ sourceId?, platform, url, label?, accessIssue?, note? }`. Required on Monitor tasks by hero-service; optional on Discovery tasks (search inside this source).
27
+ - `Task.captureWindow?` (`CaptureWindowSchema`): what a Monitor task captures — `{ mode: 'last_days', days: 1..90 }` or `{ mode: 'range', start, end }` with `end > start`. Stored flat in Mongo (`captureWindowSchema`), validated as a discriminated union in Zod.
28
+ - New enums `ACCESS_ISSUE_VALUES` (`login_required`, `private`, `bot_detection`, `captcha`, `geo_blocked`, `rate_limited`, `not_found`, `no_collector`, `collector_full`, `other`) and `CAPTURE_WINDOW_MODE_VALUES`.
29
+ - `AgentTaskSchema` gains `target?` (as `AgentTaskTargetSchema`, without `sourceId`) and `captureWindow?`.
30
+ - `AgentSession.captureWindow?` (`{ start, end }`): the task's window resolved to dates when the session started.
31
+ - `AgentSessionViewSchema` gains `target?` and `captureWindow?` (resolved) so the session header can show what is being captured.
32
+ - Task-tagged captures (agent-service analyses them in the background, with no live session):
33
+ - `Capture.sessionId` is now optional.
34
+ - New optional `assignmentId`, `taskId`, `missionId` and `userId`.
35
+ - New `attempts` (default 0) and `claimedAt` for the capture worker.
36
+ - New indexes `{status, createdAt}` and `{orgId, assignmentId, userId, capturedAt}`.
37
+ - `HoursLog.assignmentId?` and `HoursLog.source?` (`HOURS_LOG_SOURCE_VALUES`: `manual`, `inferred`), plus a unique partial index for one inferred row per person, assignment and day.
38
+
39
+ All fields are optional; existing documents and consumers are unaffected.
40
+
41
+ Validation:
42
+
43
+ - `TaskTargetSchema.url` accepts only `http:` / `https:` URLs (new `isHttpUrl` helper).
44
+ - `CaptureWindowSchema` `range` dates must be a `Date` or an ISO 8601 string with an explicit offset; `end` is exclusive and the range is at most `MAX_CAPTURE_WINDOW_DAYS` long.
45
+ - New index `{ orgId, target.sourceId }` on `tasks` (partial on `target.sourceId`).
46
+
3
47
  ## 1.4.0
4
48
 
5
49
  ### Minor Changes
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # badger_hq
1
+ # @badger_badger/badger_hq
2
2
 
3
3
  Shared types and schemas for **Harvester V2** (Badger HQ). Every service imports it: the Next.js web app,
4
4
  the Chrome extension, the Fastify core API, the worker, the agent and the scrapers.
@@ -7,10 +7,10 @@ It ships two entry points:
7
7
 
8
8
  | Entry | Import | Contents | Safe in |
9
9
  |---|---|---|---|
10
- | `.` | `badger_hq` | Zod schemas, inferred TS types, enums, `COLLECTIONS`, pagination / `ApiError` helpers | Browser **and** Node |
11
- | `./mongo` | `badger_hq/mongo` | Mongoose schemas, index definitions, `registerModels(connection)` | Node only |
10
+ | `.` | `@badger_badger/badger_hq` | Zod schemas, inferred TS types, enums, `COLLECTIONS`, pagination / `ApiError` helpers | Browser **and** Node |
11
+ | `./mongo` | `@badger_badger/badger_hq/mongo` | Mongoose schemas, index definitions, `registerModels(connection)` | Node only |
12
12
 
13
- Nothing reachable from `badger_hq` imports `mongoose`, `bson` or a Node built-in; a test bundles it with esbuild
13
+ Nothing reachable from `@badger_badger/badger_hq` imports `mongoose`, `bson` or a Node built-in; a test bundles it with esbuild
14
14
  for `platform: 'browser'` and fails if that ever changes.
15
15
 
16
16
  ## Install
@@ -18,7 +18,7 @@ for `platform: 'browser'` and fails if that ever changes.
18
18
  The package is published publicly to the npm registry.
19
19
 
20
20
  ```sh
21
- npm install badger_hq zod
21
+ npm install @badger_badger/badger_hq zod
22
22
  # server-side packages also need:
23
23
  npm install mongoose
24
24
  ```
@@ -37,7 +37,7 @@ import {
37
37
  PaginationQuerySchema,
38
38
  type Paginated,
39
39
  type ApiError,
40
- } from 'badger_hq';
40
+ } from '@badger_badger/badger_hq';
41
41
  ```
42
42
 
43
43
  Per entity (`Mission` shown; the same pattern applies to every entity):
@@ -57,7 +57,7 @@ Dates use `z.coerce.date()`, so JSON ISO strings parse to `Date`.
57
57
  ```tsx
58
58
  import { useForm } from 'react-hook-form';
59
59
  import { zodResolver } from '@hookform/resolvers/zod';
60
- import { MissionCreateSchema, type MissionCreateInput, MISSION_PRIORITY_VALUES } from 'badger_hq';
60
+ import { MissionCreateSchema, type MissionCreateInput, MISSION_PRIORITY_VALUES } from '@badger_badger/badger_hq';
61
61
 
62
62
  export function NewMissionForm() {
63
63
  const form = useForm<MissionCreateInput>({
@@ -86,7 +86,7 @@ export function NewMissionForm() {
86
86
  ### Example: parsing an API response
87
87
 
88
88
  ```ts
89
- import { PaginatedSchema, TaskSchema } from 'badger_hq';
89
+ import { PaginatedSchema, TaskSchema } from '@badger_badger/badger_hq';
90
90
 
91
91
  const PageOfTasks = PaginatedSchema(TaskSchema);
92
92
  const page = PageOfTasks.parse(await res.json()); // page.items[0].createdAt is a Date
@@ -95,7 +95,7 @@ const page = PageOfTasks.parse(await res.json()); // page.items[0].createdAt is
95
95
  ## Entry point `./mongo` — Mongoose
96
96
 
97
97
  ```ts
98
- import { registerModels, COLLECTIONS, INDEXES, incrementTaskVersion, type HarvesterModels } from 'badger_hq/mongo';
98
+ import { registerModels, COLLECTIONS, INDEXES, incrementTaskVersion, type HarvesterModels } from '@badger_badger/badger_hq/mongo';
99
99
  ```
100
100
 
101
101
  The package **never connects**. You own the `mongoose.Connection`; `registerModels(conn)` registers the models on it
@@ -139,8 +139,8 @@ with the Zod `MissionSchema`, `TaskSchema`, … from the browser entry.
139
139
  ```ts
140
140
  import Fastify from 'fastify';
141
141
  import mongoose from 'mongoose';
142
- import { registerModels } from 'badger_hq/mongo';
143
- import { MissionCreateSchema, MissionSchema, type Mission } from 'badger_hq';
142
+ import { registerModels } from '@badger_badger/badger_hq/mongo';
143
+ import { MissionCreateSchema, MissionSchema, type Mission } from '@badger_badger/badger_hq';
144
144
 
145
145
  const app = Fastify();
146
146
  const conn = mongoose.createConnection(process.env.MONGO_URL!);
@@ -205,6 +205,10 @@ Each enum is defined once in `enums.ts` as `z.enum([...])` plus a `*_VALUES` con
205
205
  - **Mission** — a priority (PIR) in plain words; the top-level unit of work.
206
206
  - **Task** — a unit of work under a mission, `source_discovery` or `monitor`; what gets assigned to a scout or analyst.
207
207
  There is no "subtask" concept.
208
+ - **Discovery** — a free search: phrases (`keywords`), a short explanation (`description`), search queries, and
209
+ optionally one `target` source to search inside.
210
+ - **Monitor** — collect **one** `target` source a scraper can't (see `accessIssue`) over a `captureWindow`
211
+ (the last N days, or a fixed range).
208
212
 
209
213
  ## Versioning
210
214
 
@@ -268,7 +272,7 @@ Choices made where the spec left room, kept consistent with the rest of it:
268
272
  `suppressReservedKeysWarning` set on that schema.
269
273
  8. **Mongoose schema export names** are lowerCamelCase (`missionSchema`) to avoid colliding with the Zod
270
274
  `MissionSchema` when both entry points are imported in one file.
271
- 9. **Package name** is `badger_hq` (set in `package.json`), published publicly to the npm registry.
275
+ 9. **Package name** is `@badger_badger/badger_hq` (set in `package.json`), published publicly to the npm registry.
272
276
  10. **Multiple assignees per task (1.0.0).** The "one active assignee per task" unique index was replaced by
273
277
  `{ taskId, assigneeUserId }` (partial, `status: 'active'`). Limits are enforced by `assigneeLoads`, not by an index,
274
278
  because a scout's limit spans organizations while an analyst's is per org.