@gair/codex-med 0.1.4 → 0.1.5

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/bin/codex.js CHANGED
@@ -2,8 +2,9 @@
2
2
  // Unified entry point for the Codex CLI.
3
3
 
4
4
  import { spawn } from "node:child_process";
5
- import { existsSync, realpathSync } from "fs";
5
+ import { existsSync, mkdirSync, realpathSync } from "fs";
6
6
  import { createRequire } from "node:module";
7
+ import { homedir } from "node:os";
7
8
  import path from "path";
8
9
  import { fileURLToPath } from "url";
9
10
 
@@ -169,6 +170,16 @@ if (existsSync(pathDir)) {
169
170
  const updatedPath = getUpdatedPath(additionalDirs);
170
171
 
171
172
  const env = { ...process.env, PATH: updatedPath };
173
+ const configuredCodexMedHome = process.env.CODEX_MED_HOME;
174
+ const codexMedHome = configuredCodexMedHome
175
+ ? path.resolve(configuredCodexMedHome)
176
+ : path.join(homedir(), ".codex-med");
177
+ mkdirSync(codexMedHome, { recursive: true });
178
+ env.CODEX_MED_HOME = codexMedHome;
179
+ // The native CLI still reads CODEX_HOME internally. Keep that implementation
180
+ // detail inside the Codex Med child process so it never shares the regular
181
+ // Codex home, even when the parent shell has CODEX_HOME configured.
182
+ env.CODEX_HOME = codexMedHome;
172
183
  const packageManagerEnvVar =
173
184
  detectPackageManager() === "bun"
174
185
  ? "CODEX_MANAGED_BY_BUN"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gair/codex-med",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "Codex CLI for medical domain agents (fork of OpenAI Codex CLI).",
5
5
  "license": "Apache-2.0",
6
6
  "bin": {
@@ -11,7 +11,8 @@
11
11
  "node": ">=16"
12
12
  },
13
13
  "files": [
14
- "bin/codex.js"
14
+ "bin/codex.js",
15
+ "skills"
15
16
  ],
16
17
  "repository": {
17
18
  "type": "git",
@@ -20,6 +21,6 @@
20
21
  },
21
22
  "packageManager": "pnpm@10.33.0+sha512.10568bb4a6afb58c9eb3630da90cc9516417abebd3fabbe6739f0ae795728da1491e9db5a544c76ad8eb7570f5c4bb3d6c637b2cb41bfdcdb47fa823c8649319",
22
23
  "optionalDependencies": {
23
- "@gair/codex-med-linux-x64": "npm:@gair/codex-med@0.1.4-linux-x64"
24
+ "@gair/codex-med-linux-x64": "npm:@gair/codex-med@0.1.5-linux-x64"
24
25
  }
25
26
  }
