moodle-cli 0.6.0 → 0.7.0-alpha.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/ONBOARDING.md ADDED
@@ -0,0 +1,54 @@
1
+ ---
2
+ name: moodle-cli-onboarding
3
+ description: Help a student set up moodle-cli through a short conversation.
4
+ ---
5
+
6
+ # moodle-cli onboarding
7
+
8
+ You are helping a student connect their university Moodle account to `moodle-cli`. Take ownership of the setup. Keep commands and configuration details out of the conversation unless the student asks or you need their help with an error.
9
+
10
+ ## Start the conversation
11
+
12
+ Use the student's language and begin with one question:
13
+
14
+ > What is your university's Moodle URL? You can paste any Moodle page you use, such as the dashboard, a course, or the login page.
15
+
16
+ Wait for the answer before doing setup work. Do not ask the student to find the site origin, remove part of the URL, choose a runtime, or edit a configuration file.
17
+
18
+ ## Handle the setup
19
+
20
+ Once the student shares a URL, complete the setup on their computer:
21
+
22
+ - Check for Node.js 22+ and Bun. Install `moodle-cli` with the runtime available on the computer. Use `bunx --bun moodle-cli` as the command prefix when Bun is the only runtime.
23
+ - Follow redirects and resolve the URL to the final Moodle origin in the form `https://host`. Remove the path, query, and fragment. Confirm that the origin serves Moodle before saving it.
24
+ - Read `~/.config/moodle-cli/config.yaml` if it exists. Set `base_url` to the verified origin and preserve the other settings.
25
+ - Tell the student that Moodle may open in their browser and that you will wait while they complete their university sign-in. Run `moodle auth login`. If a browser opens, let the student finish SSO there, then continue when the command returns.
26
+ - Verify the account with `moodle user --json` and `moodle overview --json`. Diagnose configuration or authentication failures and retry before reporting success. If browser sign-in times out, run `moodle auth login` again after the student is ready.
27
+ - Set up session renewal after verification. On macOS, run `moodle auth keepalive install` and confirm it with `moodle auth keepalive status --json`. On Linux, schedule `moodle auth keepalive --json` every 30 minutes with cron. On other systems, use the operating system scheduler for the same command or explain how to renew with `moodle auth keepalive`.
28
+ - Install the bundled agent skill with `moodle skills add`. In a Bun-only environment, use `bunx --bun skills add https://github.com/bunizao/moodle-cli`.
29
+
30
+ Do not ask the student to copy a Moodle cookie, `sesskey`, browser database, or API token into the conversation. Do not print credentials. Keep the Moodle session on the student's computer.
31
+
32
+ ## Offer remote access
33
+
34
+ After local verification succeeds, ask:
35
+
36
+ > Do you have a Cloudflare account? I can use it to deploy a private remote MCP server, which lets supported web AI clients connect to your Moodle.
37
+
38
+ If the student declines or has no account, finish the onboarding with local access. Mention that they can add remote access later.
39
+
40
+ If the student wants remote access, run `moodle mcp deploy`. Let them complete Cloudflare authorization in the browser when Wrangler requests it. The deployment command manages Worker creation, encrypted Moodle session upload, local renewal, and supported client configuration.
41
+
42
+ Verify the deployment with `moodle mcp status --json`. Continue troubleshooting until the command reports that the Worker and Moodle session are ready. Ask which web AI client the student wants to use, then guide them through that client's current custom MCP connection flow. Put access credentials into the client's connection settings, not the chat.
43
+
44
+ ## Finish with something useful
45
+
46
+ After both verification commands succeed, run `moodle todo --days 14 --json`. Summarize the student's upcoming work in the language they used.
47
+
48
+ End with three requests they can try next, adapted to the Moodle data you found:
49
+
50
+ - “Plan my Moodle work for this week.”
51
+ - “Download the slides from this Moodle link.”
52
+ - “Find forum posts about the next assessment.”
53
+
54
+ If the student has no upcoming items, say so and use their enrolled units to suggest relevant requests. Report the verified Moodle site and account, but omit session values and internal credentials.
package/README.md CHANGED
@@ -1,172 +1,214 @@
1
1
  # moodle-cli
2
2
 
3
- Terminal-first CLI for Moodle LMS that reuses an authenticated browser session. No Moodle API token required.
3
+ **Give your AI agent access to Moodle.**
4
4
 
