moodle-cli 0.5.5 → 0.6.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "moodle-cli",
3
- "version": "0.5.5",
3
+ "version": "0.6.0",
4
4
  "description": "Terminal-first CLI for Moodle LMS",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -11,17 +11,19 @@
11
11
  "dist",
12
12
  "README.md",
13
13
  "SKILL.md",
14
+ "references",
15
+ "agents",
14
16
  "LICENSE"
15
17
  ],
16
18
  "scripts": {
17
- "build": "tsup && rm -f dist/.gitignore",
19
+ "build": "tsc --noEmit && tsup && rm -f dist/.gitignore",
18
20
  "check": "tsc --noEmit",
19
- "pack:check": "npm pack --dry-run --json | node -e \"let data = ''; process.stdin.on('data', chunk => data += chunk); process.stdin.on('end', () => { const files = JSON.parse(data)[0]?.files?.map(file => file.path) ?? []; if (!files.includes('dist/moodle.js')) throw new Error('npm package is missing dist/moodle.js'); });\"",
21
+ "pack:check": "npm pack --dry-run --json | node -e \"let data = ''; process.stdin.on('data', chunk => data += chunk); process.stdin.on('end', () => { const files = JSON.parse(data)[0]?.files?.map(file => file.path) ?? []; for (const required of ['dist/moodle.js', 'SKILL.md', 'references/command-reference.md', 'agents/openai.yaml']) if (!files.includes(required)) throw new Error('npm package is missing ' + required); });\"",
20
22
  "pack:smoke": "tmp=\"$(mktemp -d)\" && npm pack --pack-destination \"$tmp\" >/dev/null && npm install --prefix \"$tmp/install\" \"$tmp\"/moodle-cli-*.tgz >/dev/null && test \"$(\"$tmp/install/node_modules/.bin/moodle\" --version)\" = \"$(node -p \"JSON.parse(require('node:fs').readFileSync('package.json', 'utf8')).version\")\"",
21
23
  "test": "vitest run",
22
24
  "test:watch": "vitest",
23
25
  "skill:generate": "node dist/moodle.js skills generate",
24
- "prepublishOnly": "npm run check && npm run test && npm run build"
26
+ "prepublishOnly": "npm run test && npm run build"
25
27
  },