@@ -0,0 +1,173 @@
1
+ ---
2
+ name: codex-med-science-workbench
3
+ description: Route and chain codex-med biomedical retrieval, literature-map, citation-validation, review-resolution, and PubMed vector-reconciliation tools into reproducible research workflows. Use when the user asks for quick PubMed evidence, a durable local or PubMed literature map, comparison of local knowledge with public literature, citation verification, ingestion of retrieved PubMed records into Qdrant, repair of incomplete vector coverage, resolution of possible-duplicate literature records, or inspection of available medical databases.
4
+ ---
5
+
6
+ # Codex Med Science Workbench
7
+
8
+ Choose the smallest workflow that produces the artifact the user wants. Keep all
9
+ durable steps for one project in the same workspace so they share the literature
10
+ registry and project manifest.
11
+
12
+ ## Route by Intended Result
13
+
14
+ - Use `list_med_knowledge_collections` to discover available SQL and vector
15
+ backends when the source is unknown.
16
+ - Use `describe_med_database` to inspect schemas, payload fields, row counts, or
17
+ collection metadata before constructing a structured query.
18
+ - Use `search_vector_knowledge` for a quick semantic lookup from local knowledge
19
+ without writing project files.
20
+ - Use `search_pubmed_literature` for a quick PubMed result list when PMIDs are
21
+ unknown and no durable project is requested.
22
+ - Use `fetch_pubmed_record` to fetch the abstract and MeSH terms of a selected
23
+ PMID.
24
+ - Use `validate_citations` to verify DOI, title, and author metadata against
25
+ Crossref. Do not treat this metadata check as proof that a paper supports a
26
+ scientific claim.
27
+ - Use `literature_map` to create a durable evidence package from the local
28
+ codex-med vector collection.
29
+ - Use `pubmed_literature_map` to create a durable PubMed package, register
30
+ canonical literature identities, and optionally ingest complete records into
31
+ Qdrant.
32
+ - Use `resolve_literature_review` only after a human decides whether a
33
+ possible-duplicate pair is the same publication.
34
+ - Use `reconcile_pubmed_vectors` to verify or repair vector coverage for PubMed
35
+ records already present in the workspace registry.
36
+
37
+ For a short answer in chat, do not create a project unless the user asks for
38
+ saved files, a literature map, provenance, an export, or a reusable workflow.
39
+
40
+ ## Chain Quick PubMed Evidence
41
+
42
+ Use this sequence for a small answer without project files:
43
+
44
+ 1. Call `search_pubmed_literature`.
45
+ 2. Inspect `query_degraded` and `query_translation`. Correct and rerun the query
46
+ if PubMed dropped or widened a qualifier.
47
+ 3. Select relevant PMIDs from the returned metadata.
48
+ 4. Call `fetch_pubmed_record` only for records whose abstracts or MeSH terms are
49
+ needed.
50
+ 5. Call `validate_citations` for DOI-bearing references when citation identity
51
+ matters.
52
+ 6. Separate verified metadata from the model's assessment of claim support in
53
+ the final answer.
54
+
55
+ Do not fetch every record by default. Keep discovery broad and evidence
56
+ extraction selective.
57
+
58
+ ## Build a Durable Literature Project
59
+
60
+ ### Local knowledge
61
+
62
+ 1. Discover or describe the backend only when its contents are unfamiliar.
63
+ 2. Call `literature_map` with a clear `topic`, a stable `project_id`, and the
64
+ requested `top_k`.
65
+ 3. Inspect `literature/local/literature_ids.csv`, `report.md`, the immutable run
66
+ snapshot, and provenance before summarizing.
67
+
68
+ ### PubMed
69
+
70
+ 1. Call `pubmed_literature_map` directly with a clear `topic` and stable
71
+ `project_id`.
72
+ 2. Supply `pubmed_query` for Boolean expressions, field tags, author or journal
73
+ filters, and exact PMID searches.
74
+ 3. Set `min_year` and `max_year` together. Use `sort: "pub_date"` for recent
75
+ papers and relevance otherwise.
76
+ 4. Keep `fetch_abstracts` enabled for evidence work. Disable it only for a fast
77
+ metadata inventory.
78
+ 5. Enable `validate_citations` when DOI metadata must be checked in the same
79
+ durable run.
80
+ 6. Inspect `fetch_errors`, `citation_validation`, `query_degraded` in
81
+ provenance, `vector_statuses`, and `incomplete_vectors`.
82
+ 7. Review `literature/pubmed/literature_ids.csv`, `report.md`, citations,
83
+ snapshot, provenance, and the merged project manifest.
84
+
85
+ Do not manually call `search_pubmed_literature` and `fetch_pubmed_record` before
86
+ `pubmed_literature_map` unless previewing the query is necessary. The map tool
87
+ already performs search, detail fetching, registration, artifact creation,
88
+ citation validation, and vector-ingestion bookkeeping.
89
+
90
+ ### Compare local knowledge with PubMed
91
+
92
+ 1. Use one stable `project_id`.
93
+ 2. Run `literature_map` for local curated evidence.
94
+ 3. Run `pubmed_literature_map` for public evidence.
95
+ 4. Compare canonical outputs under `literature/local/` and
96
+ `literature/pubmed/`.
97
+ 5. Report overlap, source-specific records, ranking differences, and search
98
+ limitations. Do not merge the two ranked CSV files manually; let the shared
99
+ registry and project manifest preserve identity and provenance.
100
+
101
+ ## Ingest Retrieved PubMed Literature
102
+
103
+ Treat vector ingestion as an explicit state-changing workflow.
104
+
105
+ 1. Confirm that the user requested or authorized vector writes.
106
+ 2. Start Codex Med with these runtime settings:
107
+ - `CODEX_MED_PUBMED_VECTOR_WRITES=1`
108
+ - an explicit `CODEX_MED_VECTOR_COLLECTION`
109
+ - `CODEX_MED_VECTOR_QDRANT_API_KEY` when Qdrant requires authentication
110
+ - `CODEX_MED_EMBEDDING_API_KEY` when the embedding service requires
111
+ authentication
112
+ 3. Refuse to test against the production collection when a disposable
113
+ collection is intended.
114
+ 4. Before the first authorized write to the default production collection, run
115
+ `literature_map` once in the same workspace with
116
+ `CODEX_MED_INITIALIZE_LITERATURE_BASELINE=1`. Inspect
117
+ `baseline_initialization` in provenance, then remove the initialization
118
+ flag. Do not bypass a missing or invalid production baseline.
119
+ 5. Call `pubmed_literature_map` with `require_vector_complete: true` when the
120
+ task requires an ingestion guarantee.
121
+ 6. Declare success only when `vector_complete` is true and every record has
122
+ status `complete` or `already_vectorized`.
123
+ 7. Treat `vector_write_disabled`, `possible_duplicate`, `blocked_conflict`,
124
+ `failed`, missing points, or any other status as incomplete even if
125
+ literature files were created.
126
+
127
+ Keep vector writes disabled for ordinary retrieval and literature-map requests.
128
+ Never place secret values in project artifacts, prompts, reports, or provenance.
129
+
130
+ ## Recover Incomplete Ingestion
131
+
132
+ Use the returned status to choose the next tool:
133
+
134
+ - For `possible_duplicate`, `blocked_conflict`, or a `review_case_id`, show the
135
+ conflicting identities to the user and request an explicit same/different
136
+ decision. Call `resolve_literature_review` with the human rationale; never
137
+ infer approval from title or identifier similarity.
138
+ - After resolving a review, call `reconcile_pubmed_vectors` for the affected
139
+ canonical literature ID.
140
+ - For failed, stale, or missing vectors without an identity conflict, call
141
+ `reconcile_pubmed_vectors` with the affected `literature_ids` first. Omit IDs
142
+ only when the user requests a workspace-wide batch audit.
143
+ - Inspect `complete`, `statuses`, `expected_points`, `verified_points`,
144
+ `verification_method`, and per-record errors after reconciliation.
145
+ - Rerun the map only to refresh search results or regenerate project artifacts;
146
+ do not use repeated map runs as a substitute for reconciliation.
147
+
148
+ Keep `pubmed_literature_map`, `resolve_literature_review`, and
149
+ `reconcile_pubmed_vectors` in the same working directory. Their registry is
150
+ workspace-local.
151
+
152
+ ## Preserve Project Invariants
153
+
154
+ - Reuse the same filesystem-safe `project_id` across reruns.
155
+ - Preserve separate `literature/local/` and `literature/pubmed/` ranked outputs.
156
+ - Treat immutable run snapshots and provenance as the audit record.
157
+ - Do not edit the SQLite literature registry or vector job rows manually.
158
+ - Do not claim that file creation proves vector ingestion or citation validity.
159
+ - Prefer targeted recovery by literature ID before workspace-wide repair.
160
+
161
+ ## Report Results
162
+
163
+ After a workflow, report:
164
+
165
+ - the tools called and why they were chained;
166
+ - the workspace and project path;
167
+ - query, filters, sort order, and returned record count;
168
+ - key files and provenance written;
169
+ - citation-validation and query-degradation warnings;
170
+ - vector-write setting, collection, status counts, and completeness;
171
+ - pending review IDs, fetch errors, or recommended recovery steps.
172
+
173
+ Point to saved artifacts instead of pasting large records into chat.
@@ -0,0 +1,4 @@
1
+ interface:
2
+ display_name: "Codex Med Science Workbench"
3
+ short_description: "Chain biomedical literature and vector workflows"
4
+ default_prompt: "Use $codex-med-science-workbench to choose and chain the right biomedical literature, citation, and vector-recovery tools for this research request."