@louisultra/dsh-verymath 0.5.1 → 0.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.
@@ -133,3 +133,21 @@ export interface UpsertResult {
133
133
  * a correction would duplicate another row's `(en, cn)` pair.
134
134
  */
135
135
  export declare function upsertTerms(terms: readonly GlossaryTerm[], upserts: readonly TermUpsert[]): UpsertResult;
136
+ /** Result of removing one row. */
137
+ export interface DeleteResult {
138
+ /** Whether a row with that id existed. */
139
+ readonly removed: boolean;
140
+ /** The document after removal, re-sorted with contiguous idx. */
141
+ readonly document: GlossaryTerm[];
142
+ }
143
+ /**
144
+ * Remove one row by `term_id`, preserving the document invariants.
145
+ *
146
+ * Deletion is how a duplicate or a wrong alias gets resolved: there is no
147
+ * "merge" operation in the upstream contract, and the panel's job is to let a
148
+ * human drop the row they decided against rather than hand-edit JSON.
149
+ * @param terms - current glossary terms (any order).
150
+ * @param termId - exact id of the row to remove.
151
+ * @throws VeryMathError when the input document already breaks an invariant.
152
+ */
153
+ export declare function deleteTerm(terms: readonly GlossaryTerm[], termId: string): DeleteResult;
@@ -424,3 +424,23 @@ function nextTermId(byId, en) {
424
424
  occurrence += 1n;
425
425
  }
426
426
  }
427
+ /**
428
+ * Remove one row by `term_id`, preserving the document invariants.
429
+ *
430
+ * Deletion is how a duplicate or a wrong alias gets resolved: there is no
431
+ * "merge" operation in the upstream contract, and the panel's job is to let a
432
+ * human drop the row they decided against rather than hand-edit JSON.
433
+ * @param terms - current glossary terms (any order).
434
+ * @param termId - exact id of the row to remove.
435
+ * @throws VeryMathError when the input document already breaks an invariant.
436
+ */
437
+ export function deleteTerm(terms, termId) {
438
+ validateGlossaryInvariants(terms);
439
+ const remaining = terms.filter(term => term.term_id !== termId);
440
+ if (remaining.length === terms.length)
441
+ return { removed: false, document: sortGlossary([...terms]) };
442
+ // Re-sorting reassigns idx, so a deletion cannot leave a numbering hole.
443
+ const document = sortGlossary(remaining);
444
+ validateGlossaryInvariants(document);
445
+ return { removed: true, document };
446
+ }
@@ -11,8 +11,8 @@ import { type GlossaryHit, type GlossaryQueryOptions, type GlossaryTerm } from '
11
11
  export { VeryMathError, isVeryMathError, isErrnoCode } from './error.ts';
12
12
  export { bundledSkillsDir } from './paths.ts';
13
13
  export { VeryMathSkillProvider } from './skills.ts';
14
- export { parseGlossary, queryGlossary, sortGlossary, upsertTerms, validateGlossaryInvariants } from './glossary.ts';
15
- export type { GlossaryHit, GlossaryQueryOptions, GlossaryTerm, TermUpsert, UpsertResult } from './glossary.ts';
14
+ export { parseGlossary, queryGlossary, sortGlossary, upsertTerms, deleteTerm, validateGlossaryInvariants } from './glossary.ts';
15
+ export type { GlossaryHit, GlossaryQueryOptions, GlossaryTerm, TermUpsert, UpsertResult, DeleteResult } from './glossary.ts';
16
16
  export { parsePaperStructure, parsePaperBatch, dependencySummary } from './paper.ts';
17
17
  export { checkGate, checkGoalApproval, checkWorkstreamCompletion, checkFinalRender, loadGoals, listWorkstreams, hasSection, } from './gates.ts';
18
18
  export type { GateResult } from './gates.ts';
package/lib/core/index.js CHANGED
@@ -17,7 +17,7 @@ import { VeryMathSkillProvider } from "./skills.js";
17
17
  export { VeryMathError, isVeryMathError, isErrnoCode } from "./error.js";
18
18
  export { bundledSkillsDir } from "./paths.js";
19
19
  export { VeryMathSkillProvider } from "./skills.js";
20
- export { parseGlossary, queryGlossary, sortGlossary, upsertTerms, validateGlossaryInvariants } from "./glossary.js";
20
+ export { parseGlossary, queryGlossary, sortGlossary, upsertTerms, deleteTerm, validateGlossaryInvariants } from "./glossary.js";
21
21
  export { parsePaperStructure, parsePaperBatch, dependencySummary } from "./paper.js";
22
22
  export { checkGate, checkGoalApproval, checkWorkstreamCompletion, checkFinalRender, loadGoals, listWorkstreams, hasSection, } from "./gates.js";
23
23
  export { loadManifest, searchSageRefs, scoreRow, termsFor, findExcerpt, readCorpusDoc, readCorpusDocWindow, resolveCorpusRoot, defaultCorpusRoot, docPath, } from "./sage.js";
package/lib/http.d.ts ADDED
@@ -0,0 +1,29 @@
1
+ import { basename } from 'node:path';
2
+ /** Minimal shape of the host connection service this module needs. */
3
+ export interface ConnectionLike {
4
+ readonly fetch?: {
5
+ readonly register?: (route: {
6
+ readonly path: string;
7
+ readonly methods: readonly string[];
8
+ readonly requestBody?: 'buffered' | 'streaming';
9
+ readonly fetch: (request: Request) => Promise<Response>;
10
+ }) => unknown;
11
+ };
12
+ }
13
+ /** What the routes need from the host context. */
14
+ export interface HttpContext {
15
+ /** Workspace root the panel browses (the session/agent cwd). */
16
+ readonly workspace: () => string;
17
+ /** Host logger; absent in some hosts. */
18
+ readonly log?: (message: string) => void;
19
+ }
20
+ /** Resolve a caller-supplied relative path and refuse anything outside the workspace. */
21
+ declare function withinWorkspace(workspace: string, candidate: string): string | undefined;
22
+ /**
23
+ * Register the panel's routes. Returns false when the host exposes no exact-fetch
24
+ * table (headless / CLI), so the panel half degrades away instead of making the
25
+ * plugin unloadable.
26
+ */
27
+ export declare function registerHttp(ctx: HttpContext, connection: ConnectionLike | undefined): boolean;
28
+ /** Exported for tests: the workspace-confinement rule the routes rely on. */
29
+ export { withinWorkspace, basename as _basename };