@mmon-co/ncept-default-theory 0.0.0-stage → 1.0.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 +21 -0
- package/README.md +73 -2
- package/dist/catalog-contract.d.ts +102 -0
- package/dist/catalog-contract.js +75 -0
- package/dist/catalog.d.ts +14 -0
- package/dist/catalog.js +164 -0
- package/dist/chat.d.ts +171 -0
- package/dist/chat.js +203 -0
- package/dist/completion.d.ts +74 -0
- package/dist/completion.js +277 -0
- package/dist/dependent-cone.d.ts +3 -0
- package/dist/dependent-cone.js +26 -0
- package/dist/diagnosis.d.ts +9 -0
- package/dist/diagnosis.js +1 -0
- package/dist/diagnostics.d.ts +25 -0
- package/dist/diagnostics.js +34 -0
- package/dist/evaluation.d.ts +33 -0
- package/dist/evaluation.js +376 -0
- package/dist/event.d.ts +7 -0
- package/dist/event.js +405 -0
- package/dist/history.d.ts +4 -0
- package/dist/history.js +61 -0
- package/dist/implementation.d.ts +170 -0
- package/dist/implementation.js +30 -0
- package/dist/index.d.ts +185 -0
- package/dist/index.js +26 -0
- package/dist/messages.d.ts +167 -0
- package/dist/messages.js +56 -0
- package/dist/outcomes.d.ts +143 -0
- package/dist/outcomes.js +323 -0
- package/dist/path.d.ts +17 -0
- package/dist/path.js +292 -0
- package/dist/reading.d.ts +12 -0
- package/dist/reading.js +75 -0
- package/dist/release.d.ts +1 -0
- package/dist/release.js +1 -0
- package/dist/roleplay.d.ts +17 -0
- package/dist/roleplay.js +2 -0
- package/dist/skills/sources.d.ts +12 -0
- package/dist/skills/sources.js +13 -0
- package/dist/skills.d.ts +12 -0
- package/dist/skills.js +70 -0
- package/dist/state.d.ts +316 -0
- package/dist/state.js +1309 -0
- package/dist/tags.d.ts +34 -0
- package/dist/tags.js +306 -0
- package/dist/timing.d.ts +21 -0
- package/dist/timing.js +79 -0
- package/dist/tools.d.ts +394 -0
- package/dist/tools.js +872 -0
- package/package.json +52 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 mmon-co
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,74 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Default Theory
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`@mmon-co/ncept-default-theory` implements Core's `Theory` interface. It depends on `@mmon-co/ncept-core` through public exports, just as a third-party Theory does; Core does not depend on it. The web Application selects it explicitly. FSRS retention, acquisition, Mission futures, tutor Programs and pedagogical Skills live here. Hosts supply persistence, model calls and their own mechanics.
|
|
4
|
+
|
|
5
|
+
## Use
|
|
6
|
+
|
|
7
|
+
Import `defaultTheory` and `DEFAULT_THEORY_REQUIREMENT` from `@mmon-co/ncept-default-theory`. The executable keeps its identity `default`, version `1.0.0+<commit>` (`dev` outside a deploy) and new-Profile range `~1.0`. This package move changes neither stored observations nor Profile requirements and needs no data migration.
|
|
8
|
+
|
|
9
|
+
The root exports the implementation's public operations and types. Focused exports are `@mmon-co/ncept-default-theory/path`, `/state`, `/messages` and `/outcomes`.
|
|
10
|
+
|
|
11
|
+
Node.js 20.19+ is supported. Published exports are ESM JavaScript with TypeScript declarations. Install with `npm install @mmon-co/ncept-default-theory`; no TypeScript runtime or host assets are needed.
|
|
12
|
+
|
|
13
|
+
From the repository root, install workspace dependencies with `bun install --frozen-lockfile`, then build and try the package:
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
bun run --cwd packages/default-theory build
|
|
17
|
+
cd packages/default-theory
|
|
18
|
+
node --input-type=module -e 'import { defaultTheory, DEFAULT_THEORY_REQUIREMENT, skillBody } from "@mmon-co/ncept-default-theory"; import { resolveTheory } from "@mmon-co/ncept-core/theory"; console.log(resolveTheory(DEFAULT_THEORY_REQUIREMENT, [defaultTheory]).version); console.log(skillBody("mission"));'
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
The Skills' Markdown is the source. `build-skills.ts` embeds it in Git-ignored `src/skills/sources.ts`; the build compiles that into JavaScript with the rest of the package. The repository's `build:skills` task uses the same generator for the Convex bundler. Workspace tsconfig paths resolve imports to source. Existing algorithm tests live in `test/`: `bun test --parallel packages/default-theory/test`.
|
|
22
|
+
|
|
23
|
+
`npm pack --dry-run` from this directory runs `prepack`, rebuilding Core and this package. The archive contains only `dist/`, this README, `LICENSE` and its manifest. Its Core dependency is a registry semver range, not a workspace-only reference.
|
|
24
|
+
|
|
25
|
+
MIT licensed; see [LICENSE](LICENSE).
|
|
26
|
+
|
|
27
|
+
## Stored-output version guard
|
|
28
|
+
|
|
29
|
+
`bun test packages/default-theory/test/stored-output.test.ts` compares a fixed graph and observation log with `test/snapshots/stored-output.<major>.<minor>.json`. The ordinary test suite and pre-integration gate run it too. It records tag membership on Nodes, Edges and the learner at several evidence prefixes and clocks, the `pedagogy:` keys those operations read, and observation payloads emitted by recording tools and outcome/day events. It does not record captions, rankings, readings, paths, prompts or build metadata. Like any fixture, it detects changes exercised by that graph and log, not every possible policy change.
|
|
30
|
+
|
|
31
|
+
A mismatch requires a minor (mechanical migration) or major (non-mechanical migration) bump to `DEFAULT_THEORY_REF` and the corresponding forward data migration. Changed criteria for applying the same tags count as stored-data changes, not patches. Generate the new version's snapshot after making that change. If the diff changes no stored data, refresh the existing snapshot instead:
|
|
32
|
+
|
|
33
|
+
```sh
|
|
34
|
+
UPDATE_DEFAULT_THEORY_STORED_OUTPUT=1 bun test packages/default-theory/test/stored-output.test.ts
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Review the snapshot diff; refreshing it is not a substitute for a required version bump or migration. A missing versioned snapshot fails rather than being created by an ordinary test run.
|
|
38
|
+
|
|
39
|
+
## Observation contract
|
|
40
|
+
|
|
41
|
+
The observation vocabulary is this package's public data contract, not a Core vocabulary or a private implementation detail. Other Theories may import and interpret it so switching Theory need not restart a learner's progress. They decide how that evidence affects their own state; reusing the evidence does not require reproducing this Theory's labels or FSRS schedules.
|
|
42
|
+
|
|
43
|
+
Core's `Observation` envelope carries identity, time, scope, support and the producing Theory's exact version. Its payload remains opaque to Core. The exported payload types and guards define what this Theory recognizes:
|
|
44
|
+
|
|
45
|
+
| Payload | Public type and guard from `@mmon-co/ncept-default-theory/outcomes` | Captured evidence |
|
|
46
|
+
| --- | --- | --- |
|
|
47
|
+
| `completion` | `CompletionOutcome`, `isCompletionOutcome` | Playground and scope, exact Node provenance, complete/incomplete and optional validity boundary |
|
|
48
|
+
| `recall` | `RecallOutcome`, `isRecallOutcome` | Card content and Nodes at retrieval, learner answer and recall grade |
|
|
49
|
+
| `quiz` | `QuizOutcome`, `isQuizOutcome` | Questions, choices and correct answers, selected/skipped responses and comments |
|
|
50
|
+
| `attempt` | `AttemptOutcome`, `isAttemptOutcome` | Problem and grading contract at opening, response, assessment, help and exact revision |
|
|
51
|
+
|
|
52
|
+
`practiceAttempts` and `problemAttempts` derive per-Node `Demonstration` evidence from captured practice payloads without consulting today's editable Materials. `NodeRef` is `{ node, provenance }`, where `provenance` is the exact authoring Patch revision (`{ identity, digest }`). Captured values are historical evidence, not pointers that a later content edit can reinterpret silently.
|
|
53
|
+
|
|
54
|
+
Record payload types are exported from `@mmon-co/ncept-default-theory/state` and the root as the `DefaultPayload` union. Their `kind` discriminates the following vocabulary:
|
|
55
|
+
|
|
56
|
+
| Kind | Type | Recorded meaning |
|
|
57
|
+
| --- | --- | --- |
|
|
58
|
+
| `completion` | `CompletionOutcome` | Scoped complete/incomplete evidence, as above |
|
|
59
|
+
| `demonstration` | `Demonstration` | A Node's success/failure/don't-know, whether unaided, grader, task and response; optional evaluation records criterion probabilities and overrides. `recording: "retrieval-opener"` marks lesson-opening retrieval. |
|
|
60
|
+
| `lapse` | `Lapse` | Diagnosed regression for a Node, optionally linked to the same lesson's prior slip; affects retention, not acquisition |
|
|
61
|
+
| `grade` | `Grade` | A Node's whole-day retention judgment (`Again`, `Hard`, `Good`, `Easy`) and the exact learner-day interval |
|
|
62
|
+
| `review-pass` | `ReviewPass` | A passed Review for a Node, clearing the path until its covering grade sets retention |
|
|
63
|
+
| `feature-use` | `FeatureUse` | An accepted operation name, not proof of every criterion clause |
|
|
64
|
+
| `teaching` | `Teaching` | An explicit explanation taught for a Node, separate from competence evidence |
|
|
65
|
+
| `claim` | `Claim` | A statement, optional eliciting prompt and learner stance (`knows`, `forgotten`, `unfamiliar`) |
|
|
66
|
+
| `retraction` | `Retraction` | Withdraws the observation named by `of` |
|
|
67
|
+
| `homing` | `Homing` | Places the demonstration/claim named by `of` on `homes` Nodes at an exact `revision`; optional `pending` marks unresolved placement |
|
|
68
|
+
| `memory` | `Memory` | Speaker-labelled text entries with timestamps and observation or transcript-span sources |
|
|
69
|
+
| `memory-summary` | `MemorySummaryPayload` | Retrieval summary text, Material speakers, source observation ids and all consumed dependencies |
|
|
70
|
+
| `interpretation` | `Interpretation` | Supported retrieval prose and canonical tags; scope/support are the envelope's `nodes`/`cites`, not learner-state evidence |
|
|
71
|
+
|
|
72
|
+
Public guards include `isDemonstration`, `isRetrievalOpenerDemonstration`, `isLapse`, `isGrade`, `isReviewPass`, `isFeatureUse`, `isTeaching`, `isClaim`, `isRetraction`, `isHoming` and `isMemory`. `isDefaultObservation` checks producing-Theory attribution only; it is not a payload validator. `MemorySummaryPayload` and `Interpretation` have exported types but no standalone public guards. Other Theories choose which kinds they understand and preserve unread observations when exchanging a Profile.
|
|
73
|
+
|
|
74
|
+
Observation-contract changes follow the Theory's semver and forward-migration rules: a patch needs no dependent-data migration, a minor permits a mechanical migration, and a major requires a non-mechanical one. This extraction preserves the existing payloads and validators unchanged.
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import type { NodeId, TutorGuidanceEntry } from "@mmon-co/ncept-core/patch";
|
|
2
|
+
/**
|
|
3
|
+
* Transport contracts for the catalog consolidation. These declarations mount nothing:
|
|
4
|
+
* the implementation tickets supply the Programs and host handlers.
|
|
5
|
+
*/
|
|
6
|
+
export declare const CATALOG_PAGE_SIZE = 20;
|
|
7
|
+
/** Per-page safety only: larger collections remain traversable with cursors. */
|
|
8
|
+
export declare const CATALOG_MAX_PAGE_SIZE = 100;
|
|
9
|
+
export interface CatalogPage<T> {
|
|
10
|
+
readonly page: readonly T[];
|
|
11
|
+
readonly isDone: boolean;
|
|
12
|
+
readonly continueCursor: string | null;
|
|
13
|
+
}
|
|
14
|
+
export type CatalogArguments = Readonly<Record<string, unknown>>;
|
|
15
|
+
export interface QueryToolInput {
|
|
16
|
+
/** Bypass context-relative deltas for document/list. */
|
|
17
|
+
readonly full?: boolean;
|
|
18
|
+
readonly resource: "profile" | "view" | "session" | "artifact" | "material" | "applet" | "audio" | "hub" | "document";
|
|
19
|
+
readonly op: "search" | "list" | "find" | "voices";
|
|
20
|
+
readonly input?: CatalogArguments;
|
|
21
|
+
readonly cursor?: string;
|
|
22
|
+
readonly limit?: number;
|
|
23
|
+
}
|
|
24
|
+
export interface ReadToolInput {
|
|
25
|
+
/** Bypass context-relative deltas and return the complete result. */
|
|
26
|
+
readonly full?: boolean;
|
|
27
|
+
/** Omitted resource means this Session's graph. */
|
|
28
|
+
readonly resource?: "graph" | "view" | "session" | "artifact" | "material" | "applet" | "patch" | "update";
|
|
29
|
+
readonly input?: CatalogArguments;
|
|
30
|
+
readonly cursor?: string;
|
|
31
|
+
readonly limit?: number;
|
|
32
|
+
}
|
|
33
|
+
export interface TheoryToolInput {
|
|
34
|
+
readonly full?: boolean;
|
|
35
|
+
readonly name: string;
|
|
36
|
+
readonly input?: CatalogArguments;
|
|
37
|
+
}
|
|
38
|
+
export interface EvaluationToolInput {
|
|
39
|
+
readonly op: "watch" | "stop" | "judge" | "override" | "record" | "retract" | "claim";
|
|
40
|
+
/** Required for record; artifact filing is a host operation, not theory evidence. */
|
|
41
|
+
readonly kind?: "demonstration" | "material-attempt" | "retrieval-opener" | "teaching" | "claim-attachment" | "interpretation-correction" | "close-recount" | "artifact";
|
|
42
|
+
readonly input: CatalogArguments;
|
|
43
|
+
}
|
|
44
|
+
export interface MaterialToolInput {
|
|
45
|
+
readonly op: "add" | "edit" | "remove" | "open" | "command";
|
|
46
|
+
/** Existing Playground identities remain the stored Material kinds. */
|
|
47
|
+
readonly kind: string;
|
|
48
|
+
readonly input: CatalogArguments;
|
|
49
|
+
/** Applet declared command name, or audio's generate command. */
|
|
50
|
+
readonly command?: string;
|
|
51
|
+
}
|
|
52
|
+
/** The web-host generic absorbs media download without changing the media result. */
|
|
53
|
+
export interface FetchPageToolInput {
|
|
54
|
+
readonly url: string;
|
|
55
|
+
readonly op?: "read" | "download";
|
|
56
|
+
}
|
|
57
|
+
export interface ProposeToolInput {
|
|
58
|
+
readonly op: "graph-diff" | "mission" | "revision" | "preferences" | "settings" | "mode" | "missing-capability";
|
|
59
|
+
readonly input: CatalogArguments;
|
|
60
|
+
}
|
|
61
|
+
export interface SkillToolInput {
|
|
62
|
+
readonly name: string;
|
|
63
|
+
/** A relative resource filename in the named Skill, never an arbitrary filesystem path. */
|
|
64
|
+
readonly resource?: string;
|
|
65
|
+
}
|
|
66
|
+
export interface GraphReadOptions {
|
|
67
|
+
/** Defaults to the Session's attached Nodes; explicit nodes override that selection. */
|
|
68
|
+
readonly scope?: "session" | "all";
|
|
69
|
+
readonly nodes?: readonly NodeId[];
|
|
70
|
+
/** Source is an explicit authoring read of raw metadata and tags. */
|
|
71
|
+
readonly projection?: "compact" | "source";
|
|
72
|
+
readonly provenance?: boolean;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* A compact graph stores every surviving origin entry once. Expanding a Node's ordered
|
|
76
|
+
* references must equal nodeTutorGuidance(graph, node), with independent keep/replace per kind.
|
|
77
|
+
*/
|
|
78
|
+
export interface CompactGuidance {
|
|
79
|
+
readonly guidance: Readonly<Record<string, TutorGuidanceEntry>>;
|
|
80
|
+
readonly effectiveGuidance: Readonly<Partial<Record<NodeId, readonly string[]>>>;
|
|
81
|
+
}
|
|
82
|
+
/** Modes whose evaluation is narrower than Lesson's; the rest mount every operation. Chart records self-report, and grading happens in Lessons. */
|
|
83
|
+
export declare const CATALOG_EVALUATION_OPERATIONS: Readonly<Partial<Record<keyof typeof CATALOG_MODE_TOOLS, readonly string[]>>>;
|
|
84
|
+
/** Finalization can read only; these roots expose no writing operations. */
|
|
85
|
+
export declare const CATALOG_READ_ONLY_TOOLS: readonly ["theory", "query", "read"];
|
|
86
|
+
/** Harness excludes only these host generics, never a second domain-tool catalog. */
|
|
87
|
+
export declare const CATALOG_WEB_ONLY_TOOLS: readonly ["web_search", "fetch_page", "bash"];
|
|
88
|
+
/** Titles change; existing stored mode identities do not. */
|
|
89
|
+
export declare const CATALOG_MODE_TITLES: {
|
|
90
|
+
readonly empty: "Chat";
|
|
91
|
+
readonly charting: "Chart";
|
|
92
|
+
readonly authoring: "Author";
|
|
93
|
+
readonly lesson: "Lesson";
|
|
94
|
+
};
|
|
95
|
+
export declare const CATALOG_MODE_TOOLS: {
|
|
96
|
+
readonly empty: readonly ["query", "read", "theory", "skill", "report_friction", "propose"];
|
|
97
|
+
readonly charting: readonly ["evaluation", "query", "read", "theory", "skill", "report_friction", "edit_graph_draft", "propose", "web_search", "fetch_page", "code", "bash", "undo"];
|
|
98
|
+
readonly authoring: readonly ["query", "read", "theory", "skill", "report_friction", "edit_graph_draft", "propose", "web_search", "fetch_page", "code", "bash", "undo", "material"];
|
|
99
|
+
readonly lesson: readonly ["query", "read", "theory", "skill", "report_friction", "material", "edit_metadata", "evaluation", "propose", "code", "bash", "undo", "fetch_page"];
|
|
100
|
+
};
|
|
101
|
+
/** The keys each mode's edit_metadata may write; the tool is mounted only where a list exists. */
|
|
102
|
+
export declare const CATALOG_MODE_METADATA_KEYS: Readonly<Partial<Record<keyof typeof CATALOG_MODE_TOOLS, readonly string[]>>>;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transport contracts for the catalog consolidation. These declarations mount nothing:
|
|
3
|
+
* the implementation tickets supply the Programs and host handlers.
|
|
4
|
+
*/
|
|
5
|
+
export const CATALOG_PAGE_SIZE = 20;
|
|
6
|
+
/** Per-page safety only: larger collections remain traversable with cursors. */
|
|
7
|
+
export const CATALOG_MAX_PAGE_SIZE = 100;
|
|
8
|
+
/** Modes whose evaluation is narrower than Lesson's; the rest mount every operation. Chart records self-report, and grading happens in Lessons. */
|
|
9
|
+
export const CATALOG_EVALUATION_OPERATIONS = {
|
|
10
|
+
charting: ["claim", "retract"],
|
|
11
|
+
};
|
|
12
|
+
/** Finalization can read only; these roots expose no writing operations. */
|
|
13
|
+
export const CATALOG_READ_ONLY_TOOLS = ["theory", "query", "read"];
|
|
14
|
+
/** Harness excludes only these host generics, never a second domain-tool catalog. */
|
|
15
|
+
export const CATALOG_WEB_ONLY_TOOLS = ["web_search", "fetch_page", "bash"];
|
|
16
|
+
/** Titles change; existing stored mode identities do not. */
|
|
17
|
+
export const CATALOG_MODE_TITLES = {
|
|
18
|
+
empty: "Chat",
|
|
19
|
+
charting: "Chart",
|
|
20
|
+
authoring: "Author",
|
|
21
|
+
lesson: "Lesson",
|
|
22
|
+
};
|
|
23
|
+
export const CATALOG_MODE_TOOLS = {
|
|
24
|
+
empty: ["query", "read", "theory", "skill", "report_friction", "propose"],
|
|
25
|
+
charting: [
|
|
26
|
+
"evaluation",
|
|
27
|
+
"query",
|
|
28
|
+
"read",
|
|
29
|
+
"theory",
|
|
30
|
+
"skill",
|
|
31
|
+
"report_friction",
|
|
32
|
+
"edit_graph_draft",
|
|
33
|
+
"propose",
|
|
34
|
+
"web_search",
|
|
35
|
+
"fetch_page",
|
|
36
|
+
"code",
|
|
37
|
+
"bash",
|
|
38
|
+
"undo",
|
|
39
|
+
],
|
|
40
|
+
// Author proposes Missions and revisions that the captured Patch ships.
|
|
41
|
+
authoring: [
|
|
42
|
+
"query",
|
|
43
|
+
"read",
|
|
44
|
+
"theory",
|
|
45
|
+
"skill",
|
|
46
|
+
"report_friction",
|
|
47
|
+
"edit_graph_draft",
|
|
48
|
+
"propose",
|
|
49
|
+
"web_search",
|
|
50
|
+
"fetch_page",
|
|
51
|
+
"code",
|
|
52
|
+
"bash",
|
|
53
|
+
"undo",
|
|
54
|
+
"material",
|
|
55
|
+
],
|
|
56
|
+
lesson: [
|
|
57
|
+
"query",
|
|
58
|
+
"read",
|
|
59
|
+
"theory",
|
|
60
|
+
"skill",
|
|
61
|
+
"report_friction",
|
|
62
|
+
"material",
|
|
63
|
+
"edit_metadata",
|
|
64
|
+
"evaluation",
|
|
65
|
+
"propose",
|
|
66
|
+
"code",
|
|
67
|
+
"bash",
|
|
68
|
+
"undo",
|
|
69
|
+
"fetch_page",
|
|
70
|
+
],
|
|
71
|
+
};
|
|
72
|
+
/** The keys each mode's edit_metadata may write; the tool is mounted only where a list exists. */
|
|
73
|
+
export const CATALOG_MODE_METADATA_KEYS = {
|
|
74
|
+
lesson: ["pedagogy:completion"],
|
|
75
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { CATALOG_MODE_TOOLS } from "./catalog-contract.js";
|
|
2
|
+
import type { Tool } from "@mmon-co/ncept-core/theory";
|
|
3
|
+
import type { DefaultState } from "./state.js";
|
|
4
|
+
type DefaultTool = Tool<unknown, unknown, DefaultState>;
|
|
5
|
+
/** Resolve before running so the host can validate the original schema and enrich items. */
|
|
6
|
+
export declare function resolveDefaultCatalogProgram(name: string, raw: unknown, mode?: string): {
|
|
7
|
+
tool: DefaultTool;
|
|
8
|
+
input: Record<string, unknown>;
|
|
9
|
+
};
|
|
10
|
+
/** Web hosts mount envelopes; native hosts mount their declared members. */
|
|
11
|
+
export declare const defaultCatalogTools: readonly DefaultTool[];
|
|
12
|
+
/** The mode's catalog roots; Chart's evaluation only records self-report and corrects evidence. */
|
|
13
|
+
export declare function catalogToolsForMode(mode: keyof typeof CATALOG_MODE_TOOLS): readonly DefaultTool[];
|
|
14
|
+
export {};
|
package/dist/catalog.js
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { evaluationTools } from "./evaluation.js";
|
|
2
|
+
import { CATALOG_EVALUATION_OPERATIONS, CATALOG_MODE_TOOLS } from "./catalog-contract.js";
|
|
3
|
+
import { defaultInstrumentTools, defaultRecordingTools, defaultBackgroundTools } from "./tools.js";
|
|
4
|
+
const theoryNames = [
|
|
5
|
+
"frontier",
|
|
6
|
+
"route",
|
|
7
|
+
"interpretations",
|
|
8
|
+
"trail",
|
|
9
|
+
"coverage",
|
|
10
|
+
"probes",
|
|
11
|
+
"warnings",
|
|
12
|
+
"items",
|
|
13
|
+
"memory",
|
|
14
|
+
"mission",
|
|
15
|
+
];
|
|
16
|
+
const theoryReadings = defaultInstrumentTools.filter((tool) => theoryNames.includes(tool.name));
|
|
17
|
+
const programs = [...defaultInstrumentTools, ...defaultRecordingTools, ...defaultBackgroundTools, ...evaluationTools];
|
|
18
|
+
function program(name) {
|
|
19
|
+
const found = programs.find((tool) => tool.name === name);
|
|
20
|
+
if (!found)
|
|
21
|
+
throw new Error("Missing catalog Program: " + name);
|
|
22
|
+
return found;
|
|
23
|
+
}
|
|
24
|
+
const records = {
|
|
25
|
+
demonstration: "record_demonstration",
|
|
26
|
+
"material-attempt": "record_material_attempt",
|
|
27
|
+
"retrieval-opener": "record_retrieval_opener",
|
|
28
|
+
teaching: "record_teaching",
|
|
29
|
+
"claim-attachment": "attach_claim",
|
|
30
|
+
"interpretation-correction": "correct_interpretation",
|
|
31
|
+
"close-recount": "close_recount",
|
|
32
|
+
};
|
|
33
|
+
const evaluationOperations = [
|
|
34
|
+
...Object.entries(records).map(([kind, name]) => ({ op: "record", kind, tool: program(name) })),
|
|
35
|
+
...["watch", "stop", "judge", "override", "claim", "retract"].map((op) => ({
|
|
36
|
+
op,
|
|
37
|
+
kind: undefined,
|
|
38
|
+
tool: program(op === "claim" ? "record_claim" : op === "retract" ? "record_retraction" : "evaluation_" + op),
|
|
39
|
+
})),
|
|
40
|
+
];
|
|
41
|
+
function isObject(raw) {
|
|
42
|
+
return typeof raw === "object" && raw !== null && !Array.isArray(raw);
|
|
43
|
+
}
|
|
44
|
+
function object(raw) {
|
|
45
|
+
if (!isObject(raw))
|
|
46
|
+
throw new Error("Catalog arguments must be an object");
|
|
47
|
+
return raw;
|
|
48
|
+
}
|
|
49
|
+
function evaluationOperationsFor(mode) {
|
|
50
|
+
const narrowed = CATALOG_EVALUATION_OPERATIONS;
|
|
51
|
+
const allowed = mode !== undefined && Object.hasOwn(narrowed, mode) ? narrowed[mode] : undefined;
|
|
52
|
+
return allowed === undefined ? evaluationOperations : evaluationOperations.filter(({ op }) => allowed.includes(op));
|
|
53
|
+
}
|
|
54
|
+
/** Resolve before running so the host can validate the original schema and enrich items. */
|
|
55
|
+
export function resolveDefaultCatalogProgram(name, raw, mode) {
|
|
56
|
+
const envelope = object(raw);
|
|
57
|
+
const operations = evaluationOperationsFor(mode);
|
|
58
|
+
const allowed = name === "theory" ? ["name", "input", "full"] : ["op", "kind", "input"];
|
|
59
|
+
if (name !== "theory" && name !== "evaluation")
|
|
60
|
+
throw new Error("Unsupported catalog");
|
|
61
|
+
if (Object.keys(envelope).some((key) => !allowed.includes(key)))
|
|
62
|
+
throw new Error("Unknown catalog argument");
|
|
63
|
+
if (name === "theory" && envelope.full !== undefined && typeof envelope.full !== "boolean")
|
|
64
|
+
throw new Error("Invalid full flag");
|
|
65
|
+
const tool = name === "theory"
|
|
66
|
+
? theoryReadings.find((reading) => reading.name === envelope.name)
|
|
67
|
+
: operations.find((entry) => entry.op === envelope.op && entry.kind === envelope.kind)?.tool;
|
|
68
|
+
if (tool === undefined && name === "evaluation" && operations !== evaluationOperations)
|
|
69
|
+
throw new Error(`This mode's evaluation accepts ${operations.map(({ op }) => op).join(", ")}; grade work in a Lesson's Materials`);
|
|
70
|
+
if (tool === undefined && name === "evaluation" && envelope.kind !== undefined && envelope.op !== "record")
|
|
71
|
+
throw new Error(`kind applies only to op record (kinds: ${Object.keys(records).join(", ")}); ${String(envelope.op)} takes no kind`);
|
|
72
|
+
if (tool === undefined && name === "evaluation" && envelope.op === "record")
|
|
73
|
+
throw new Error("op record needs kind: " + Object.keys(records).join(", "));
|
|
74
|
+
if (tool === undefined)
|
|
75
|
+
throw new Error(name === "theory"
|
|
76
|
+
? "Theory name accepts " + theoryReadings.map((reading) => reading.name).join(", ")
|
|
77
|
+
: "Evaluation accepts " + evaluationOperations.map(({ op, kind }) => op + (kind ? "/" + kind : "")).join(", "));
|
|
78
|
+
try {
|
|
79
|
+
return {
|
|
80
|
+
tool: name !== "theory"
|
|
81
|
+
? tool
|
|
82
|
+
: {
|
|
83
|
+
...tool,
|
|
84
|
+
*run(input, ctx) {
|
|
85
|
+
try {
|
|
86
|
+
return yield* tool.run(input, ctx);
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
throw new Error(`${String(error)}. ${tool.name} input accepts ${JSON.stringify(tool.schema)}; Nodes must exist in the graph.`);
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
input: object(name === "theory" && envelope.input === undefined ? {} : envelope.input),
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
throw new Error(`${String(error)}. ${tool.name} input accepts ${JSON.stringify(tool.schema)}`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/** Web hosts mount envelopes; native hosts mount their declared members. */
|
|
101
|
+
export const defaultCatalogTools = [
|
|
102
|
+
{
|
|
103
|
+
name: "theory",
|
|
104
|
+
members: theoryReadings,
|
|
105
|
+
description: "Read theory facts. Node inputs name existing Nodes from the graph, never Session identities. Interpretations return source handles: retrieval context, never labels or evidence. Trail defaults to limit 20; follow continueCursor, restart on stale cursor.",
|
|
106
|
+
schema: {
|
|
107
|
+
type: "object",
|
|
108
|
+
// Top-level properties beside the variants: without them DeepSeek sent input as a JSON string.
|
|
109
|
+
properties: { name: { enum: theoryNames }, input: { type: "object" }, full: { type: "boolean" } },
|
|
110
|
+
required: ["name"],
|
|
111
|
+
oneOf: theoryReadings.map((reading) => ({
|
|
112
|
+
type: "object",
|
|
113
|
+
properties: { name: { const: reading.name }, input: reading.schema, full: { type: "boolean" } },
|
|
114
|
+
required: [
|
|
115
|
+
"name",
|
|
116
|
+
...(Array.isArray(reading.schema.required) && reading.schema.required.length ? ["input"] : []),
|
|
117
|
+
],
|
|
118
|
+
additionalProperties: false,
|
|
119
|
+
})),
|
|
120
|
+
},
|
|
121
|
+
*run(raw, ctx) {
|
|
122
|
+
const { tool, input } = resolveDefaultCatalogProgram("theory", raw);
|
|
123
|
+
return yield* tool.run(input, ctx);
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
evaluationCatalogTool(undefined),
|
|
127
|
+
];
|
|
128
|
+
/** The mode's catalog roots; Chart's evaluation only records self-report and corrects evidence. */
|
|
129
|
+
export function catalogToolsForMode(mode) {
|
|
130
|
+
const roots = CATALOG_MODE_TOOLS[mode];
|
|
131
|
+
return defaultCatalogTools
|
|
132
|
+
.filter((tool) => roots.includes(tool.name))
|
|
133
|
+
.map((tool) => (tool.name === "evaluation" ? evaluationCatalogTool(mode) : tool));
|
|
134
|
+
}
|
|
135
|
+
function evaluationCatalogTool(mode) {
|
|
136
|
+
const operations = evaluationOperationsFor(mode);
|
|
137
|
+
const recording = operations.some(({ op }) => op === "record");
|
|
138
|
+
return {
|
|
139
|
+
name: "evaluation",
|
|
140
|
+
members: operations.map(({ tool }) => tool),
|
|
141
|
+
description: operations === evaluationOperations
|
|
142
|
+
? "Delegate chat checks: watch grades subsequent learner replies; stop ends it; judge grades one response (message selects original learner media). Grader decision uses the Account decision model. Host records per-Node verdicts and returns criterion probabilities; do not record them again. Usually delegate rather than manually record. Record/material-attempt grades a Material item answered in chat; identical retries return the existing Record, later different answers get new Records. A runner's outcome stays the record. Override corrects a delegated or Material Record with a reason; claim records self-report; retract corrects evidence. Before an interpretation-correction, read that interpretation's current handles with theory interpretations. A close-recount carries no citations. Artifact filing is host-owned."
|
|
143
|
+
: "Record evidence that needs no grading: claim records self-report; retract corrects evidence. Nothing here grades a response; graded checks happen in a Lesson's Materials. Artifact filing is host-owned.",
|
|
144
|
+
schema: {
|
|
145
|
+
type: "object",
|
|
146
|
+
properties: {
|
|
147
|
+
op: { enum: [...new Set(operations.map(({ op }) => op))] },
|
|
148
|
+
...(recording ? { kind: { enum: Object.keys(records), description: "Only with op record" } } : {}),
|
|
149
|
+
input: { type: "object" },
|
|
150
|
+
},
|
|
151
|
+
required: ["op", "input"],
|
|
152
|
+
oneOf: operations.map(({ op, kind, tool }) => ({
|
|
153
|
+
type: "object",
|
|
154
|
+
properties: { op: { const: op }, ...(kind ? { kind: { const: kind } } : {}), input: tool.schema },
|
|
155
|
+
required: ["op", "input", ...(kind ? ["kind"] : [])],
|
|
156
|
+
additionalProperties: false,
|
|
157
|
+
})),
|
|
158
|
+
},
|
|
159
|
+
*run(raw, ctx) {
|
|
160
|
+
const { tool, input } = resolveDefaultCatalogProgram("evaluation", raw, mode);
|
|
161
|
+
return yield* tool.run(input, ctx);
|
|
162
|
+
},
|
|
163
|
+
};
|
|
164
|
+
}
|
package/dist/chat.d.ts
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { type NodeId } from "@mmon-co/ncept-core/patch";
|
|
2
|
+
import type { Program } from "@mmon-co/ncept-core/observations";
|
|
3
|
+
import type { ChatContext, ChatSetup } from "@mmon-co/ncept-core/theory";
|
|
4
|
+
import type { HostCapability } from "@mmon-co/ncept-core/theory";
|
|
5
|
+
import { type DefaultState } from "./state.js";
|
|
6
|
+
import { evaluateWatchedReply } from "./evaluation.js";
|
|
7
|
+
type ProductDocument = {
|
|
8
|
+
readonly node: NodeId;
|
|
9
|
+
readonly label: string;
|
|
10
|
+
readonly summary: string;
|
|
11
|
+
readonly documentId: string;
|
|
12
|
+
};
|
|
13
|
+
type Recommendation = ProductDocument & {
|
|
14
|
+
readonly raiseWhen: string;
|
|
15
|
+
readonly documentUrl: string;
|
|
16
|
+
};
|
|
17
|
+
export declare function documentListing(ctx: ChatContext<DefaultState>): {
|
|
18
|
+
documents: ProductDocument[];
|
|
19
|
+
candidates: Recommendation[];
|
|
20
|
+
};
|
|
21
|
+
declare function setup(ctx: ChatContext<DefaultState>, mode?: "empty" | "charting" | "authoring" | "lesson"): Program<ChatSetup<DefaultState>>;
|
|
22
|
+
/**
|
|
23
|
+
* The host supplies a current value context at both entry points, including cross-surface
|
|
24
|
+
* evidence. The learner's saved preferences are not part of it: the Application assembles them
|
|
25
|
+
* into the interactive conversation it is running, so no theory Program can read or cite them.
|
|
26
|
+
*/
|
|
27
|
+
export declare const chat: {
|
|
28
|
+
open: typeof setup;
|
|
29
|
+
turn: typeof setup;
|
|
30
|
+
reply: typeof evaluateWatchedReply;
|
|
31
|
+
};
|
|
32
|
+
/** The default theory’s Session choices; host capabilities are mounted separately. */
|
|
33
|
+
export declare const modes: {
|
|
34
|
+
empty: {
|
|
35
|
+
title: "Chat";
|
|
36
|
+
frontTab: string;
|
|
37
|
+
entry: {
|
|
38
|
+
required: false;
|
|
39
|
+
kinds: never[];
|
|
40
|
+
};
|
|
41
|
+
capabilities: readonly HostCapability[];
|
|
42
|
+
switches: {
|
|
43
|
+
mode: string;
|
|
44
|
+
then: "here";
|
|
45
|
+
}[];
|
|
46
|
+
setup: (ctx: ChatContext<DefaultState>) => Program<Readonly<{
|
|
47
|
+
prompt: string;
|
|
48
|
+
context?: string;
|
|
49
|
+
tools: readonly Readonly<{
|
|
50
|
+
name: string;
|
|
51
|
+
description: string;
|
|
52
|
+
schema: import("@mmon-co/ncept-core/observations").JsonSchema;
|
|
53
|
+
members?: readonly Readonly</*elided*/ any>[] | undefined;
|
|
54
|
+
run(args: unknown, ctx: ChatContext<DefaultState>): Program<unknown>;
|
|
55
|
+
}>[];
|
|
56
|
+
skills: readonly Readonly<{
|
|
57
|
+
name: string;
|
|
58
|
+
description: string;
|
|
59
|
+
body: string;
|
|
60
|
+
resources?: readonly import("@mmon-co/ncept-core/theory").SkillResource[];
|
|
61
|
+
}>[];
|
|
62
|
+
}>>;
|
|
63
|
+
};
|
|
64
|
+
charting: {
|
|
65
|
+
title: "Chart";
|
|
66
|
+
frontTab: string;
|
|
67
|
+
noteTemplates: {
|
|
68
|
+
id: string;
|
|
69
|
+
defaultMessage: string;
|
|
70
|
+
}[];
|
|
71
|
+
entry: {
|
|
72
|
+
required: false;
|
|
73
|
+
kinds: ("mission" | "checkpoint" | "goal" | "target")[];
|
|
74
|
+
};
|
|
75
|
+
capabilities: readonly HostCapability[];
|
|
76
|
+
switches: {
|
|
77
|
+
mode: string;
|
|
78
|
+
then: "next";
|
|
79
|
+
carry: {
|
|
80
|
+
kind: "brief";
|
|
81
|
+
};
|
|
82
|
+
}[];
|
|
83
|
+
setup: (ctx: ChatContext<DefaultState>) => Program<Readonly<{
|
|
84
|
+
prompt: string;
|
|
85
|
+
context?: string;
|
|
86
|
+
tools: readonly Readonly<{
|
|
87
|
+
name: string;
|
|
88
|
+
description: string;
|
|
89
|
+
schema: import("@mmon-co/ncept-core/observations").JsonSchema;
|
|
90
|
+
members?: readonly Readonly</*elided*/ any>[] | undefined;
|
|
91
|
+
run(args: unknown, ctx: ChatContext<DefaultState>): Program<unknown>;
|
|
92
|
+
}>[];
|
|
93
|
+
skills: readonly Readonly<{
|
|
94
|
+
name: string;
|
|
95
|
+
description: string;
|
|
96
|
+
body: string;
|
|
97
|
+
resources?: readonly import("@mmon-co/ncept-core/theory").SkillResource[];
|
|
98
|
+
}>[];
|
|
99
|
+
}>>;
|
|
100
|
+
};
|
|
101
|
+
authoring: {
|
|
102
|
+
title: "Author";
|
|
103
|
+
frontTab: string;
|
|
104
|
+
entry: {
|
|
105
|
+
required: false;
|
|
106
|
+
kinds: ("mission" | "goal")[];
|
|
107
|
+
};
|
|
108
|
+
capabilities: readonly HostCapability[];
|
|
109
|
+
switches: never[];
|
|
110
|
+
setup: (ctx: ChatContext<DefaultState>) => Program<Readonly<{
|
|
111
|
+
prompt: string;
|
|
112
|
+
context?: string;
|
|
113
|
+
tools: readonly Readonly<{
|
|
114
|
+
name: string;
|
|
115
|
+
description: string;
|
|
116
|
+
schema: import("@mmon-co/ncept-core/observations").JsonSchema;
|
|
117
|
+
members?: readonly Readonly</*elided*/ any>[] | undefined;
|
|
118
|
+
run(args: unknown, ctx: ChatContext<DefaultState>): Program<unknown>;
|
|
119
|
+
}>[];
|
|
120
|
+
skills: readonly Readonly<{
|
|
121
|
+
name: string;
|
|
122
|
+
description: string;
|
|
123
|
+
body: string;
|
|
124
|
+
resources?: readonly import("@mmon-co/ncept-core/theory").SkillResource[];
|
|
125
|
+
}>[];
|
|
126
|
+
}>>;
|
|
127
|
+
};
|
|
128
|
+
lesson: {
|
|
129
|
+
title: "Lesson";
|
|
130
|
+
frontTab: string;
|
|
131
|
+
entry: {
|
|
132
|
+
required: true;
|
|
133
|
+
kinds: ("lesson" | "review")[];
|
|
134
|
+
};
|
|
135
|
+
capabilities: readonly HostCapability[];
|
|
136
|
+
metadataKeys: readonly string[] | undefined;
|
|
137
|
+
switches: ({
|
|
138
|
+
mode: string;
|
|
139
|
+
then: "next";
|
|
140
|
+
carry: {
|
|
141
|
+
kind: "brief";
|
|
142
|
+
focus?: undefined;
|
|
143
|
+
};
|
|
144
|
+
} | {
|
|
145
|
+
mode: string;
|
|
146
|
+
then: "aside";
|
|
147
|
+
carry: {
|
|
148
|
+
kind: "compacted";
|
|
149
|
+
focus: string;
|
|
150
|
+
};
|
|
151
|
+
})[];
|
|
152
|
+
setup: (ctx: ChatContext<DefaultState>) => Program<Readonly<{
|
|
153
|
+
prompt: string;
|
|
154
|
+
context?: string;
|
|
155
|
+
tools: readonly Readonly<{
|
|
156
|
+
name: string;
|
|
157
|
+
description: string;
|
|
158
|
+
schema: import("@mmon-co/ncept-core/observations").JsonSchema;
|
|
159
|
+
members?: readonly Readonly</*elided*/ any>[] | undefined;
|
|
160
|
+
run(args: unknown, ctx: ChatContext<DefaultState>): Program<unknown>;
|
|
161
|
+
}>[];
|
|
162
|
+
skills: readonly Readonly<{
|
|
163
|
+
name: string;
|
|
164
|
+
description: string;
|
|
165
|
+
body: string;
|
|
166
|
+
resources?: readonly import("@mmon-co/ncept-core/theory").SkillResource[];
|
|
167
|
+
}>[];
|
|
168
|
+
}>>;
|
|
169
|
+
};
|
|
170
|
+
};
|
|
171
|
+
export {};
|