moodle-cli 0.5.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/LICENSE +21 -0
- package/README.md +155 -0
- package/SKILL.md +167 -0
- package/dist/moodle.js +3474 -0
- package/package.json +52 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 bunizao
|
|
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
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
# moodle-cli
|
|
2
|
+
|
|
3
|
+
Terminal-first CLI for Moodle LMS that reuses an authenticated browser session. No Moodle API token required.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Reuses `MoodleSession` from `okta-auth`, your browser, or `MOODLE_SESSION`
|
|
8
|
+
- Uses Moodle AJAX APIs and falls back to authenticated page scraping when needed
|
|
9
|
+
- Lists courses, deadlines, alerts, activities, grades, and forum discussions
|
|
10
|
+
- Agent-friendly JSON/YAML output, field selection, and stable exit codes
|
|
11
|
+
|
|
12
|
+
## Install
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm i -g moodle-cli
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Run without installing:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npx moodle-cli --help
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Standalone binaries are attached to GitHub Releases for macOS arm64 and Linux x64.
|
|
25
|
+
|
|
26
|
+
### Existing PyPI Users
|
|
27
|
+
|
|
28
|
+
The TypeScript CLI keeps the same config file and environment variables as the Python package. Migrate with:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
uv tool uninstall moodle-cli
|
|
32
|
+
npm i -g moodle-cli
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
`~/.config/moodle-cli/config.yaml`, `MOODLE_BASE_URL`, and `MOODLE_SESSION` remain compatible.
|
|
36
|
+
|
|
37
|
+
## Authentication
|
|
38
|
+
|
|
39
|
+
Use one of:
|
|
40
|
+
|
|
41
|
+
- `okta-auth-cli` configured for your Moodle site
|
|
42
|
+
- an active Moodle browser session
|
|
43
|
+
- a `MOODLE_SESSION` environment variable
|
|
44
|
+
|
|
45
|
+
Optional Okta setup:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
npm i -g okta-auth-cli
|
|
49
|
+
okta config
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
On first run, if no `base_url` is configured, the CLI prompts for the Moodle root URL and saves it to `~/.config/moodle-cli/config.yaml`:
|
|
53
|
+
|
|
54
|
+
```yaml
|
|
55
|
+
base_url: https://school.example.edu
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Use a root URL only, not `/login/index.php` or `/my/`.
|
|
59
|
+
|
|
60
|
+
## Usage
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
moodle --help
|
|
64
|
+
moodle user
|
|
65
|
+
moodle alerts
|
|
66
|
+
moodle todo
|
|
67
|
+
moodle overview
|
|
68
|
+
moodle courses
|
|
69
|
+
moodle grades 34637
|
|
70
|
+
moodle activities 34637
|
|
71
|
+
moodle https://school.example.edu/course/view.php?id=34637
|
|
72
|
+
moodle https://school.example.edu/mod/forum/discuss.php?d=9001#p9101 --json
|
|
73
|
+
moodle skills
|
|
74
|
+
moodle skills generate
|
|
75
|
+
moodle skills add
|
|
76
|
+
moodle update
|
|
77
|
+
moodle update --check-only
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Supported Moodle URLs can be passed as the first argument. The CLI routes forum discussion, forum view, assignment, quiz, resource, link, page, folder, course, and grade report URLs to the shortest matching command.
|
|
81
|
+
|
|
82
|
+
## Agent Output Contract
|
|
83
|
+
|
|
84
|
+
JSON-capable commands support:
|
|
85
|
+
|
|
86
|
+
- `--json`: write JSON to stdout
|
|
87
|
+
- `--yaml`: write YAML to stdout
|
|
88
|
+
- `--table`: force human output
|
|
89
|
+
- `--fields a,b,c`: keep only listed top-level fields; arrays apply the filter per item
|
|
90
|
+
|
|
91
|
+
When stdout is not a TTY, the CLI defaults to JSON. `--table` overrides that.
|
|
92
|
+
|
|
93
|
+
Invalid `--fields` values fail as usage errors and list valid fields.
|
|
94
|
+
|
|
95
|
+
With JSON output enabled, errors are one parseable JSON line on stderr:
|
|
96
|
+
|
|
97
|
+
```json
|
|
98
|
+
{"error":true,"code":"auth_failed","message":"...","hint":"..."}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Exit codes:
|
|
102
|
+
|
|
103
|
+
| Code | Meaning |
|
|
104
|
+
| --- | --- |
|
|
105
|
+
| 0 | Success |
|
|
106
|
+
| 1 | Unexpected error |
|
|
107
|
+
| 2 | Authentication or configuration error |
|
|
108
|
+
| 3 | Usage error |
|
|
109
|
+
| 4 | Requested course, activity, forum, or discussion was not found |
|
|
110
|
+
|
|
111
|
+
## Updates
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
moodle update --check-only
|
|
115
|
+
moodle update --json
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
`moodle update` checks `https://registry.npmjs.org/moodle-cli/latest`. npm installs update with:
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
npm install -g moodle-cli@latest
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Standalone binaries print the latest GitHub Release URL instead of modifying themselves.
|
|
125
|
+
|
|
126
|
+
## Agent Skill
|
|
127
|
+
|
|
128
|
+
Install the bundled agent skill:
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
npx skills add https://github.com/bunizao/moodle-cli
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
The CLI alias delegates to the same command:
|
|
135
|
+
|
|
136
|
+
```bash
|
|
137
|
+
moodle skills add
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Regenerate `SKILL.md` from the command tree:
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
npm run build
|
|
144
|
+
npm run skill:generate
|
|
145
|
+
git diff --exit-code SKILL.md
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## Development
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
npm install
|
|
152
|
+
npm run check
|
|
153
|
+
npm test
|
|
154
|
+
npm run build
|
|
155
|
+
```
|
package/SKILL.md
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: moodle-cli
|
|
3
|
+
description: Inspect Moodle data from the terminal with the `moodle` CLI. Use when an agent needs courses, deadlines, grades, alerts, activities, or forum discussions. Prefer JSON output for agent workflows.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# moodle-cli
|
|
7
|
+
|
|
8
|
+
<!-- Generated by `moodle skills generate`. Edit `src/skill.template.md` for prose changes. -->
|
|
9
|
+
|
|
10
|
+
Use `moodle` for read-only Moodle access.
|
|
11
|
+
|
|
12
|
+
## Defaults
|
|
13
|
+
|
|
14
|
+
Use the narrowest command that answers the request.
|
|
15
|
+
|
|
16
|
+
Prefer JSON for agent work. `--json` is explicit, and piped stdout defaults to JSON automatically. Use `--fields` to keep only the top-level fields you need.
|
|
17
|
+
|
|
18
|
+
Omit `--json` only when a human explicitly wants the formatted terminal view. Use `--table` to force human output in a pipe.
|
|
19
|
+
|
|
20
|
+
Resolve course IDs with `moodle courses --json` before running course-specific commands when the user gives only a course name.
|
|
21
|
+
|
|
22
|
+
Avoid `moodle overview --json` unless the user explicitly asks for a combined snapshot across courses, deadlines, and alerts.
|
|
23
|
+
|
|
24
|
+
## Setup
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npm i -g moodle-cli
|
|
28
|
+
# or run without installing
|
|
29
|
+
npx moodle-cli --help
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Standalone binaries are published on GitHub Releases.
|
|
33
|
+
|
|
34
|
+
Existing PyPI users should migrate:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
uv tool uninstall moodle-cli
|
|
38
|
+
npm i -g moodle-cli
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Authenticate with an active Moodle browser session, `MOODLE_SESSION`, or `okta-auth-cli`.
|
|
42
|
+
|
|
43
|
+
Set `MOODLE_BASE_URL` or let the first run prompt for the Moodle root URL and save it to config.
|
|
44
|
+
|
|
45
|
+
## Forum Routing
|
|
46
|
+
|
|
47
|
+
For forum requests, prefer `moodle forum find` over manually chaining `forum forums`, `forum discussions`, and `forum discussion`.
|
|
48
|
+
|
|
49
|
+
If the user already gives a forum discussion URL, skip search and open it directly with `moodle forum discussion DISCUSSION_OR_URL --json`.
|
|
50
|
+
|
|
51
|
+
If the user gives a forum view URL or discussion URL and wants to browse nearby discussions, use `moodle forum discussions FORUM_OR_URL --json`.
|
|
52
|
+
|
|
53
|
+
Use scan budgets first when the site may be large:
|
|
54
|
+
|
|
55
|
+
- `--course` to narrow to one course
|
|
56
|
+
- `--limit-forums` to cap how many forums to scan
|
|
57
|
+
- `--limit-discussions` to cap how many discussions to scan per forum
|
|
58
|
+
|
|
59
|
+
Grouped forums are handled automatically. Do not assume an empty default forum page means the forum has no discussions.
|
|
60
|
+
|
|
61
|
+
Default forum agent flow:
|
|
62
|
+
|
|
63
|
+
1. Start with `moodle forum find QUERY --json`
|
|
64
|
+
2. Add `--unread-only` when the user wants new or unseen content
|
|
65
|
+
3. Add `--list --limit N` when one result is not enough and you need a shortlist
|
|
66
|
+
4. Add `--body` only when the snippet is insufficient and you need the full target post/discussion
|
|
67
|
+
|
|
68
|
+
Avoid `moodle forum search` unless you explicitly need a larger result set than `forum find --list`.
|
|
69
|
+
|
|
70
|
+
## Intent To Command
|
|
71
|
+
|
|
72
|
+
| User intent | Command |
|
|
73
|
+
| --- | --- |
|
|
74
|
+
| Show my profile or account info | moodle user --json |
|
|
75
|
+
| List my courses | moodle courses --json |
|
|
76
|
+
| Find nearest deadlines or upcoming actions | moodle todo --limit 5 --days 14 --json |
|
|
77
|
+
| List alerts or unread notifications | moodle alerts --limit 10 --json |
|
|
78
|
+
| Show a compact dashboard | moodle overview --todo-limit 5 --alerts-limit 5 --json |
|
|
79
|
+
| Show activities in a course | moodle activities COURSE_ID --json |
|
|
80
|
+
| Show course sections | moodle course COURSE_ID --json |
|
|
81
|
+
| Show grades for a course | moodle grades COURSE_ID --json |
|
|
82
|
+
| Find the best forum match | moodle forum find QUERY --json |
|
|
83
|
+
| Open a forum discussion URL or ID | moodle forum discussion DISCUSSION_OR_URL --json |
|
|
84
|
+
| Check whether the CLI has an update | moodle update --json |
|
|
85
|
+
| Install this agent skill | moodle skills add |
|
|
86
|
+
|
|
87
|
+
## Command Reference
|
|
88
|
+
|
|
89
|
+
| Command | Description | Arguments | Flags |
|
|
90
|
+
| --- | --- | --- | --- |
|
|
91
|
+
| moodle activities | List activities in a course. | <course> | --json<br>--yaml<br>--table<br>--fields (value required) |
|
|
92
|
+
| moodle alerts | List notifications and message counts. | | --json<br>--yaml<br>--table<br>--fields (value required)<br>--limit (default: 20; value required) |
|
|
93
|
+
| moodle assign | Show assignment details. | <assign> | --json<br>--yaml<br>--table<br>--fields (value required) |
|
|
94
|
+
| moodle course | Show course detail with sections. | <course> | --json<br>--yaml<br>--table<br>--fields (value required) |
|
|
95
|
+
| moodle courses | List enrolled courses. | | --json<br>--yaml<br>--table<br>--fields (value required) |
|
|
96
|
+
| moodle folder | Show folder details. | <folder> | --json<br>--yaml<br>--table<br>--fields (value required) |
|
|
97
|
+
| moodle forum | Forum utilities. | | |
|
|
98
|
+
| moodle forum check | Validate discussion rendering. | <forum> | --json<br>--yaml<br>--table<br>--fields (value required)<br>--limit (default: 20; value required) |
|
|
99
|
+
| 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 |
|
|
100
|
+
| 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) |
|
|
101
|
+
| 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) |
|
|
102
|
+
| 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) |
|
|
103
|
+
| 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) |
|
|
104
|
+
| moodle grades | Show grade details for a course. | <course> | --json<br>--yaml<br>--table<br>--fields (value required) |
|
|
105
|
+
| moodle link | Show link details. | <link> | --json<br>--yaml<br>--table<br>--fields (value required) |
|
|
106
|
+
| 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) |
|
|
107
|
+
| moodle page | Show page details. | <page> | --json<br>--yaml<br>--table<br>--fields (value required) |
|
|
108
|
+
| moodle quiz | Show quiz details. | <quiz> | --json<br>--yaml<br>--table<br>--fields (value required) |
|
|
109
|
+
| moodle resource | Show resource details. | <resource> | --json<br>--yaml<br>--table<br>--fields (value required) |
|
|
110
|
+
| moodle skills | Show skill metadata or delegate to the shared skills CLI. | | |
|
|
111
|
+
| moodle skills add | Install the published skill through npx skills add. | | |
|
|
112
|
+
| moodle skills generate | Regenerate SKILL.md from the CLI command tree. | | |
|
|
113
|
+
| 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) |
|
|
114
|
+
| moodle update | Check for updates and upgrade the installed CLI. | | --json<br>--yaml<br>--table<br>--fields (value required)<br>--check-only |
|
|
115
|
+
| moodle user | Show authenticated user info. | | --json<br>--yaml<br>--table<br>--fields (value required) |
|
|
116
|
+
|
|
117
|
+
## Agent Output
|
|
118
|
+
|
|
119
|
+
### Output Contract
|
|
120
|
+
|
|
121
|
+
- `--json` writes JSON to stdout.
|
|
122
|
+
- `--yaml` writes YAML to stdout when supported.
|
|
123
|
+
- `--table` forces human-readable table/tree output.
|
|
124
|
+
- When stdout is not a TTY, commands default to JSON unless `--table` is set.
|
|
125
|
+
- `--fields a,b,c` keeps only listed top-level fields. Arrays apply the field filter to each item.
|
|
126
|
+
- Invalid `--fields` values are usage errors and list valid fields.
|
|
127
|
+
- With JSON output enabled, errors are one JSON line on stderr: `{"error":true,"code":"auth_failed","message":"...","hint":"..."}`.
|
|
128
|
+
|
|
129
|
+
Exit codes:
|
|
130
|
+
|
|
131
|
+
| Code | Meaning |
|
|
132
|
+
| --- | --- |
|
|
133
|
+
| 0 | Success |
|
|
134
|
+
| 1 | Unexpected error |
|
|
135
|
+
| 2 | Authentication or configuration error |
|
|
136
|
+
| 3 | Usage error |
|
|
137
|
+
| 4 | Requested course, activity, forum, or discussion was not found |
|
|
138
|
+
|
|
139
|
+
## Operating Rules
|
|
140
|
+
|
|
141
|
+
Parse JSON locally and return a concise answer.
|
|
142
|
+
|
|
143
|
+
Do not paste full command output unless the user explicitly asks for raw JSON.
|
|
144
|
+
|
|
145
|
+
If the user asks for "recent", "next", or "nearest", sort by relevance and mention exact timestamps from `due_at` or `created_at`.
|
|
146
|
+
|
|
147
|
+
If a request is ambiguous between activities, courses, and grades, inspect courses first and then run the smallest follow-up command.
|
|
148
|
+
|
|
149
|
+
For forum work, do not enumerate forums or discussions first unless the user explicitly asks to browse. Search first, then expand only if needed.
|
|
150
|
+
|
|
151
|
+
For forum discussion output, prefer structured fields over heuristic text parsing when available:
|
|
152
|
+
|
|
153
|
+
- `image_urls` for original image links
|
|
154
|
+
- `links` for extracted hyperlinks
|
|
155
|
+
- `tables` for structured table content
|
|
156
|
+
- `group_id` and `group_name` for grouped forum context
|
|
157
|
+
|
|
158
|
+
## Failure Modes
|
|
159
|
+
|
|
160
|
+
- Authentication failed: sign in to Moodle in the browser, export `MOODLE_SESSION`, or configure `okta-auth-cli`.
|
|
161
|
+
- Invalid base URL: use the Moodle site root such as `https://school.example.edu`, not `/login/index.php` or `/my/`.
|
|
162
|
+
- Could not check for updates: retry with network access to the npm registry, then run `npm install -g moodle-cli@latest` or download the latest GitHub Release binary.
|
|
163
|
+
|
|
164
|
+
## Safety
|
|
165
|
+
|
|
166
|
+
- Treat `MOODLE_SESSION` as a secret and never paste it into chat or logs.
|
|
167
|
+
- The CLI is read-only and does not create or modify Moodle content.
|