26
28
  "dependencies": {
27
29
  "commander": "^14.0.0",
@@ -35,7 +37,7 @@
35
37
  "devDependencies": {
36
38
  "@types/node": "^24.0.10",
37
39
  "tsup": "^8.5.0",
38
- "typescript": "^5.8.3",
40
+ "typescript": "^7.0.2",
39
41
  "vitest": "^3.2.4"
40
42
  },
41
43
  "engines": {
@@ -0,0 +1,38 @@
1
+ # Command Reference
2
+
3
+ Read this file for exact arguments, flags, and defaults after selecting a branch from `SKILL.md`.
4
+
5
+ | Command | Description | Arguments | Flags |
6
+ | --- | --- | --- | --- |
7
+ | moodle activities | List activities in a course. | <course> | --json<br>--yaml<br>--table<br>--fields (value required) |
8
+ | moodle alerts | List notifications and message counts. | | --json<br>--yaml<br>--table<br>--fields (value required)<br>--limit (default: 20; value required) |
9
+ | moodle assign | Show assignment details. | <assign> | --json<br>--yaml<br>--table<br>--fields (value required) |
10
+ | moodle auth | Session and keepalive utilities. | | |
11
+ | moodle auth keepalive | Renew the Moodle session once; used by the background keepalive agent. | | --no-renew<br>--json<br>--yaml<br>--table<br>--fields (value required) |
12
+ | moodle auth keepalive install | Install a macOS launch agent that renews the session periodically. | | --interval (value required)<br>--json<br>--yaml<br>--table<br>--fields (value required) |
13
+ | moodle auth keepalive status | Show whether the keepalive launch agent is installed. | | --json<br>--yaml<br>--table<br>--fields (value required) |
14
+ | moodle auth keepalive uninstall | Remove the keepalive launch agent. | | --json<br>--yaml<br>--table<br>--fields (value required) |
15
+ | moodle auth login | Force a fresh login and refresh the session cache. | | --json<br>--yaml<br>--table<br>--fields (value required) |
16
+ | moodle auth status | Show cached session freshness and keepalive state. | | --json<br>--yaml<br>--table<br>--fields (value required) |
17
+ | moodle course | Show course detail with sections. | <course> | --json<br>--yaml<br>--table<br>--fields (value required) |
18
+ | moodle courses | List enrolled courses. | | --json<br>--yaml<br>--table<br>--fields (value required) |
19
+ | moodle folder | Show folder details. | <folder> | --json<br>--yaml<br>--table<br>--fields (value required) |
20
+ | moodle forum | Forum utilities. | | |
21
+ | moodle forum check | Validate discussion rendering. | <forum> | --json<br>--yaml<br>--table<br>--fields (value required)<br>--limit (default: 20; value required) |
22
+ | moodle forum discussion | Show posts in a forum discussion. | <discussion> | --json<br>--yaml<br>--table<br>--fields (value required)<br>--post (value required)<br>--body |
23
+ | moodle forum discussions | List discussions from a forum. | <forum> | --json<br>--yaml<br>--table<br>--fields (value required)<br>--limit (default: 50; value required)<br>--query (value required) |
24
+ | moodle forum find | Find the best forum match. | <query> | --list<br>--body<br>--json<br>--yaml<br>--table<br>--fields (value required)<br>--course (value required)<br>--forum (value required)<br>--titles-only<br>--unread-only<br>--recent<br>--limit-forums (value required)<br>--limit-discussions (value required)<br>--limit (default: 5; value required) |
25
+ | moodle forum forums | List forum activities. | [query] | --json<br>--yaml<br>--table<br>--fields (value required)<br>--course (value required)<br>--limit (default: 50; value required) |
26
+ | moodle forum search | Search forum discussion titles and post text. | <query> | --json<br>--yaml<br>--table<br>--fields (value required)<br>--course (value required)<br>--forum (value required)<br>--titles-only<br>--unread-only<br>--recent<br>--limit-forums (value required)<br>--limit-discussions (value required)<br>--limit (default: 20; value required) |
27
+ | moodle grades | Show grade details for a course. | <course> | --json<br>--yaml<br>--table<br>--fields (value required) |
28
+ | moodle link | Show link details. | <link> | --json<br>--yaml<br>--table<br>--fields (value required) |
29
+ | moodle overview | Show a compact multi-source overview. | | --json<br>--yaml<br>--table<br>--fields (value required)<br>--todo-limit (default: 5; value required)<br>--todo-days (value required)<br>--alerts-limit (default: 5; value required) |
30
+ | moodle page | Show page details. | <page> | --json<br>--yaml<br>--table<br>--fields (value required) |
31
+ | moodle quiz | Show quiz details. | <quiz> | --json<br>--yaml<br>--table<br>--fields (value required) |
32
+ | moodle resource | Show resource details. | <resource> | --json<br>--yaml<br>--table<br>--fields (value required) |
33
+ | moodle skills | Show skill metadata or delegate to the shared skills CLI. | | |
34
+ | moodle skills add | Install the published skill through npx skills add. | | |
35
+ | moodle skills generate | Regenerate the agent skill bundle from the CLI command tree. | | |
36
+ | moodle todo | List upcoming actionable timeline items. | | --json<br>--yaml<br>--table<br>--fields (value required)<br>--limit (default: 20; value required)<br>--days (value required) |
37
+ | moodle update | Check for updates and upgrade the installed CLI. | | --json<br>--yaml<br>--table<br>--fields (value required)<br>--check-only |
38
+ | moodle user | Show authenticated user info. | | --json<br>--yaml<br>--table<br>--fields (value required) |
@@ -0,0 +1,42 @@
1
+ # Coursework and Grades
2
+
3
+ Read this file for grades or detail about assignments, quizzes, resources, links, pages, and folders.
4
+
5
+ ## Grades
6
+
7
+ Use a course ID or unique course name:
8
+
9
+ ```bash
10
+ moodle grades COURSE --json
11
+ ```
12
+
13
+ Report the course total and requested grade items. Preserve displayed values and percentages; Moodle gradebooks may expose text such as ranges, letters, or incomplete totals.
14
+
15
+ ## Activity Detail
16
+
17
+ Each command accepts a numeric module ID or its full Moodle URL:
18
+
19
+ | Activity | Command |
20
+ | --- | --- |
21
+ | Assignment | `moodle assign ASSIGNMENT --json` |
22
+ | Quiz | `moodle quiz QUIZ --json` |
23
+ | File/resource | `moodle resource RESOURCE --json` |
24
+ | External link | `moodle link LINK --json` |
25
+ | Moodle page | `moodle page PAGE --json` |
26
+ | Folder | `moodle folder FOLDER --json` |
27
+
28
+ When the user supplies a supported Moodle URL without naming a command, route it directly:
29
+
30
+ ```bash
31
+ moodle 'MOODLE_URL' --json
32
+ ```
33
+
34
+ The CLI recognizes course, grade report, forum, assignment, quiz, resource, link, page, and folder URLs. For another activity URL, it may fall back to the containing course.
35
+
36
+ ## Agent Steps
37
+
38
+ 1. Use the activity-specific command when the activity type is known.
39
+ 2. Use direct URL routing when the user already supplied a URL and only wants its content.
40
+ 3. Return structured links and files from the result instead of scraping prose from the formatted table.
41
+
42
+ The branch is complete when the answer identifies the course or module and quotes the grade or activity state returned by Moodle.
@@ -0,0 +1,25 @@
1
+ # Deadlines and Alerts
2
+
3
+ Read this file for upcoming work, due dates, notifications, unread counts, or a combined snapshot.
4
+
5
+ ## Choose the Command
6
+
7
+ | Need | Command |
8
+ | --- | --- |
9
+ | Nearest actionable items | `moodle todo --limit 5 --days 14 --json` |
10
+ | Notifications and message counts | `moodle alerts --limit 10 --json` |
11
+ | User, courses, todo, and alerts together | `moodle overview --todo-limit 5 --alerts-limit 5 --json` |
12
+
13
+ Use `todo` for “next,” “due,” “deadline,” and “upcoming.” Add `--days N` for a time window and `--limit N` for result size.
14
+
15
+ Use `alerts` for notifications, unread items, starred messages, and conversation counts.
16
+
17
+ Use `overview` only when the user explicitly wants multiple categories in one snapshot. A narrow request should stay on `todo` or `alerts`.
18
+
19
+ ## Agent Steps
20
+
21
+ 1. Run the narrow command.
22
+ 2. Sort or filter the returned data only when the command does not already express the request.
23
+ 3. Report exact timestamps and course/activity names; preserve the Moodle URL when it helps the user act.
24
+
25
+ The branch is complete when every reported deadline or alert comes from the command result and the requested time window is explicit.
@@ -0,0 +1,58 @@
1
+ # Forums
2
+
3
+ Read this file for forum discovery, title or body search, discussion reading, grouped forums, unread posts, or rendering checks.
4
+
5
+ ## Default Search
6
+
7
+ Start with the narrowest high-level command:
8
+
9
+ ```bash
10
+ moodle forum find QUERY --json
11
+ ```
12
+
13
+ Refine it with:
14
+
15
+ - `--course COURSE` to restrict the course.
16
+ - `--forum FORUM_OR_URL` to restrict the forum.
17
+ - `--unread-only` for unseen content.
18
+ - `--titles-only` to avoid fetching post bodies.
19
+ - `--list --limit N` for a shortlist.
20
+ - `--body` only when the winning snippet is insufficient.
21
+ - `--limit-forums N` and `--limit-discussions N` to bound large-site scans.
22
+
23
+ Use `moodle forum search QUERY --json` when a larger result set is the goal. `forum find` is the default for one best answer.
24
+
25
+ When one request combines search with the full matching post, use one command:
26
+
27
+ ```bash
28
+ moodle forum find QUERY --course COURSE --body --json
29
+ ```
30
+
31
+ Reserve `forum discussion` for an existing discussion ID or URL, or for selecting a known post ID.
32
+
33
+ ## Browse or Open Directly
34
+
35
+ | Need | Command |
36
+ | --- | --- |
37
+ | List forum activities | `moodle forum forums [QUERY] --json` |
38
+ | List discussions in one forum | `moodle forum discussions FORUM_OR_URL --json` |
39
+ | Read a discussion | `moodle forum discussion DISCUSSION_OR_URL --json` |
40
+ | Read one post | `moodle forum discussion DISCUSSION_OR_URL --post POST_ID --json` |
41
+ | Include full bodies in terminal format | `moodle forum discussion DISCUSSION_OR_URL --body --table` |
42
+ | Validate discussion rendering | `moodle forum check FORUM_OR_URL --limit 20 --json` |
43
+
44
+ Skip discovery when the user already supplied a discussion URL. Use `forum discussions` when they supplied a forum view URL and want nearby threads.
45
+
46
+ Grouped forums are resolved automatically. An empty default group page does not prove the forum has no discussions.
47
+
48
+ ## Structured Forum Content
49
+
50
+ Prefer these fields over text heuristics:
51
+
52
+ - `image_urls` for original images
53
+ - `links` for extracted hyperlinks
54
+ - `tables` for table rows and headers
55
+ - `group_id` and `group_name` for group context
56
+ - `unread` and `time_created` for unread/recent requests
57
+
58
+ The branch is complete when the selected discussion or post matches the query and the answer retains the source URL.
@@ -0,0 +1,43 @@
1
+ # Maintenance
2
+
3
+ Read this file for update checks, upgrades, agent-skill installation, or repository skill regeneration.
4
+
5
+ ## Update the CLI
6
+
7
+ Check without changing the installation:
8
+
9
+ ```bash
10
+ moodle update --check-only --json
11
+ ```
12
+
13
+ Run `moodle update --table` when the user explicitly wants the installation upgraded. npm installations use `npm install -g moodle-cli@latest`; standalone binaries return the latest GitHub Release URL.
14
+
15
+ If the registry check fails, verify network access and retry before proposing an upgrade command.
16
+
17
+ ## Install the Agent Skill
18
+
19
+ Show skill metadata with:
20
+
21
+ ```bash
22
+ moodle skills
23
+ ```
24
+
25
+ Install from the published repository with:
26
+
27
+ ```bash
28
+ moodle skills add
29
+ ```
30
+
31
+ Extra arguments are passed to the shared `skills` CLI, for example `moodle skills add --agent codex`.
32
+
33
+ ## Regenerate the Skill Bundle
34
+
35
+ Inside the `moodle-cli` source repository:
36
+
37
+ ```bash
38
+ npm run build
39
+ npm run skill:generate
40
+ git diff -- SKILL.md references agents/openai.yaml
41
+ ```
42
+
43
+ Regeneration is complete when the root skill, branch references, command reference, output contract, and agent metadata are all current.
@@ -0,0 +1,30 @@
1
+ # Output and Errors
2
+
3
+ Read this file when choosing an output mode, filtering fields, consuming errors, or interpreting exit codes.
4
+
5
+ ### Output Contract
6
+
7
+ - `--json` writes JSON to stdout.
8
+ - `--yaml` writes YAML to stdout when supported.
9
+ - `--table` forces human-readable table/tree output.
10
+ - When stdout is not a TTY, commands default to JSON unless `--table` is set.
11
+ - `--fields a,b,c` keeps only listed top-level fields. Arrays apply the field filter to each item.
12
+ - Invalid `--fields` values are usage errors and list valid fields.
13
+ - With JSON output enabled, errors are one JSON line on stderr: `{"error":true,"code":"auth_failed","message":"...","hint":"..."}`.
14
+
15
+ Exit codes:
16
+
17
+ | Code | Meaning |
18
+ | --- | --- |
19
+ | 0 | Success |
20
+ | 1 | Unexpected error |
21
+ | 2 | Authentication or configuration error |
22
+ | 3 | Usage error |
23
+ | 4 | Requested course, activity, forum, or discussion was not found |
24
+
25
+ ## Agent Handling
26
+
27
+ - Parse structured stdout locally and return only the facts the user requested.
28
+ - Treat stderr as the error channel; JSON mode emits one parseable error object there.
29
+ - Use the exit code to distinguish authentication/configuration, usage, not-found, and unexpected failures.
30
+ - Retry only after acting on the error hint. A repeated authentication failure needs a fresh login or session source, not another identical command.
@@ -0,0 +1,27 @@
1
+ # Profile and Courses
2
+
3
+ Read this file for identity, enrolled-course discovery, course sections, or course activity lists.
4
+
5
+ ## Choose the Command
6
+
7
+ | Need | Command |
8
+ | --- | --- |
9
+ | Authenticated user and site | `moodle user --json` |
10
+ | Enrolled courses | `moodle courses --json` |
11
+ | Sections and nested activities | `moodle course COURSE --json` |
12
+ | Flat activity list | `moodle activities COURSE --json` |
13
+
14
+ `COURSE` accepts a numeric course ID or a unique course-name match. When a name could match several courses, run `moodle courses --json`, identify the intended course, and continue with its ID.
15
+
16
+ ## Agent Steps
17
+
18
+ 1. Use `user` only for account or site identity.
19
+ 2. Use `courses` for discovery and ID resolution.
20
+ 3. Use `course` when section placement matters; use `activities` when the user wants a flat inventory.
21
+ 4. Use `--fields` only for fields present in the returned objects, for example:
22
+
23
+ ```bash
24
+ moodle courses --json --fields id,shortname,fullname
25
+ ```
26
+
27
+ The branch is complete when the requested course or activity facts are tied to an unambiguous course ID.
@@ -0,0 +1,73 @@
1
+ # Setup and Authentication
2
+
3
+ Read this file for installation, first-run configuration, browser-session reuse, or authentication recovery.
4
+
5
+ ## Install
6
+
7
+ Prefer the published npm package:
8
+
9
+ ```bash
10
+ npm install -g moodle-cli
11
+ moodle --version
12
+ ```
13
+
14
+ Use `npx moodle-cli --help` for a one-off run. Existing PyPI users should migrate with:
15
+
16
+ ```bash
17
+ uv tool uninstall moodle-cli
18
+ npm install -g moodle-cli
19
+ ```
20
+
21
+ Standalone binaries are available from GitHub Releases for supported platforms.
22
+
23
+ ## Configure the Moodle Site
24
+
25
+ Set `MOODLE_BASE_URL` to the Moodle site root, such as `https://school.example.edu`. A URL ending in `/login/index.php`, `/my/`, or another page is invalid.
26
+
27
+ For an interactive first run, allow the CLI to prompt for the root URL and save it under `~/.config/moodle-cli/config.yaml`.
28
+
29
+ ## Authenticate
30
+
31
+ The CLI tries these session sources:
32
+
33
+ 1. `MOODLE_SESSION`
34
+ 2. A fresh local session cache
35
+ 3. Supported browser cookies
36
+ 4. `okta-auth-cli`
37
+
38
+ For automatic Okta login:
39
+
40
+ ```bash
41
+ uv tool install okta-auth-cli
42
+ okta config
43
+ ```
44
+
45
+ Validate setup with:
46
+
47
+ ```bash
48
+ moodle user --json
49
+ ```
50
+
51
+ Setup is complete when this returns the authenticated Moodle user.
52
+
53
+ ## Keep the Session Alive
54
+
55
+ Moodle expires idle sessions server-side (often a few hours). To avoid re-running SSO logins:
56
+
57
+ ```bash
58
+ moodle auth status --json # cache freshness + server session state
59
+ moodle auth keepalive --json # renew once (re-login from browser/okta cookies if expired)
60
+ moodle auth keepalive install # macOS launch agent, renews every 30 min
61
+ moodle auth keepalive install --interval 15
62
+ moodle auth keepalive uninstall
63
+ moodle auth login --json # force a fresh login and refresh the cache
64
+ ```
65
+
66
+ On Linux, schedule `moodle auth keepalive --json` with cron instead of `install`.
67
+
68
+ ## Recover Failures
69
+
70
+ - **No usable MoodleSession**: sign in to Moodle in a supported browser and retry; otherwise configure `okta-auth-cli` or provide `MOODLE_SESSION` through the environment.
71
+ - **Configured site is wrong**: correct `MOODLE_BASE_URL` or the saved `base_url`, then rerun `moodle user --json`.
72
+ - **Cached session expired**: run `moodle auth login`, or rerun with `--no-cache` once so the CLI reacquires a session.
73
+ - **Non-interactive config error**: set `MOODLE_BASE_URL`; a pipe cannot answer the first-run prompt.