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/README.md CHANGED
@@ -57,6 +57,19 @@ base_url: https://school.example.edu
57
57
 
58
58
  Use a root URL only, not `/login/index.php` or `/my/`.
59
59
 
60
+ ### Session Keepalive
61
+
62
+ Moodle expires idle sessions server-side, which normally forces a fresh SSO login. The CLI can renew the session in the background instead:
63
+
64
+ ```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
69
+ ```
70
+
71
+ On Linux, add a cron entry: `*/30 * * * * moodle auth keepalive --json`.
72
+
60
73
  ## Usage
61
74
 
62
75
  ```bash
@@ -137,16 +150,20 @@ The CLI alias delegates to the same command:
137
150
  moodle skills add
138
151
  ```
139
152
 
140
- Regenerate `SKILL.md` from the command tree:
153
+ Regenerate the skill bundle from the command tree and source templates:
141
154
 
142
155
  ```bash
143
156
  npm run build
144
157
  npm run skill:generate
145
- git diff --exit-code SKILL.md
158
+ git diff --exit-code -- SKILL.md references agents/openai.yaml
146
159
  ```
147
160
 
161
+ `SKILL.md` routes agents to focused guidance under `references/`; the exact command and output references remain generated from the CLI.
162
+
148
163
  ## Development
149
164
 
165
+ The project typechecks with TypeScript 7 and bundles the Node.js CLI with tsup/esbuild.
166
+
150
167
  ```bash
151
168
  npm install
152
169
  npm run check
package/SKILL.md CHANGED
@@ -1,167 +1,36 @@
1
1
  ---
2
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.
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.
4
4
  ---
5
5
 
6
- # moodle-cli
6
+ # Moodle CLI
7
7
 
8
- <!-- Generated by `moodle skills generate`. Edit `src/skill.template.md` for prose changes. -->
8
+ <!-- Generated by `moodle skills generate`. Edit `src/skill.template.md` and `src/skill-references/`. -->
9
9
 
10
- Use `moodle` for read-only Moodle access.
10
+ Use `moodle` for read-only Moodle inspection.
11
11
 
12
- ## Defaults
12
+ ## Core Steps
13
13
 
14
- Use the narrowest command that answers the request.
14
+ 1. Classify the request with the branch map below and read that reference file before running a command.
15
+ 2. Run the narrowest command that answers the request. Prefer `--json`; add `--fields` when only a few top-level fields matter.
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.
15
17
 
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.
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.
17
19
 
18
- Omit `--json` only when a human explicitly wants the formatted terminal view. Use `--table` to force human output in a pipe.
20
+ ## Branch Map
19
21
 
20
- Resolve course IDs with `moodle courses --json` before running course-specific commands when the user gives only a course name.
22
+ - **Installation, configuration, authentication failure, or session keepalive**: read [references/setup-and-auth.md](references/setup-and-auth.md).
23
+ - **Profile, course discovery, sections, or activity lists**: read [references/profile-and-courses.md](references/profile-and-courses.md).
24
+ - **Deadlines, todo items, alerts, or a combined snapshot**: read [references/deadlines-and-alerts.md](references/deadlines-and-alerts.md).
25
+ - **Grades or assignment, quiz, resource, link, page, and folder detail**: read [references/coursework-and-grades.md](references/coursework-and-grades.md).
26
+ - **Forum discovery, search, discussions, posts, groups, or rendering checks**: read [references/forums.md](references/forums.md).
27
+ - **Output selection, field filtering, error handling, or exit codes**: read [references/output-and-errors.md](references/output-and-errors.md).
28
+ - **Updates, skill installation, or skill regeneration**: read [references/maintenance.md](references/maintenance.md).
29
+ - **Exact syntax or all flags**: read [references/command-reference.md](references/command-reference.md).
21
30
 
22
- Avoid `moodle overview --json` unless the user explicitly asks for a combined snapshot across courses, deadlines, and alerts.
31
+ ## Shared Rules
23
32
 
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.
33
+ - Use `--table` only when the user asks for the terminal presentation.
34
+ - Return a concise answer instead of pasting raw output unless raw JSON is requested.
35
+ - 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.
@@ -0,0 +1,4 @@
1
+ interface:
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."