5
- ## Features
5
+ Let it keep up with deadlines and grades, fetch course files, and search forum discussions. `moodle-cli` finds your active browser session and keeps it alive in the background, so Moodle's login wall stays out of your way.
6
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
7
+ [![npm version](https://img.shields.io/npm/v/moodle-cli?logo=npm)](https://www.npmjs.com/package/moodle-cli)
8
+ [![CI](https://github.com/bunizao/moodle-cli/actions/workflows/ci.yml/badge.svg)](https://github.com/bunizao/moodle-cli/actions/workflows/ci.yml)
9
+ [![Node.js 22+](https://img.shields.io/badge/Node.js-22%2B-339933?logo=nodedotjs&logoColor=white)](https://nodejs.org/)
10
+ [![Bun](https://img.shields.io/badge/Bun-supported-fbf0df?logo=bun&logoColor=black)](https://bun.sh/)
11
+ [![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
11
12
 
12
- ## Install
13
+ ## Quick links
13
14
 
14
- ```bash
15
- npm i -g moodle-cli
15
+ - [Set up with your agent](#start-with-your-agent)
16
+ - [Install and sign in manually](#install-and-sign-in-manually)
17
+ - [Study Boooooooooost](#study-boooooooooost)
18
+ - [Connect web AI through a private MCP server](#remote-mcp-for-web-ai)
19
+ - [Developer and agent reference](#for-developers-and-agents)
20
+
21
+ ## For users
22
+
23
+ ### Start with your agent
24
+
25
+ Paste this into Codex, Claude Code, OpenClaw, Hermes Agent, or another agent that can use your terminal:
26
+
27
+ ```text
28
+ Can you use https://github.com/bunizao/moodle-cli/raw/main/ONBOARDING.md to help me set up moodle-cli?
16
29
  ```
17
30
 
18
- Run without installing:
31
+ Your agent asks for your Moodle URL and opens your university's sign-in page when needed. Finish SSO in the browser while the agent waits; it verifies your account and sets up session renewal before reading Moodle. The same onboarding can deploy a private remote MCP server through your Cloudflare account.
32
+
33
+ ### Install and sign in manually
34
+
35
+ Use Node.js 22+ or Bun:
19
36
 
20
37
  ```bash
21
- npx moodle-cli --help
38
+ # npm
39
+ npm install -g moodle-cli
40
+
41
+ # Bun
42
+ bun add --global moodle-cli
43
+
44
+ moodle --version
22
45
  ```
23
46
 
24
- Standalone binaries are attached to GitHub Releases for macOS arm64 and Linux x64.
47
+ Run without a global install:
25
48
 
26
- ### Existing PyPI Users
49
+ ```bash
50
+ npx moodle-cli --help
51
+ bunx --bun moodle-cli --help
52
+ ```
27
53
 
28
- The TypeScript CLI keeps the same config file and environment variables as the Python package. Migrate with:
54
+ Sign in and open your dashboard:
29
55
 
30
56
  ```bash
31
- uv tool uninstall moodle-cli
32
- npm i -g moodle-cli
57
+ moodle auth login
58
+ moodle overview
33
59
  ```
34
60
 
35
- `~/.config/moodle-cli/config.yaml`, `MOODLE_BASE_URL`, and `MOODLE_SESSION` remain compatible.
61
+ On first use, enter your Moodle site origin, such as `https://moodle.example.edu`. `moodle-cli` validates it and saves it to `~/.config/moodle-cli/config.yaml`. If the CLI cannot find an active session, it opens your university's sign-in page and waits for you to finish.
62
+
63
+ Keep the session active on macOS with `moodle auth keepalive install`. On Linux, schedule `moodle auth keepalive --json` every 30 minutes with cron.
36
64
 
37
- ## Authentication
65
+ GitHub Releases also provide standalone binaries for macOS arm64 and Linux x64.
38
66
 
39
- Use one of:
67
+ ### Study Boooooooooost
40
68
 
41
- - `okta-auth-cli` configured for your Moodle site
42
- - an active Moodle browser session
43
- - a `MOODLE_SESSION` environment variable
69
+ Ask your agent in plain language or run the matching command:
70
+
71
+ | Student request | CLI command |
72
+ | --- | --- |
73
+ | “Give me a quick Moodle dashboard.” | `moodle overview` |
74
+ | “What is due in the next 14 days?” | `moodle todo --days 14` |
75
+ | “Show my grades and feedback for FIT1045.” | `moodle grades FIT1045` |
76
+ | “Find forum posts about the exam in FIT1045.” | `moodle forums search "exam" --course FIT1045` |
77
+ | “Download the slides from this Moodle link.” | `moodle download '<Moodle URL>' --dest './slides.pdf'` |
44
78
 
45
- Optional Okta setup:
79
+ Unit arguments accept a Moodle course ID or a unique course name.
80
+
81
+ #### Paste Moodle links directly
82
+
83
+ The CLI recognizes course, forum, assignment, quiz, resource, page, folder, and grade-report URLs:
46
84
 
47
85
  ```bash
48
- npm i -g okta-auth-cli
49
- okta config
86
+ moodle 'https://moodle.example.edu/course/view.php?id=34637'
87
+ moodle 'https://moodle.example.edu/mod/forum/discuss.php?d=9001#p9101'
88
+ moodle download 'https://moodle.example.edu/mod/resource/view.php?id=91234' --dest './Week 03/slides.pdf'
50
89
  ```
51
90
 
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`:
91
+ You can paste the same links into your agent and ask it to inspect the page, find related material, or download the file.
53
92
 
54
- ```yaml
55
- base_url: https://school.example.edu
56
- ```
93
+ #### Download course files
57
94
 
58
- Use a root URL only, not `/login/index.php` or `/my/`.
95
+ `moodle download` accepts an activity ID or an authenticated Moodle URL. `--dest` sets the exact local path, and `--force` replaces an existing file after the download completes. Folder activities expose `file_entries` so you can choose which files to save.
59
96
 
60
- ### Session Keepalive
97
+ ### Remote MCP for web AI
61
98
 
62
- Moodle expires idle sessions server-side, which normally forces a fresh SSO login. The CLI can renew the session in the background instead:
99
+ A private remote MCP server lets a supported web AI client use Moodle when it cannot run the local CLI. You need a Cloudflare account.
63
100
 
64
101
  ```bash
65
- moodle auth status # cache freshness + server session state
66
- moodle auth keepalive # renew once; re-login from browser/okta cookies if expired
67
- moodle auth keepalive install # macOS launch agent, renews every 30 min
68
- moodle auth login # force a fresh login
102
+ moodle mcp deploy
103
+ moodle mcp status
69
104
  ```
70
105
 
71
- On Linux, add a cron entry: `*/30 * * * * moodle auth keepalive --json`.
106
+ `moodle mcp deploy` validates Moodle access, deploys a Cloudflare Worker, uploads an encrypted Moodle session, verifies readiness, and installs session renewal. The guided [`ONBOARDING.md`](ONBOARDING.md) asks whether you want this after local setup and helps connect your web AI client.
72
107
 
73
- ## Usage
108
+ ### Update
74
109
 
75
110
  ```bash
76
- moodle --help
77
- moodle user
78
- moodle alerts
79
- moodle todo
80
- moodle overview
81
- moodle courses
82
- moodle grades 34637
83
- moodle activities 34637
84
- moodle https://school.example.edu/course/view.php?id=34637
85
- moodle https://school.example.edu/mod/forum/discuss.php?d=9001#p9101 --json
86
- moodle skills
87
- moodle skills generate
88
- moodle skills add
89
- moodle update
90
- moodle update --check-only
111
+ npm install -g moodle-cli@latest
112
+ bun add --global moodle-cli@latest
91
113
  ```
92
114
 
93
- 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.
115
+ Standalone binaries print the latest GitHub Release URL instead of modifying themselves.
94
116
 
95
- ## Agent Output Contract
117
+ ## For developers and agents
96
118
 
97
- JSON-capable commands support:
119
+ ### Command and output contract
98
120
 
99
- - `--json`: write JSON to stdout
100
- - `--yaml`: write YAML to stdout
101
- - `--table`: force human output
102
- - `--fields a,b,c`: keep only listed top-level fields; arrays apply the filter per item
121
+ Inspect the full machine-readable command tree:
103
122
 
104
- When stdout is not a TTY, the CLI defaults to JSON. `--table` overrides that.
123
+ ```bash
124
+ moodle commands --json
125
+ ```
105
126
 
106
- Invalid `--fields` values fail as usage errors and list valid fields.
127
+ Commands support:
107
128
 
108
- With JSON output enabled, errors are one parseable JSON line on stderr:
129
+ - `--json` or `--yaml` for structured output
130
+ - `--table` for human-readable output
131
+ - `--fields a,b,c` to select fields
132
+ - `-o, --output FILE` to write command output or a download receipt
133
+
134
+ The CLI prints tables in an interactive terminal and JSON when stdout goes to a pipe or file. Structured errors use one JSON object on stderr:
109
135
 
110
136
  ```json
111
- {"error":true,"code":"auth_failed","message":"...","hint":"..."}
137
+ {"ok":false,"error":{"code":"auth","message":"...","hint":"..."},"exit_code":3}
112
138
  ```
113
139
 
114
- Exit codes:
115
-
116
140
  | Code | Meaning |
117
141
  | --- | --- |
118
142
  | 0 | Success |
119
- | 1 | Unexpected error |
120
- | 2 | Authentication or configuration error |
121
- | 3 | Usage error |
122
- | 4 | Requested course, activity, forum, or discussion was not found |
143
+ | 1 | Network, configuration, or unexpected error |
144
+ | 2 | Usage error |
145
+ | 3 | Authentication error |
146
+ | 4 | Course, activity, forum, or discussion not found |
147
+ | 5 | Moodle rejected the request |
123
148
 
124
- ## Updates
149
+ ### Agent skill
125
150
 
126
- ```bash
127
- moodle update --check-only
128
- moodle update --json
129
- ```
130
-
131
- `moodle update` checks `https://registry.npmjs.org/moodle-cli/latest`. npm installs update with:
151
+ Install the generated skill bundle:
132
152
 
133
153
  ```bash
134
- npm install -g moodle-cli@latest
135
- ```
154
+ moodle skills add
136
155
 
137
- Standalone binaries print the latest GitHub Release URL instead of modifying themselves.
156
+ # Direct alternatives
157
+ npx skills add https://github.com/bunizao/moodle-cli
158
+ bunx --bun skills add https://github.com/bunizao/moodle-cli
159
+ ```
138
160
 
139
- ## Agent Skill
161
+ [`SKILL.md`](SKILL.md) routes agents to focused setup, coursework, forum, download, and maintenance guidance under [`references/`](references/).
140
162
 
141
- Install the bundled agent skill:
163
+ ### MCP lifecycle and protocol
142
164
 
143
165
  ```bash
144
- npx skills add https://github.com/bunizao/moodle-cli
166
+ moodle mcp deploy
167
+ moodle mcp status
168
+ moodle mcp login
169
+ moodle mcp connect
170
+ moodle mcp remove
171
+ moodle mcp serve
172
+ moodle mcp bridge
145
173
  ```
146
174
 
147
- The CLI alias delegates to the same command:
175
+ The default client connection uses `moodle mcp bridge`, which keeps the Bearer token out of client configuration. Use `moodle mcp connect CLIENT --mode remote` for clients that support authenticated remote MCP headers.
148
176
 
149
- ```bash
150
- moodle skills add
151
- ```
177
+ Alpha version `0.7.0-alpha.0` supports MCP `2026-07-28` and a stateless compatibility lane for `2025-11-25` clients.
152
178
 
153
- Regenerate the skill bundle from the command tree and source templates:
179
+ ### Configuration
154
180
 
155
- ```bash
156
- npm run build
157
- npm run skill:generate
158
- git diff --exit-code -- SKILL.md references agents/openai.yaml
159
- ```
181
+ | Variable | Purpose |
182
+ | --- | --- |
183
+ | `MOODLE_BASE_URL` | Set the Moodle site origin without writing a config file. |
184
+ | `MOODLE_CONFIG` | Use another YAML config file. |
185
+ | `MOODLE_TOKEN` | Provide a `MoodleSession` cookie value in a non-browser environment. |
186
+ | `MOODLE_SESSION` | Compatibility alias for `MOODLE_TOKEN`. |
160
187
 
161
- `SKILL.md` routes agents to focused guidance under `references/`; the exact command and output references remain generated from the CLI.
188
+ For local use, save `base_url` in `~/.config/moodle-cli/config.yaml`. `MOODLE_URL` remains a deprecated fallback for `MOODLE_BASE_URL`.
162
189
 
163
- ## Development
190
+ ### Build from source
164
191
 
165
- The project typechecks with TypeScript 7 and bundles the Node.js CLI with tsup/esbuild.
192
+ Node.js workflow:
166
193
 
167
194
  ```bash
168
- npm install
195
+ npm ci
169
196
  npm run check
170
197
  npm test
171
198
  npm run build
199
+ npm run pack:check
172
200
  ```
201
+
202
+ Bun workflow:
203
+
204
+ ```bash
205
+ bun install
206
+ bunx tsc --noEmit
207
+ bunx vitest run
208
+ bun run build
209
+ bun run pack:check
210
+ ```
211
+
212
+ ## License
213
+
214
+ [MIT](LICENSE)
package/SKILL.md CHANGED
@@ -1,13 +1,13 @@
1
1
  ---
2
2
  name: moodle-cli
3
- description: Read Moodle data with the `moodle` CLI. Use for authenticated profile, course discovery, deadlines, alerts, sections, activities, grades, assignment or quiz detail, resources, forum search and discussions, supported Moodle URLs, authentication diagnostics, or CLI updates.
3
+ description: Read Moodle data, download local files, and manage a private Moodle MCP deployment with the `moodle` CLI. Use for authenticated profile, unit discovery, deadlines, alerts, sections, activities, grades, forum workflows, local file downloads, supported Moodle URLs, authentication diagnostics, or MCP deploy, status, login, connection, and removal.
4
4
  ---
5
5
 
6
6
  # Moodle CLI
7
7
 
8
8
  <!-- Generated by `moodle skills generate`. Edit `src/skill.template.md` and `src/skill-references/`. -->
9
9
 
10
- Use `moodle` for read-only Moodle inspection.
10
+ Use `moodle` for read-only Moodle inspection, explicit local file downloads, and private managed MCP lifecycle operations.
11
11
 
12
12
  ## Core Steps
13
13
 
@@ -15,14 +15,15 @@ Use `moodle` for read-only Moodle inspection.
15
15
  2. Run the narrowest command that answers the request. Prefer `--json`; add `--fields` when only a few top-level fields matter.
16
16
  3. Parse the result locally and answer with the requested facts, exact dates, and relevant Moodle links. The task is complete when the answer is supported by command output rather than inference.
17
17
 
18
- Resolve an unfamiliar course name with `moodle courses --json` before using a course-specific command. Use `moodle overview --json` only for an explicitly combined snapshot.
18
+ Resolve an unfamiliar unit name with `moodle units --json` before using a unit-specific command. `courses` and `projects` are equivalent aliases. Use `moodle overview --json` only for an explicitly combined snapshot.
19
19
 
20
20
  ## Branch Map
21
21
 
22
- - **Installation, configuration, authentication failure, or session keepalive**: read [references/setup-and-auth.md](references/setup-and-auth.md).
22
+ - **Installation, configuration, authentication failure, session keepalive, or managed MCP lifecycle**: read [references/setup-and-auth.md](references/setup-and-auth.md).
23
23
  - **Profile, course discovery, sections, or activity lists**: read [references/profile-and-courses.md](references/profile-and-courses.md).
24
24
  - **Deadlines, todo items, alerts, or a combined snapshot**: read [references/deadlines-and-alerts.md](references/deadlines-and-alerts.md).
25
25
  - **Grades or assignment, quiz, resource, link, page, and folder detail**: read [references/coursework-and-grades.md](references/coursework-and-grades.md).
26
+ - **Downloading a resource or selected folder files to local paths**: read [references/downloads.md](references/downloads.md).
26
27
  - **Forum discovery, search, discussions, posts, groups, or rendering checks**: read [references/forums.md](references/forums.md).
27
28
  - **Output selection, field filtering, error handling, or exit codes**: read [references/output-and-errors.md](references/output-and-errors.md).
28
29
  - **Updates, skill installation, or skill regeneration**: read [references/maintenance.md](references/maintenance.md).
@@ -30,7 +31,8 @@ Resolve an unfamiliar course name with `moodle courses --json` before using a co
30
31
 
31
32
  ## Shared Rules
32
33
 
34
+ - Treat `moodle commands --json` as the source of truth for this tool's command tree.
33
35
  - Use `--table` only when the user asks for the terminal presentation.
34
36
  - Return a concise answer instead of pasting raw output unless raw JSON is requested.
35
37
  - Treat `MOODLE_SESSION` as a secret and keep it out of chat, commands shown to the user, and logs.
36
- - Keep the operation read-only. This CLI inspects Moodle; it does not create or modify Moodle content.
38
+ - Keep remote Moodle data read-only. `moodle download` may write only the explicitly selected local file path; managed MCP commands may change only the selected Worker, local renewal job, client registration, and MCP deployment credentials.
@@ -1,4 +1,4 @@
1
1
  interface:
2
2
  display_name: "Moodle CLI"
3
- short_description: "Inspect courses, grades, deadlines, and forums"
4
- default_prompt: "Use $moodle-cli to inspect my Moodle data and answer with the narrowest relevant command."
3
+ short_description: "Inspect Moodle and download local Moodle files"
4
+ default_prompt: "Use $moodle-cli to inspect my Moodle data or download selected local Moodle files with the narrowest relevant command."