monash-study-kit 1.9.0__tar.gz → 1.10.0__tar.gz
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.
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/CHANGELOG.md +8 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/PKG-INFO +36 -1
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/README.md +35 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/README.zh-CN.md +35 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/pyproject.toml +1 -1
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/scripts/check_dist.py +1 -1
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/src/monash_study_kit/__init__.py +1 -1
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/src/monash_study_kit/__main__.py +1 -1
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/src/monash_study_kit/browser_login.py +3 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/src/monash_study_kit/cli.py +20 -3
- monash_study_kit-1.10.0/src/monash_study_kit/cli_profile.py +118 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/src/monash_study_kit/doctor.py +3 -1
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/src/monash_study_kit/doctor_deep.py +2 -0
- monash_study_kit-1.10.0/src/monash_study_kit/entry.py +89 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/src/monash_study_kit/google_export.py +28 -11
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/src/monash_study_kit/help_menu.py +10 -0
- monash_study_kit-1.10.0/src/monash_study_kit/home.py +41 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/src/monash_study_kit/jobs.py +12 -2
- monash_study_kit-1.10.0/src/monash_study_kit/materials_policy.py +57 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/src/monash_study_kit/mcp_server.py +25 -8
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/src/monash_study_kit/paths.py +15 -27
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/src/monash_study_kit/student_tools.py +2 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/tests/test_google_export.py +44 -1
- monash_study_kit-1.10.0/tests/test_profiles.py +448 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/.github/ISSUE_TEMPLATE/bug_report.yml +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/.github/ISSUE_TEMPLATE/config.yml +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/.github/ISSUE_TEMPLATE/feature_request.yml +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/.github/pull_request_template.md +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/.github/workflows/release.yml +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/.github/workflows/test.yml +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/.gitignore +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/CODE_OF_CONDUCT.md +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/CONTRIBUTING.md +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/LICENSE +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/PRIVACY.md +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/SECURITY.md +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/docs/SECURITY-REVIEW-1.5-SCOPE.md +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/docs/adr/0001-one-shared-core.md +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/docs/adr/0002-read-only-public-package.md +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/docs/adr/0003-release-from-a-tag.md +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/docs/adr/0004-confirmed-mail-and-attendance-actions.md +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/docs/adr/README.md +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/docs/gmail-foundation.md +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/docs/google-and-attendance-setup.md +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/docs/panels-library-remote.md +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/docs/releasing.md +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/docs/screenshots/todo.png +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/docs/security.md +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/glama.json +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/scripts/measure_tokens.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/scripts/smoke_test.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/skills/monash-study-kit/SKILL.md +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/src/monash_study_kit/attendance.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/src/monash_study_kit/attendance_assets/PROVENANCE.md +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/src/monash_study_kit/attendance_assets/extract-rows.js +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/src/monash_study_kit/attendance_assets/shared.js +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/src/monash_study_kit/attendance_auto.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/src/monash_study_kit/attendance_evidence.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/src/monash_study_kit/attendance_http.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/src/monash_study_kit/cdp.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/src/monash_study_kit/claude_setup.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/src/monash_study_kit/cli_attendance.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/src/monash_study_kit/cli_ed.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/src/monash_study_kit/cli_gmail.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/src/monash_study_kit/cli_google.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/src/monash_study_kit/clients.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/src/monash_study_kit/content_index.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/src/monash_study_kit/edexport.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/src/monash_study_kit/edlib.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/src/monash_study_kit/edquery.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/src/monash_study_kit/edsync.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/src/monash_study_kit/export.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/src/monash_study_kit/features.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/src/monash_study_kit/gmail.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/src/monash_study_kit/gmail_tools.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/src/monash_study_kit/google_client.json +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/src/monash_study_kit/htmldom.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/src/monash_study_kit/htmlmd.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/src/monash_study_kit/lesson_reader.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/src/monash_study_kit/lessons.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/src/monash_study_kit/library.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/src/monash_study_kit/location.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/src/monash_study_kit/moodle_content.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/src/monash_study_kit/moodlelib.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/src/monash_study_kit/output.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/src/monash_study_kit/recordings.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/src/monash_study_kit/remote.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/src/monash_study_kit/semester.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/src/monash_study_kit/service_actions.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/src/monash_study_kit/service_jobs.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/src/monash_study_kit/service_setup.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/src/monash_study_kit/student_services.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/src/monash_study_kit/syncer.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/src/monash_study_kit/textextract.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/src/monash_study_kit/todo.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/src/monash_study_kit/transcribe.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/src/monash_study_kit/ui/panel.html +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/src/monash_study_kit/update_check.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/src/monash_study_kit/webnotes.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/src/monash_study_kit/widgets.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/tests/conftest.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/tests/test_attendance_browser.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/tests/test_attendance_fast.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/tests/test_attendance_parity.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/tests/test_cdp.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/tests/test_cli.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/tests/test_clients.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/tests/test_content_index.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/tests/test_course_export.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/tests/test_doctor.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/tests/test_doctor_deep.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/tests/test_ed_auth.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/tests/test_ed_export.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/tests/test_ed_markdown.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/tests/test_ed_query.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/tests/test_ed_quiz.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/tests/test_ed_tracking.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/tests/test_feature_cli.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/tests/test_features.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/tests/test_gmail.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/tests/test_help_menu.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/tests/test_layout.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/tests/test_lesson_reader.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/tests/test_library.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/tests/test_location.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/tests/test_mcp.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/tests/test_moodle_content.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/tests/test_panels.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/tests/test_recordings.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/tests/test_remote.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/tests/test_removed_files.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/tests/test_security.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/tests/test_semester.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/tests/test_service_setup.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/tests/test_setup.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/tests/test_shared_core.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/tests/test_skill.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/tests/test_student_gmail.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/tests/test_student_tools.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/tests/test_sync_robustness.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/tests/test_todo.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/tests/test_update_check.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/tests/test_webnotes.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/tests/test_without_ed.py +0 -0
- {monash_study_kit-1.9.0 → monash_study_kit-1.10.0}/uv.lock +0 -0
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
Version numbers follow `__version__` in `src/monash_study_kit/__init__.py`: patch for bug fixes, minor for new features.
|
|
4
4
|
|
|
5
|
+
## 1.10.0
|
|
6
|
+
|
|
7
|
+
- Add an early account-selection entry point: `--profile NAME`, `--profile=NAME`, or `MONASH_KIT_PROFILE` isolates credentials, databases, materials and browser sessions under the default data home's `profiles/NAME`. Names are validated, directories are private, per-directory overrides cannot escape named profiles, and the default account keeps its existing behavior.
|
|
8
|
+
- Add `profile list` and confirmed `profile remove NAME [--all] [--yes]`. Removal revokes the target's Drive and Gmail OAuth authorizations before deleting any local session files; any revocation failure preserves all local files. Materials remain unless `--all` is used. No Moodle logout is requested, and the completion message points to Ed's manual API-token deletion page.
|
|
9
|
+
- Named profiles stay local: refuse remote serving, AI configuration and independent moves; setup only logs in and selects courses. Add `materials_only`, false by default and forced true for named profiles, with centralized CLI and MCP allowlists.
|
|
10
|
+
- Materials mode syncs Ed course lists and Lessons without discussions, preserves Moodle and linked Google material exports, and skips Gmail sync, attendance reads/keepalive, personal-calendar setup and private diagnostic checks. Its MCP surface is limited to file listing/reading/search, Lessons/quizzes and local Ed export; forbidden tools and aliases fail before their handlers run.
|
|
11
|
+
- Document complete command/tool policies, account isolation and cleanup. Add synthetic and subprocess tests for import order, directory isolation, settings enforcement, local-only restrictions, materials sync, background work, diagnostics, safe removal and credential-free listings.
|
|
12
|
+
|
|
5
13
|
## 1.9.0
|
|
6
14
|
|
|
7
15
|
Course exports now contain what used to be left as links, with the reason for anything still missing.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: monash-study-kit
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.10.0
|
|
4
4
|
Summary: Connect Monash Moodle and Ed to Claude, Codex, Cursor or any local MCP client via a local MCP server and CLI: deadlines, announcements, grades, full-text search over course materials and Ed posts, all on your own machine.
|
|
5
5
|
Project-URL: Homepage, https://github.com/Waldo0926/monash-study-kit
|
|
6
6
|
Project-URL: Issues, https://github.com/Waldo0926/monash-study-kit/issues
|
|
@@ -72,6 +72,41 @@ The picture is real output of `monash todo` against a database filled with made-
|
|
|
72
72
|
For the original v1.1 security review and the [1.5 feature review checklist](docs/SECURITY-REVIEW-1.5-SCOPE.md), see [security documentation](docs/security.md). The earlier review does not automatically certify features added later.
|
|
73
73
|
|
|
74
74
|
|
|
75
|
+
|
|
76
|
+
## Multiple accounts / course materials only (1.10.0)
|
|
77
|
+
|
|
78
|
+
Without `--profile`, or with `--profile default`, the existing default account keeps its directory rules and features. Named accounts store separate databases, files, credentials and browser sessions under `<default data home>/profiles/<name>/`. The base still follows `MONASH_KIT_HOME` > `location.json` > the platform default. `default` is reserved; other names must match `[a-z0-9][a-z0-9_-]{0,31}`.
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
monash --profile alice setup # login and course selection only
|
|
82
|
+
monash --profile alice google login # optional; drive.readonly only
|
|
83
|
+
monash --profile alice sync
|
|
84
|
+
monash --profile=alice export FIT1045 --sync
|
|
85
|
+
monash --profile alice mcp # local stdio, materials tools only
|
|
86
|
+
monash profile list # manage from the default account
|
|
87
|
+
monash profile remove alice # confirm, clear logins, keep materials
|
|
88
|
+
monash profile remove alice --all --yes # also remove databases and materials
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
`MONASH_KIT_PROFILE=alice` also works; the command-line selection wins. Selection happens before importing service modules; an initialized Python process cannot switch accounts. Named profiles ignore individual directory overrides (`MONASH_KIT_DATA`, `MONASH_KIT_SECRETS`, `MONASH_KIT_FILES`, `MONASH_KIT_ED_DATA`, `MONASH_KIT_ED_TOKEN`, `ED_TOKEN`, and `files_dir`) to avoid sharing the default account's paths or credentials. Directories use mode 700 where supported.
|
|
92
|
+
|
|
93
|
+
Named profiles **stay local**: `remote`, `connect`, `setup claude`, and `move` are refused, and `setup` skips AI configuration. Sessions cannot be handed to remote services or AI configuration. Local stdio `mcp` can still be run manually. Profiles move together with the default data home rather than independently.
|
|
94
|
+
|
|
95
|
+
Named profiles force `materials_only=true`, even if settings or environment variables request false. The default account starts with false and can enable it with `monash config materials_only true`. While the mode is active, config can inspect this setting but cannot change it. To exit on the default account, temporarily override `MONASH_KIT_MATERIALS_ONLY=false`, then save false; named profiles cannot use this override.
|
|
96
|
+
|
|
97
|
+
Materials sync keeps Moodle files, Pages, Books, assignment descriptions and visible grading criteria, folders, linked Google files and Ed Lessons. It still reads Ed course lists to match unit codes, but never syncs discussions or replies. Gmail background sync, attendance reads and keepalive are skipped; Moodle login does not obtain a personal calendar link. `doctor --deep` checks materials and the search index only, skipping deadlines, submission status, grades and posts. Existing cached data is not deleted when enabling the mode.
|
|
98
|
+
|
|
99
|
+
Complete command policy in materials mode (refused commands return exit code 1):
|
|
100
|
+
|
|
101
|
+
- Allowed: `setup` (login and course selection), `login moodle/ed`, `google login/status/logout`, `sync`, `export`, `courses`, `status`, `doctor`, `open`, `library`, `config`, `grep`, `help`, `mcp`; `ed export/lessons/read/quiz`; `moodle ls/get`; `profile list/remove` from the default account.
|
|
102
|
+
- Config cannot change active `materials_only`; named profiles cannot change `files_dir`. `moodle get` only accepts course-resource/file entry points, rejecting grade pages and submission files.
|
|
103
|
+
- Refused: all `gmail` and `attendance` commands; `todo`, `due`, `semester`, `media`, `uninstall`, `update`, `connect`, `move`, all `remote`, `setup claude`; `ed courses/threads/search/show/new/following`; `moodle overview/due/calendar/assignments/grades/news/search/find/open/alerts/messages`. New commands require an explicit allowlist entry.
|
|
104
|
+
|
|
105
|
+
The MCP tool list is exactly `list_files`, `read_file`, `search_content`, `get_ed_lessons`, `export_ed_lessons`; `use_ed=false` removes the last two. Other tools and their legacy aliases fail when called. Export writes a local zip without changing upstream course data and retains its local-write MCP annotation. Personal study prompts are unavailable. There is no arbitrary Drive browsing or search command/tool: Google exports only follow course links during sync.
|
|
106
|
+
|
|
107
|
+
`profile list` checks only credential-file presence and disk usage, never reading or printing credential contents. Removal first revokes the target profile's Drive and Gmail Google OAuth authorizations in order. Any revocation failure stops removal and preserves **every local file** for a retry; an earlier successful remote revocation cannot be undone. Once all revocations succeed, `secrets/`, `browser-profile/` and `attendance-browser/` are removed. Only `--all` removes the complete profile, including materials and databases. The default account and other profiles are untouched; Moodle receives no logout or other request. Ed API tokens have no revocation interface here: manually delete them at [Ed API tokens](https://edstem.org/au/settings/api-tokens).
|
|
108
|
+
|
|
109
|
+
|
|
75
110
|
## 1.9.0: more complete course exports
|
|
76
111
|
|
|
77
112
|
Moodle Pages, Book chapters, assignment descriptions and visible rubrics / marking guides are saved as Markdown. Moodle images are stored in course `assets/` by content hash, and internal links to Page, Resource, Folder and Book activities are followed. Folder downloads preserve original names, subdirectories and case, reuse files for seven days, and fall back to individual downloads. Missing notebook images, case mismatches, empty pages and hidden grading criteria are explained in the index.
|
|
@@ -36,6 +36,41 @@ The picture is real output of `monash todo` against a database filled with made-
|
|
|
36
36
|
For the original v1.1 security review and the [1.5 feature review checklist](docs/SECURITY-REVIEW-1.5-SCOPE.md), see [security documentation](docs/security.md). The earlier review does not automatically certify features added later.
|
|
37
37
|
|
|
38
38
|
|
|
39
|
+
|
|
40
|
+
## Multiple accounts / course materials only (1.10.0)
|
|
41
|
+
|
|
42
|
+
Without `--profile`, or with `--profile default`, the existing default account keeps its directory rules and features. Named accounts store separate databases, files, credentials and browser sessions under `<default data home>/profiles/<name>/`. The base still follows `MONASH_KIT_HOME` > `location.json` > the platform default. `default` is reserved; other names must match `[a-z0-9][a-z0-9_-]{0,31}`.
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
monash --profile alice setup # login and course selection only
|
|
46
|
+
monash --profile alice google login # optional; drive.readonly only
|
|
47
|
+
monash --profile alice sync
|
|
48
|
+
monash --profile=alice export FIT1045 --sync
|
|
49
|
+
monash --profile alice mcp # local stdio, materials tools only
|
|
50
|
+
monash profile list # manage from the default account
|
|
51
|
+
monash profile remove alice # confirm, clear logins, keep materials
|
|
52
|
+
monash profile remove alice --all --yes # also remove databases and materials
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
`MONASH_KIT_PROFILE=alice` also works; the command-line selection wins. Selection happens before importing service modules; an initialized Python process cannot switch accounts. Named profiles ignore individual directory overrides (`MONASH_KIT_DATA`, `MONASH_KIT_SECRETS`, `MONASH_KIT_FILES`, `MONASH_KIT_ED_DATA`, `MONASH_KIT_ED_TOKEN`, `ED_TOKEN`, and `files_dir`) to avoid sharing the default account's paths or credentials. Directories use mode 700 where supported.
|
|
56
|
+
|
|
57
|
+
Named profiles **stay local**: `remote`, `connect`, `setup claude`, and `move` are refused, and `setup` skips AI configuration. Sessions cannot be handed to remote services or AI configuration. Local stdio `mcp` can still be run manually. Profiles move together with the default data home rather than independently.
|
|
58
|
+
|
|
59
|
+
Named profiles force `materials_only=true`, even if settings or environment variables request false. The default account starts with false and can enable it with `monash config materials_only true`. While the mode is active, config can inspect this setting but cannot change it. To exit on the default account, temporarily override `MONASH_KIT_MATERIALS_ONLY=false`, then save false; named profiles cannot use this override.
|
|
60
|
+
|
|
61
|
+
Materials sync keeps Moodle files, Pages, Books, assignment descriptions and visible grading criteria, folders, linked Google files and Ed Lessons. It still reads Ed course lists to match unit codes, but never syncs discussions or replies. Gmail background sync, attendance reads and keepalive are skipped; Moodle login does not obtain a personal calendar link. `doctor --deep` checks materials and the search index only, skipping deadlines, submission status, grades and posts. Existing cached data is not deleted when enabling the mode.
|
|
62
|
+
|
|
63
|
+
Complete command policy in materials mode (refused commands return exit code 1):
|
|
64
|
+
|
|
65
|
+
- Allowed: `setup` (login and course selection), `login moodle/ed`, `google login/status/logout`, `sync`, `export`, `courses`, `status`, `doctor`, `open`, `library`, `config`, `grep`, `help`, `mcp`; `ed export/lessons/read/quiz`; `moodle ls/get`; `profile list/remove` from the default account.
|
|
66
|
+
- Config cannot change active `materials_only`; named profiles cannot change `files_dir`. `moodle get` only accepts course-resource/file entry points, rejecting grade pages and submission files.
|
|
67
|
+
- Refused: all `gmail` and `attendance` commands; `todo`, `due`, `semester`, `media`, `uninstall`, `update`, `connect`, `move`, all `remote`, `setup claude`; `ed courses/threads/search/show/new/following`; `moodle overview/due/calendar/assignments/grades/news/search/find/open/alerts/messages`. New commands require an explicit allowlist entry.
|
|
68
|
+
|
|
69
|
+
The MCP tool list is exactly `list_files`, `read_file`, `search_content`, `get_ed_lessons`, `export_ed_lessons`; `use_ed=false` removes the last two. Other tools and their legacy aliases fail when called. Export writes a local zip without changing upstream course data and retains its local-write MCP annotation. Personal study prompts are unavailable. There is no arbitrary Drive browsing or search command/tool: Google exports only follow course links during sync.
|
|
70
|
+
|
|
71
|
+
`profile list` checks only credential-file presence and disk usage, never reading or printing credential contents. Removal first revokes the target profile's Drive and Gmail Google OAuth authorizations in order. Any revocation failure stops removal and preserves **every local file** for a retry; an earlier successful remote revocation cannot be undone. Once all revocations succeed, `secrets/`, `browser-profile/` and `attendance-browser/` are removed. Only `--all` removes the complete profile, including materials and databases. The default account and other profiles are untouched; Moodle receives no logout or other request. Ed API tokens have no revocation interface here: manually delete them at [Ed API tokens](https://edstem.org/au/settings/api-tokens).
|
|
72
|
+
|
|
73
|
+
|
|
39
74
|
## 1.9.0: more complete course exports
|
|
40
75
|
|
|
41
76
|
Moodle Pages, Book chapters, assignment descriptions and visible rubrics / marking guides are saved as Markdown. Moodle images are stored in course `assets/` by content hash, and internal links to Page, Resource, Folder and Book activities are followed. Folder downloads preserve original names, subdirectories and case, reuse files for seven days, and fall back to individual downloads. Missing notebook images, case mismatches, empty pages and hidden grading criteria are explained in the index.
|
|
@@ -37,6 +37,41 @@ Moodle和Ed始终**只读**:不会交作业、做测验或在Ed发帖。可选
|
|
|
37
37
|
之前的[1.1安全审计](docs/security.md)只覆盖当时的功能;新增的远程连接、邮箱与考勤另列有[1.5审查清单](docs/SECURITY-REVIEW-1.5-SCOPE.md),不能直接沿用旧版结论。
|
|
38
38
|
|
|
39
39
|
|
|
40
|
+
|
|
41
|
+
## 多账号 / 只导课程资料(1.10.0)
|
|
42
|
+
|
|
43
|
+
不加 `--profile` 或使用 `--profile default`,仍是原来的默认账号,目录规则和功能不变。命名账号在默认数据目录的 `profiles/<名称>/` 中独立保存数据库、课件、凭据和浏览器会话;默认目录仍按 `MONASH_KIT_HOME` > `location.json` > 系统默认位置决定。`default` 是保留名,其他名称只能匹配 `[a-z0-9][a-z0-9_-]{0,31}`。
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
monash --profile alice setup # 只做登录和选课
|
|
47
|
+
monash --profile alice google login # 可选:只申请 drive.readonly
|
|
48
|
+
monash --profile alice sync
|
|
49
|
+
monash --profile=alice export FIT1045 --sync
|
|
50
|
+
monash --profile alice mcp # 本机 stdio,仅课程资料工具
|
|
51
|
+
monash profile list # 必须在默认账号下管理
|
|
52
|
+
monash profile remove alice # 确认后清除登录,保留资料
|
|
53
|
+
monash profile remove alice --all --yes # 同时删除资料和数据库
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
也支持环境变量 `MONASH_KIT_PROFILE=alice`;命令行选择优先。入口在导入服务模块前选定账号,不能在同一个 Python 进程中切换已经初始化的账号。命名账号忽略单项目录覆盖(`MONASH_KIT_DATA`、`MONASH_KIT_SECRETS`、`MONASH_KIT_FILES`、`MONASH_KIT_ED_DATA`、`MONASH_KIT_ED_TOKEN`、`ED_TOKEN` 和 `files_dir`),避免误用默认账号的目录或令牌。目录在支持的系统上设为 700 权限。
|
|
57
|
+
|
|
58
|
+
命名 profile **只留在本机**:拒绝 `remote`、`connect`、`setup claude` 和 `move`,`setup` 跳过 AI 软件配置;不能把会话交给远程服务或 AI 软件配置。`mcp` 仍可在本机手动运行。profile 随默认数据目录整体移动,不单独搬家。
|
|
59
|
+
|
|
60
|
+
命名 profile 强制开启 `materials_only`,设置文件或环境变量也关不掉。默认账号的该设置默认是 false,可以用 `monash config materials_only true` 开启;资料模式运行中只能查看 `materials_only`,不能用 config 修改。默认账号如需退出,可先用 `MONASH_KIT_MATERIALS_ONLY=false` 临时覆盖,再保存 false;命名账号不接受该覆盖。
|
|
61
|
+
|
|
62
|
+
资料模式同步照常获取 Moodle 课件、Page、Book、作业说明和可见评分细则、文件夹、课程链接中的 Google 文件和 Ed Lessons。Ed 仍拉课程列表以匹配课号,但不抓 threads / replies;跳过 Gmail 后台同步、考勤读取和续期,Moodle 登录时也不获取个人日历。`doctor --deep` 只检查课件和全文索引,不读个人截止、提交状态、成绩或帖子。已有缓存不会因此被删除。
|
|
63
|
+
|
|
64
|
+
资料模式的完整命令清单(被拒绝时退出码 1):
|
|
65
|
+
|
|
66
|
+
- 允许:`setup`(仅登录选课)、`login moodle/ed`、`google login/status/logout`、`sync`、`export`、`courses`、`status`、`doctor`、`open`、`library`、`config`、`grep`、`help`、`mcp`;`ed export/lessons/read/quiz`;`moodle ls/get`;默认账号下的 `profile list/remove`。
|
|
67
|
+
- `config` 不能修改当前启用的 `materials_only`;命名账号也不能修改 `files_dir`。`moodle get` 只接受课件资源和文件入口,拒绝成绩页和提交文件。
|
|
68
|
+
- 拒绝:全部 `gmail`、全部 `attendance`;`todo`、`due`、`semester`、`media`、`uninstall`、`update`、`connect`、`move`、全部 `remote`、`setup claude`;`ed courses/threads/search/show/new/following`;`moodle overview/due/calendar/assignments/grades/news/search/find/open/alerts/messages`。未来新增命令也需显式加入白名单。
|
|
69
|
+
|
|
70
|
+
MCP 只注册 `list_files`、`read_file`、`search_content`、`get_ed_lessons`、`export_ed_lessons`;`use_ed=false` 时再去掉后两项。其余工具(包括旧别名)调用均报错。导出只在本机写 zip,不修改上游课程;仍保留其本地写文件的 MCP 标注。个人学习预设提示不在此模式提供。没有任意浏览或搜索 Drive 的命令或工具,Google 文件只在同步时按课程链接导出。
|
|
71
|
+
|
|
72
|
+
`profile list` 只检查 Moodle / Ed / Google 凭据文件是否存在及占用空间,不读取或打印内容。`profile remove` 会先依次吊销目标 profile 的 Drive 和 Gmail Google OAuth 授权;任何一个失败时停止,**本机文件一律保留**,可重试(此前已成功的远端吊销无法撤回)。全部成功后删除目标的 `secrets/`、`browser-profile/`、`attendance-browser/`;只有 `--all` 才删整个 profile,默认账号和其他 profile 不受影响。不向 Moodle 发送注销或任何其他请求。Ed 的 API 令牌没有吊销接口,请到 [Ed API tokens](https://edstem.org/au/settings/api-tokens) 手动删除。
|
|
73
|
+
|
|
74
|
+
|
|
40
75
|
## 1.9.0:补全课程资料导出
|
|
41
76
|
|
|
42
77
|
- Moodle 的 Page、Book 章节、作业说明和学生能看到的 rubric / marking guide 存成 Markdown;正文里的 Moodle 图片存到课程的 `assets/`,同内容去重。指向本课程 Page、Resource、Folder、Book 的内部链接也会跟进。
|
|
@@ -41,7 +41,7 @@ Issues = "https://github.com/Waldo0926/monash-study-kit/issues"
|
|
|
41
41
|
Changelog = "https://github.com/Waldo0926/monash-study-kit/blob/main/CHANGELOG.md"
|
|
42
42
|
|
|
43
43
|
[project.scripts]
|
|
44
|
-
monash = "monash_study_kit.
|
|
44
|
+
monash = "monash_study_kit.entry:main"
|
|
45
45
|
|
|
46
46
|
[dependency-groups]
|
|
47
47
|
# tzdata:Windows 上跑考勤相关的测试要它
|
|
@@ -65,7 +65,7 @@ def main() -> None:
|
|
|
65
65
|
fail(f"包里不该有 {n}")
|
|
66
66
|
if f"\nVersion: {version}\n" not in meta:
|
|
67
67
|
fail("METADATA 里的版本号不对")
|
|
68
|
-
if "monash = monash_study_kit.
|
|
68
|
+
if "monash = monash_study_kit.entry:main" not in entry:
|
|
69
69
|
fail("没有 monash 命令的入口")
|
|
70
70
|
if "Description-Content-Type: text/markdown" not in meta or "## Installation" not in meta:
|
|
71
71
|
fail("PyPI 页面会没有 README")
|
|
@@ -181,6 +181,9 @@ def login_moodle(interactive: bool = True, timeout: float = 300, log=print) -> d
|
|
|
181
181
|
|
|
182
182
|
def _save_calendar_url(client: MoodleClient, log) -> None:
|
|
183
183
|
"""顺手存下 iCal 订阅链接:以后会话过期了,截止日期还能靠它拿到。"""
|
|
184
|
+
from .paths import load_settings
|
|
185
|
+
if load_settings().get("materials_only"):
|
|
186
|
+
return
|
|
184
187
|
from . import features as F
|
|
185
188
|
if F.load_calendar_url():
|
|
186
189
|
return
|
|
@@ -181,7 +181,9 @@ def cmd_setup(args):
|
|
|
181
181
|
code = claude_setup.install_code()
|
|
182
182
|
return 0 if desktop or code else 1
|
|
183
183
|
from . import location
|
|
184
|
-
|
|
184
|
+
from .paths import is_default_profile
|
|
185
|
+
materials = load_settings().get("materials_only", False)
|
|
186
|
+
if is_default_profile() and location.first_run():
|
|
185
187
|
print(f"Monash 学习助手 {__version__}\n")
|
|
186
188
|
choice = location.ask()
|
|
187
189
|
if choice is not None:
|
|
@@ -208,6 +210,9 @@ def cmd_setup(args):
|
|
|
208
210
|
login_moodle()
|
|
209
211
|
print("\n== 3/4 选课 ==")
|
|
210
212
|
choose_courses(interactive=_yes("默认跟踪本学期的课。要自己挑吗?", default=False))
|
|
213
|
+
if materials:
|
|
214
|
+
print("\n完成!已登录并选课。只导课程资料模式下,请运行 monash sync,再用 monash export <课号> 导出。")
|
|
215
|
+
return 0
|
|
211
216
|
print("\n== 4/4 接进 Claude ==")
|
|
212
217
|
claude_setup.install_code()
|
|
213
218
|
claude_setup.install_desktop()
|
|
@@ -256,6 +261,8 @@ def cmd_status(args):
|
|
|
256
261
|
def _optional_status() -> dict:
|
|
257
262
|
"""开了的可选功能各给一行;坏了也不影响 Moodle 和 Ed 的状态。"""
|
|
258
263
|
settings, out = load_settings(), {}
|
|
264
|
+
if settings.get("materials_only"):
|
|
265
|
+
return out
|
|
259
266
|
try:
|
|
260
267
|
if settings.get("gmail_enabled"):
|
|
261
268
|
from . import gmail
|
|
@@ -900,7 +907,7 @@ class _Parser(argparse.ArgumentParser):
|
|
|
900
907
|
|
|
901
908
|
|
|
902
909
|
def build_parser() -> argparse.ArgumentParser:
|
|
903
|
-
from . import cli_attendance, cli_ed, cli_gmail, cli_google
|
|
910
|
+
from . import cli_attendance, cli_ed, cli_gmail, cli_google, cli_profile
|
|
904
911
|
ap = _Parser(prog="monash", description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
905
912
|
ap.add_argument("--version", action="version", version=f"monash-study-kit {__version__}")
|
|
906
913
|
sub = ap.add_subparsers(dest="cmd")
|
|
@@ -1005,6 +1012,7 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
1005
1012
|
p.add_argument("conversation", nargs="?", type=int); p.add_argument("--limit", type=int, default=20)
|
|
1006
1013
|
p = cmd(m, "ls", cmd_m_ls, help="本地已同步的课件"); p.add_argument("course"); p.add_argument("week", nargs="?")
|
|
1007
1014
|
|
|
1015
|
+
cli_profile.add_commands(sub.add_parser("profile", help="管理本机命名账号").add_subparsers(dest="profile_cmd", required=True))
|
|
1008
1016
|
cli_ed.add_commands(sub.add_parser("ed", help="Ed 查询").add_subparsers(dest="ecmd", required=True))
|
|
1009
1017
|
cli_google.add_commands(sub.add_parser("google", help="Google 课程文件只读授权").add_subparsers(dest="google_cmd", required=True))
|
|
1010
1018
|
cli_gmail.add_commands(sub.add_parser("gmail", help="Gmail 同步、离线搜索与可选邮箱操作").add_subparsers(dest="gcmd", required=True))
|
|
@@ -1021,7 +1029,7 @@ def _print_update_notice() -> None:
|
|
|
1021
1029
|
print(f"\n↑ {msg}", file=sys.stderr)
|
|
1022
1030
|
|
|
1023
1031
|
|
|
1024
|
-
def
|
|
1032
|
+
def setup_streams() -> None:
|
|
1025
1033
|
for stream in (sys.stdout, sys.stderr):
|
|
1026
1034
|
try:
|
|
1027
1035
|
if stream.isatty():
|
|
@@ -1030,8 +1038,17 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
1030
1038
|
stream.reconfigure(encoding="utf-8") # 管道/重定向:Windows 默认是本地代码页,中文会丢
|
|
1031
1039
|
except (AttributeError, ValueError):
|
|
1032
1040
|
pass
|
|
1041
|
+
|
|
1042
|
+
|
|
1043
|
+
def main(argv: list[str] | None = None) -> int:
|
|
1044
|
+
setup_streams()
|
|
1033
1045
|
ap = build_parser()
|
|
1034
1046
|
args = ap.parse_args(argv)
|
|
1047
|
+
from .materials_policy import command_error
|
|
1048
|
+
error = command_error(args, load_settings())
|
|
1049
|
+
if error:
|
|
1050
|
+
print(error, file=sys.stderr)
|
|
1051
|
+
return 1
|
|
1035
1052
|
ensure_private_dir(HOME) # 库里有同学的名字和私密帖,只给自己读
|
|
1036
1053
|
quiet = args.cmd in ("mcp", "update", "doctor", "remote", "library")
|
|
1037
1054
|
if not quiet:
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"""仅在默认账号下管理命名 profile;删除前先吊销全部 Google 授权。"""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import os
|
|
5
|
+
import shutil
|
|
6
|
+
import sys
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
from . import google_export, paths
|
|
10
|
+
from .home import validate_profile
|
|
11
|
+
|
|
12
|
+
ED_HINT = "Ed 的 API 令牌没有吊销接口,请到 https://edstem.org/au/settings/api-tokens 手动删除"
|
|
13
|
+
SESSIONS = ("secrets", "browser-profile", "attendance-browser")
|
|
14
|
+
TOKENS = ("google-drive-token.json", "gmail-token.json")
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def profile_path(name: str) -> Path:
|
|
18
|
+
validate_profile(name)
|
|
19
|
+
root = paths.HOME / "profiles"
|
|
20
|
+
target = root / name
|
|
21
|
+
if root.is_symlink() or target.is_symlink():
|
|
22
|
+
raise ValueError("profile 目录不能是符号链接")
|
|
23
|
+
return target
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _size(directory: Path, exclude_profiles=False) -> int:
|
|
27
|
+
total = 0
|
|
28
|
+
for base, dirs, files in os.walk(directory, followlinks=False):
|
|
29
|
+
dirs[:] = [d for d in dirs if not (Path(base) / d).is_symlink()
|
|
30
|
+
and not (exclude_profiles and Path(base) == directory and d == "profiles")]
|
|
31
|
+
for name in files:
|
|
32
|
+
file = Path(base) / name
|
|
33
|
+
if not file.is_symlink():
|
|
34
|
+
total += file.stat().st_size
|
|
35
|
+
return total
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def list_profiles() -> list[dict]:
|
|
39
|
+
"""只查凭据文件是否存在,不读其中内容。"""
|
|
40
|
+
rows = []
|
|
41
|
+
roots = [("default", paths.HOME)]
|
|
42
|
+
root = paths.HOME / "profiles"
|
|
43
|
+
if root.is_dir() and not root.is_symlink():
|
|
44
|
+
for directory in sorted(root.iterdir()):
|
|
45
|
+
try:
|
|
46
|
+
validate_profile(directory.name)
|
|
47
|
+
except ValueError:
|
|
48
|
+
continue
|
|
49
|
+
if directory.is_dir() and not directory.is_symlink():
|
|
50
|
+
roots.append((directory.name, directory))
|
|
51
|
+
for name, directory in roots:
|
|
52
|
+
secrets = paths.SECRETS_DIR if name == "default" else directory / "secrets"
|
|
53
|
+
safe = not secrets.is_symlink()
|
|
54
|
+
exists = lambda filename: safe and (secrets / filename).is_file() and not (secrets / filename).is_symlink()
|
|
55
|
+
rows.append({"name": name, "path": str(directory), "moodle": exists("moodle-cookie"),
|
|
56
|
+
"ed": exists("ed-token"), "google": any(exists(t) for t in TOKENS),
|
|
57
|
+
"bytes": _size(directory, exclude_profiles=name == "default")})
|
|
58
|
+
return rows
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def remove_profile(name: str, *, all_data: bool = False, yes: bool = False, ask=None, log=print) -> bool:
|
|
62
|
+
"""任何吊销失败都不删本机内容;不调用 Moodle 注销或任何课程接口。"""
|
|
63
|
+
if not paths.is_default_profile():
|
|
64
|
+
raise ValueError("请在默认账号下运行 monash profile,不能在命名 profile 内管理其他账号")
|
|
65
|
+
target = profile_path(name)
|
|
66
|
+
if not target.is_dir():
|
|
67
|
+
raise ValueError(f"没有这个 profile:{name}")
|
|
68
|
+
for part in SESSIONS:
|
|
69
|
+
if (target / part).is_symlink():
|
|
70
|
+
raise ValueError("登录或会话目录不能是符号链接,请先手动检查")
|
|
71
|
+
for token in TOKENS:
|
|
72
|
+
if (target / "secrets" / token).is_symlink():
|
|
73
|
+
raise ValueError("凭据文件不能是符号链接,请先手动检查")
|
|
74
|
+
deleting = [target] if all_data else [target / part for part in SESSIONS]
|
|
75
|
+
if not yes:
|
|
76
|
+
answer = (ask or input)("将删除以下本机目录,并先吊销 Google 授权:\n" + "\n".join(str(d) for d in deleting) + "\n确认删除?[y/N] ")
|
|
77
|
+
if answer.strip().lower() not in {"y", "yes", "是"}:
|
|
78
|
+
log("已取消,未删除任何文件")
|
|
79
|
+
return False
|
|
80
|
+
for token in TOKENS:
|
|
81
|
+
google_export.revoke_token(target / "secrets" / token)
|
|
82
|
+
if all_data:
|
|
83
|
+
shutil.rmtree(target)
|
|
84
|
+
log(f"已删除 profile:{target}")
|
|
85
|
+
else:
|
|
86
|
+
for part in SESSIONS:
|
|
87
|
+
directory = target / part
|
|
88
|
+
if directory.is_dir():
|
|
89
|
+
shutil.rmtree(directory)
|
|
90
|
+
log(f"已清除登录和会话,课程资料与数据库仍保留在:{target}")
|
|
91
|
+
log(ED_HINT)
|
|
92
|
+
return True
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def run(args):
|
|
96
|
+
try:
|
|
97
|
+
if not paths.is_default_profile():
|
|
98
|
+
raise ValueError("请在默认账号下运行 monash profile,不能在命名 profile 内管理其他账号")
|
|
99
|
+
if args.profile_cmd == "list":
|
|
100
|
+
for row in list_profiles():
|
|
101
|
+
flag = lambda key: "有" if row[key] else "无"
|
|
102
|
+
print(f"{row['name']} · Moodle {flag('moodle')} · Ed {flag('ed')} · Google {flag('google')} · {row['bytes']} 字节 · {row['path']}")
|
|
103
|
+
else:
|
|
104
|
+
remove_profile(args.name, all_data=args.all, yes=args.yes)
|
|
105
|
+
return 0
|
|
106
|
+
except (ValueError, OSError, google_export.GoogleError) as e:
|
|
107
|
+
print(str(e) if not isinstance(e, OSError) else "本机目录清理失败,请检查权限后重试", file=sys.stderr)
|
|
108
|
+
return 1
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def add_commands(sub):
|
|
112
|
+
p = sub.add_parser("list", help="列账号、凭据是否存在和占用空间")
|
|
113
|
+
p.set_defaults(fn=run)
|
|
114
|
+
p = sub.add_parser("remove", help="吊销 Google 授权并清除本机登录会话")
|
|
115
|
+
p.set_defaults(fn=run)
|
|
116
|
+
p.add_argument("name", help="命名 profile,不能是 default")
|
|
117
|
+
p.add_argument("--all", action="store_true", help="同时删除课程资料和数据库")
|
|
118
|
+
p.add_argument("--yes", action="store_true", help="直接确认所列目录的清理")
|
|
@@ -257,8 +257,10 @@ CHECKS = [check_install, check_data_dir, check_browser, check_moodle, check_ed,
|
|
|
257
257
|
|
|
258
258
|
def run(skip: tuple = (), deep: bool = False) -> dict:
|
|
259
259
|
results = []
|
|
260
|
+
materials = load_settings().get("materials_only")
|
|
261
|
+
private = {"check_gmail", "check_attendance", "check_claude_desktop", "check_claude_code"}
|
|
260
262
|
for fn in CHECKS:
|
|
261
|
-
if fn.__name__ in skip:
|
|
263
|
+
if fn.__name__ in skip or materials and fn.__name__ in private:
|
|
262
264
|
continue
|
|
263
265
|
try:
|
|
264
266
|
result = fn()
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"""先选择账号目录,再导入会固定路径的 CLI 和服务模块。"""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import os
|
|
5
|
+
import sys
|
|
6
|
+
|
|
7
|
+
from .home import resolve_home, validate_profile
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
PROFILE_OVERRIDES = ("MONASH_KIT_DATA", "MONASH_KIT_SECRETS", "MONASH_KIT_FILES", "MONASH_KIT_ED_DATA",
|
|
11
|
+
"MONASH_KIT_ED_TOKEN", "ED_TOKEN")
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def configure(argv: list[str]) -> list[str]:
|
|
15
|
+
"""从任意命令层级取出全局 --profile,参数分隔符 -- 之后按原样保留。"""
|
|
16
|
+
remaining, names = [], []
|
|
17
|
+
i = 0
|
|
18
|
+
while i < len(argv):
|
|
19
|
+
arg = argv[i]
|
|
20
|
+
if arg == "--":
|
|
21
|
+
remaining.extend(argv[i:])
|
|
22
|
+
break
|
|
23
|
+
if arg == "--profile":
|
|
24
|
+
i += 1
|
|
25
|
+
if i == len(argv) or argv[i].startswith("--"):
|
|
26
|
+
raise ValueError("--profile 后面要填账号名称")
|
|
27
|
+
names.append(argv[i])
|
|
28
|
+
elif arg.startswith("--profile="):
|
|
29
|
+
names.append(arg.split("=", 1)[1])
|
|
30
|
+
else:
|
|
31
|
+
remaining.append(arg)
|
|
32
|
+
i += 1
|
|
33
|
+
if len(names) > 1:
|
|
34
|
+
raise ValueError("一次只能选择一个 --profile")
|
|
35
|
+
name = names[0] if names else os.environ.get("MONASH_KIT_PROFILE")
|
|
36
|
+
if name not in (None, "default"):
|
|
37
|
+
validate_profile(name)
|
|
38
|
+
environ = dict(os.environ)
|
|
39
|
+
# 子进程继承当前 profile 时,用记住的默认根目录,避免再套一层 profiles。
|
|
40
|
+
if environ.get("_MONASH_KIT_PROFILE_HOME") == environ.get("MONASH_KIT_HOME") and environ.get("_MONASH_KIT_BASE_HOME"):
|
|
41
|
+
environ["MONASH_KIT_HOME"] = environ["_MONASH_KIT_BASE_HOME"]
|
|
42
|
+
base = resolve_home(environ)
|
|
43
|
+
loaded = sys.modules.get(__package__ + ".paths")
|
|
44
|
+
selected = None if name in (None, "default") else name
|
|
45
|
+
expected = base / "profiles" / name if selected else base
|
|
46
|
+
if loaded is not None and (loaded.HOME != expected or loaded.PROFILE != selected):
|
|
47
|
+
raise ValueError("账号路径已初始化,请用新的 monash 进程选择 --profile,不能在同一进程内切换账号")
|
|
48
|
+
if name in (None, "default"):
|
|
49
|
+
if os.environ.get("_MONASH_KIT_PROFILE_HOME") == os.environ.get("MONASH_KIT_HOME") and os.environ.get("_MONASH_KIT_BASE_HOME"):
|
|
50
|
+
os.environ["MONASH_KIT_HOME"] = str(base)
|
|
51
|
+
os.environ.pop("MONASH_KIT_PROFILE", None)
|
|
52
|
+
else:
|
|
53
|
+
target = base / "profiles" / name
|
|
54
|
+
if (base / "profiles").is_symlink() or target.is_symlink():
|
|
55
|
+
raise ValueError("profile 目录不能是符号链接")
|
|
56
|
+
os.environ.update(MONASH_KIT_HOME=str(target), MONASH_KIT_PROFILE=name,
|
|
57
|
+
_MONASH_KIT_BASE_HOME=str(base), _MONASH_KIT_PROFILE_HOME=str(target))
|
|
58
|
+
for key in PROFILE_OVERRIDES:
|
|
59
|
+
os.environ.pop(key, None)
|
|
60
|
+
from .paths import ensure_private_dir
|
|
61
|
+
ensure_private_dir(target.parent)
|
|
62
|
+
ensure_private_dir(target)
|
|
63
|
+
return remaining
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def _setup_streams() -> None:
|
|
67
|
+
"""和 cli.setup_streams 一样;--profile 的报错在导入 cli 之前就要打印中文,Windows 上得先设好。"""
|
|
68
|
+
for stream in (sys.stdout, sys.stderr):
|
|
69
|
+
try:
|
|
70
|
+
if stream.isatty():
|
|
71
|
+
stream.reconfigure(errors="replace")
|
|
72
|
+
else:
|
|
73
|
+
stream.reconfigure(encoding="utf-8")
|
|
74
|
+
except (AttributeError, ValueError):
|
|
75
|
+
pass
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def main(argv: list[str] | None = None) -> int:
|
|
79
|
+
_setup_streams()
|
|
80
|
+
try:
|
|
81
|
+
arguments = configure(list(sys.argv[1:] if argv is None else argv))
|
|
82
|
+
except ValueError as e:
|
|
83
|
+
print(e, file=sys.stderr)
|
|
84
|
+
return 1
|
|
85
|
+
except OSError:
|
|
86
|
+
print("profile 目录无法创建,请检查默认数据目录及权限", file=sys.stderr)
|
|
87
|
+
return 1
|
|
88
|
+
from .cli import main as cli_main
|
|
89
|
+
return cli_main(arguments)
|
|
@@ -113,19 +113,36 @@ def status() -> dict:
|
|
|
113
113
|
raise GoogleError(AUTH_REASON) from None
|
|
114
114
|
|
|
115
115
|
|
|
116
|
+
def revoke_token(token_file: Path) -> None:
|
|
117
|
+
"""只吊销指定文件里的授权,不删文件,供多文件全部吊销后再统一清理。"""
|
|
118
|
+
if not token_file.is_file():
|
|
119
|
+
return
|
|
120
|
+
try:
|
|
121
|
+
data = json.loads(token_file.read_text(encoding="utf-8"))
|
|
122
|
+
token = data.get("refresh_token") or data.get("token")
|
|
123
|
+
if not token:
|
|
124
|
+
return
|
|
125
|
+
# 吊销接口只认 POST(GET 会 404);令牌放在请求体里,不出现在网址中
|
|
126
|
+
req = urllib.request.Request("https://oauth2.googleapis.com/revoke", method="POST",
|
|
127
|
+
data=urllib.parse.urlencode({"token": token}).encode(),
|
|
128
|
+
headers={"Content-Type": "application/x-www-form-urlencoded"})
|
|
129
|
+
with urllib.request.build_opener(gmail._NoRedirect()).open(req, timeout=30) as resp:
|
|
130
|
+
resp.read()
|
|
131
|
+
except urllib.error.HTTPError as e:
|
|
132
|
+
# 400 invalid_token:授权早就失效了(过期,或者在 Google 账号页面撤销过),等于已经吊销
|
|
133
|
+
body = e.read(4096).decode("utf-8", "replace")
|
|
134
|
+
e.close()
|
|
135
|
+
if e.code == 400 and "invalid_token" in body:
|
|
136
|
+
return
|
|
137
|
+
raise GoogleError("Google 授权吊销失败,本机令牌已保留,请重试") from None
|
|
138
|
+
except Exception:
|
|
139
|
+
raise GoogleError("Google 授权吊销失败,本机令牌已保留,请重试") from None
|
|
140
|
+
|
|
141
|
+
|
|
116
142
|
def logout() -> dict:
|
|
117
143
|
"""先吊销再删本机文件;吊销失败保留文件,方便重试。"""
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
token = data.get("refresh_token") or data.get("token")
|
|
121
|
-
if token:
|
|
122
|
-
req = urllib.request.Request("https://oauth2.googleapis.com/revoke?" + urllib.parse.urlencode({"token": token}))
|
|
123
|
-
try:
|
|
124
|
-
with urllib.request.build_opener(gmail._NoRedirect()).open(req, timeout=30) as resp:
|
|
125
|
-
resp.read()
|
|
126
|
-
except Exception:
|
|
127
|
-
raise GoogleError("Google 授权吊销失败,本机令牌已保留,请重试") from None
|
|
128
|
-
TOKEN_FILE.unlink()
|
|
144
|
+
revoke_token(TOKEN_FILE)
|
|
145
|
+
TOKEN_FILE.unlink(missing_ok=True)
|
|
129
146
|
return {"已授权": False}
|
|
130
147
|
|
|
131
148
|
|
|
@@ -93,6 +93,16 @@ def features(settings: dict | None = None) -> list:
|
|
|
93
93
|
|
|
94
94
|
def render(cli: bool = True, settings: dict | None = None) -> str:
|
|
95
95
|
"""cli=True 给终端看(带命令);False 给 Claude 看(只有功能和问法)。"""
|
|
96
|
+
if settings is None:
|
|
97
|
+
from .paths import load_settings
|
|
98
|
+
settings = load_settings()
|
|
99
|
+
if settings.get("materials_only"):
|
|
100
|
+
return ("只导课程资料模式:\n"
|
|
101
|
+
"登录:monash login [moodle|ed];monash google login/status/logout\n"
|
|
102
|
+
"同步导出:monash sync;monash export <课号> [--sync];monash ed export <课号>\n"
|
|
103
|
+
"查资料:monash grep;monash ed lessons/read/quiz;monash moodle ls/get\n"
|
|
104
|
+
"管理:monash courses/status/doctor/open/library/config;默认账号下 monash profile list/remove\n"
|
|
105
|
+
"MCP:monash mcp,只提供课程资料工具。邮箱、考勤、成绩、私信、帖子和个人待办已禁用。")
|
|
96
106
|
out = ["能做的事(直接用自己的话问就行,下面只是例子):" if not cli else "monash 能做的事:", ""]
|
|
97
107
|
for cat, items in features(settings):
|
|
98
108
|
out.append(f"■ {cat}")
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"""入口和路径模块共用的目录规则;不初始化任何账号路径。"""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import json
|
|
5
|
+
import os
|
|
6
|
+
import re
|
|
7
|
+
import sys
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def _default_home() -> Path:
|
|
12
|
+
if sys.platform == "darwin":
|
|
13
|
+
return Path.home() / "Library" / "Application Support" / "monash-study-kit"
|
|
14
|
+
if os.name == "nt":
|
|
15
|
+
base = os.environ.get("LOCALAPPDATA") or str(Path.home() / "AppData" / "Local")
|
|
16
|
+
return Path(base) / "monash-study-kit"
|
|
17
|
+
base = os.environ.get("XDG_DATA_HOME") or str(Path.home() / ".local" / "share")
|
|
18
|
+
return Path(base) / "monash-study-kit"
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
DEFAULT_HOME = _default_home()
|
|
22
|
+
LOCATION_FILE = DEFAULT_HOME / "location.json" # 数据放在别处时,这里记着实际位置
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def resolve_home(environ=os.environ, location_file: Path = LOCATION_FILE, default: Path = DEFAULT_HOME) -> Path:
|
|
26
|
+
"""MONASH_KIT_HOME > location.json 里记的位置 > 系统默认位置。location.json 坏了或写的不是绝对路径就当没有。"""
|
|
27
|
+
if environ.get("MONASH_KIT_HOME"):
|
|
28
|
+
return Path(environ["MONASH_KIT_HOME"])
|
|
29
|
+
try:
|
|
30
|
+
home = Path(json.loads(location_file.read_text(encoding="utf-8"))["home"]).expanduser()
|
|
31
|
+
except (OSError, ValueError, KeyError, TypeError):
|
|
32
|
+
return default
|
|
33
|
+
return home if home.is_absolute() else default
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def validate_profile(name: str) -> str:
|
|
38
|
+
"""default 保留给默认账号,命名 profile 不能使用它。"""
|
|
39
|
+
if name == "default" or not re.fullmatch(r"[a-z0-9][a-z0-9_-]{0,31}", name):
|
|
40
|
+
raise ValueError("profile 名称只能是 1–32 位小写字母、数字、下划线或连字符,首位须为字母或数字;default 是保留名")
|
|
41
|
+
return name
|