@zaowu-labs/teach 1.0.1

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/README.md ADDED
@@ -0,0 +1,12 @@
1
+ # @zaowu-labs/teach
2
+
3
+ Teaching workflow package for ZaoWu.
4
+
5
+ This package provides deterministic local teaching-plan and quiz generation for
6
+ the first CLI foundation.
7
+
8
+ Safety:
9
+
10
+ - It does not call external AI services.
11
+ - Future AI-backed teaching behavior should go through `@zaowu-labs/ai`.
12
+ - User-facing commands should keep output readable before adding complexity.
@@ -0,0 +1,23 @@
1
+ import { type DomainDefinition } from '@zaowu-labs/core';
2
+ export interface TeachPlanResult {
3
+ schemaVersion: 1;
4
+ status: 'ok';
5
+ topic: string;
6
+ outline: string[];
7
+ }
8
+ export interface TeachQuizResult {
9
+ schemaVersion: 1;
10
+ status: 'ok';
11
+ topic: string;
12
+ questionCount: number;
13
+ questions: string[];
14
+ format?: string;
15
+ content?: string;
16
+ }
17
+ export declare const TEACH_DOMAIN: DomainDefinition;
18
+ export declare const createTeachingPlan: (input: string) => Promise<TeachPlanResult>;
19
+ export declare const createTeachingQuiz: (input: string, options?: {
20
+ format?: string;
21
+ count?: number;
22
+ }) => Promise<TeachQuizResult>;
23
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAsC,KAAK,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAE7F,MAAM,WAAW,eAAe;IAC9B,aAAa,EAAE,CAAC,CAAC;IACjB,MAAM,EAAE,IAAI,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,MAAM,WAAW,eAAe;IAC9B,aAAa,EAAE,CAAC,CAAC;IACjB,MAAM,EAAE,IAAI,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAKD,eAAO,MAAM,YAAY,EAAE,gBAkB1B,CAAC;AA8CF,eAAO,MAAM,kBAAkB,GAAU,OAAO,MAAM,KAAG,OAAO,CAAC,eAAe,CA6B/E,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAC7B,OAAO,MAAM,EACb,UAAS;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAO,KAChD,OAAO,CAAC,eAAe,CA0CzB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,124 @@
1
+ import { readFile } from 'node:fs/promises';
2
+ import { createCapabilityLedger, ZaoWuError } from '@zaowu-labs/core';
3
+ const DEFAULT_QUIZ_COUNT = 3;
4
+ const MAX_QUIZ_COUNT = 20;
5
+ export const TEACH_DOMAIN = {
6
+ name: 'teach',
7
+ summary: 'Teaching workflows for lesson planning and practice materials',
8
+ capabilities: createCapabilityLedger({
9
+ readsFiles: true,
10
+ }),
11
+ commands: [
12
+ {
13
+ name: 'plan',
14
+ summary: 'Create a teaching plan',
15
+ status: 'available',
16
+ },
17
+ {
18
+ name: 'quiz',
19
+ summary: 'Create practice questions from provided material',
20
+ status: 'available',
21
+ },
22
+ ],
23
+ };
24
+ const readTopicOrFile = async (input) => {
25
+ if (!input.trim()) {
26
+ throw new ZaoWuError({
27
+ code: 'TEACH_INPUT_REQUIRED',
28
+ message: 'Teaching input is required.',
29
+ why: '`zw teach` needs a topic, text, or readable file path.',
30
+ fix: 'Run `zw teach plan "TypeScript basics"`.',
31
+ });
32
+ }
33
+ try {
34
+ return await readFile(input, 'utf8');
35
+ }
36
+ catch {
37
+ // Not a readable file path — treat the input as a literal topic string.
38
+ return input;
39
+ }
40
+ };
41
+ const getTopic = (content) => {
42
+ const firstLine = content
43
+ .split(/\r?\n/)
44
+ .map((line) => line.replace(/^#+\s*/, '').trim())
45
+ .find(Boolean);
46
+ return firstLine ?? 'Untitled topic';
47
+ };
48
+ const getSentences = (content) => content
49
+ .split(/[.!?\n。!?]+/)
50
+ .map((sentence) => sentence.trim())
51
+ .filter(Boolean);
52
+ /**
53
+ * Extract heading lines from markdown-like content.
54
+ * Returns bare heading text without the leading # characters.
55
+ */
56
+ const getHeadings = (content) => content
57
+ .split(/\r?\n/)
58
+ .filter((line) => /^#{1,6}\s/.test(line))
59
+ .map((line) => line.replace(/^#+\s*/, '').trim())
60
+ .filter(Boolean);
61
+ export const createTeachingPlan = async (input) => {
62
+ const content = await readTopicOrFile(input);
63
+ const topic = getTopic(content);
64
+ const headings = getHeadings(content);
65
+ // Build a richer outline when the content has discoverable section headings.
66
+ const outline = headings.length > 1
67
+ ? [
68
+ `Goal: understand ${topic}.`,
69
+ 'Warm-up: ask what the learner already knows.',
70
+ ...headings.slice(1).map((h, i) => `Section ${i + 1}: ${h}`),
71
+ 'Practice: complete a short guided exercise.',
72
+ 'Check: summarize the key point and one common mistake.',
73
+ ]
74
+ : [
75
+ `Goal: understand ${topic}.`,
76
+ 'Warm-up: ask what the learner already knows.',
77
+ 'Explain: introduce the core idea with one concrete example.',
78
+ 'Practice: complete a short guided exercise.',
79
+ 'Check: summarize the key point and one common mistake.',
80
+ ];
81
+ return {
82
+ schemaVersion: 1,
83
+ status: 'ok',
84
+ topic,
85
+ outline,
86
+ };
87
+ };
88
+ export const createTeachingQuiz = async (input, options = {}) => {
89
+ const rawCount = options.count ?? DEFAULT_QUIZ_COUNT;
90
+ if (!Number.isInteger(rawCount) || rawCount < 1 || rawCount > MAX_QUIZ_COUNT) {
91
+ throw new ZaoWuError({
92
+ code: 'TEACH_INPUT_REQUIRED',
93
+ message: 'Quiz count is out of range.',
94
+ why: `Question count must be a whole number between 1 and ${MAX_QUIZ_COUNT}, but got ${rawCount}.`,
95
+ fix: 'Run `zw teach quiz --count 5 "your topic"` to generate 5 questions.',
96
+ });
97
+ }
98
+ const count = rawCount;
99
+ const content = await readTopicOrFile(input);
100
+ const topic = getTopic(content);
101
+ const sentences = getSentences(content).slice(0, count);
102
+ const questions = sentences.length > 0
103
+ ? sentences.map((sentence, index) => `Q${index + 1}: Explain this idea in your own words: ${sentence}.`)
104
+ : [`Q1: What is the main idea of ${topic}?`];
105
+ const format = options.format === 'canvas-csv' ? 'canvas-csv' : 'text';
106
+ let resultCsv = '';
107
+ if (format === 'canvas-csv') {
108
+ const lines = [
109
+ 'Type,Question Text,Points',
110
+ ...questions.map((q) => `E,"${q.replaceAll('"', '""')}",1`),
111
+ ];
112
+ resultCsv = lines.join('\n') + '\n';
113
+ }
114
+ return {
115
+ schemaVersion: 1,
116
+ status: 'ok',
117
+ topic,
118
+ questionCount: questions.length,
119
+ questions,
120
+ format,
121
+ content: format === 'canvas-csv' ? resultCsv : undefined,
122
+ };
123
+ };
124
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,sBAAsB,EAAE,UAAU,EAAyB,MAAM,kBAAkB,CAAC;AAmB7F,MAAM,kBAAkB,GAAG,CAAC,CAAC;AAC7B,MAAM,cAAc,GAAG,EAAE,CAAC;AAE1B,MAAM,CAAC,MAAM,YAAY,GAAqB;IAC5C,IAAI,EAAE,OAAO;IACb,OAAO,EAAE,+DAA+D;IACxE,YAAY,EAAE,sBAAsB,CAAC;QACnC,UAAU,EAAE,IAAI;KACjB,CAAC;IACF,QAAQ,EAAE;QACR;YACE,IAAI,EAAE,MAAM;YACZ,OAAO,EAAE,wBAAwB;YACjC,MAAM,EAAE,WAAW;SACpB;QACD;YACE,IAAI,EAAE,MAAM;YACZ,OAAO,EAAE,kDAAkD;YAC3D,MAAM,EAAE,WAAW;SACpB;KACF;CACF,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,KAAK,YAAY,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS;KACzD,CAAC;AACJ,CAAC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@zaowu-labs/teach",
3
+ "version": "1.0.1",
4
+ "description": "ZaoWu teaching workflows",
5
+ "type": "module",
6
+ "license": "Apache-2.0",
7
+ "publishConfig": {
8
+ "access": "public"
9
+ },
10
+ "files": [
11
+ "dist",
12
+ "README.md"
13
+ ],
14
+ "main": "./dist/index.js",
15
+ "types": "./dist/index.d.ts",
16
+ "exports": {
17
+ ".": {
18
+ "types": "./dist/index.d.ts",
19
+ "import": "./dist/index.js"
20
+ }
21
+ },
22
+ "scripts": {
23
+ "build": "tsc -b --pretty false",
24
+ "typecheck": "tsc -b --pretty false",
25
+ "dev": "tsc -b --watch"
26
+ },
27
+ "dependencies": {
28
+ "@zaowu-labs/core": "workspace:*"
29
+ },
30
+ "keywords": [
31
+ "zaowu",
32
+ "teaching"
33
+ ],
34
+ "repository": {
35
+ "type": "git",
36
+ "url": "https://github.com/zaowu-labs/zaowu.git",
37
+ "directory": "packages/teach"
38
+ },
39
+ "homepage": "https://github.com/zaowu-labs/zaowu",
40
+ "bugs": "https://github.com/zaowu-labs/zaowu/issues"
41
+ }