Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 60 additions & 16 deletions pm-stack/console/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,53 @@ refused. Five files a phone fetches before anyone has signed in are
public, matched exactly: `/manifest.webmanifest` and the four icons under
`/icons/`.

| Section | What you can do | What runs |
| ------------- | ----------------------------------------------------------------------------------- | --------------------------------------- |
| Overview | Queue counts, ready pull requests, agents, failed units | the calls below, together |
| Queue | List queued, claimed, blocked and parked tasks; unblock or cancel one with a reason | the queue store (read), `fleet queue` |
| Priorities | Ranked issues, most urgent first; change a rank; comment; file new work | `fleet gh` |
| Agents | Send an idea, message or command to one agent, a group or everyone; recent messages | `fleet bridge` |
| Services | State of the stack's units; start, stop, restart; read logs | `systemctl --user`, `journalctl --user` |
| Pull requests | Open pull requests; check one; merge it | `fleet gh` |
## The app

`/console/` is one page with five tabs. The first four are what the
owner does every day; everything else is under More.

| Tab | What it is for |
| -------- | ---------------------------------------------------------------------------------------------------------------- |
| Now | Tasks in progress with their next step, sessions that are moving, and what the owner did lately |
| Next | The queue in the order it will be claimed; move a task first, sooner or later; why tasks are blocked |
| Needs me | Open questions (one tap to answer, undo for a few seconds), things only hands can do, reviews |
| Ask | Say what you want in your own words (typed or dictated). It becomes an issue and a top-of-queue task in one pass |
| More | Queue by state, pull requests, ranked issues, agents, services, notifications, phones, and the dashboard's pages |

The page never waits on a live fan-out. The server keeps three documents
ready (`core`, `questions`, `ops`), each built from sections that are
read in the background and served from memory with the time they were
read (`GET /console/api/doc/<name>`, ETag, gzip). Every change goes
through one endpoint, `POST /console/api/act {kind, args}`; the kinds are
the table in `src/actions.ts`.

| Source | Read by | Written by |
| ----------------------------------------- | --------------------------------------- | ----------------------------------------------------- |
| The queue store | `src/work.ts` (one round trip) | `fleet queue`; one priority update for "move" |
| GitHub issues and pull requests | `fleet gh` | `fleet gh` |
| The dashboard's questions and needs lists | the dashboard's own JSON and store file | the dashboard's submit endpoint, with the set's token |
| Agents and messages | `fleet agent`, `fleet bridge` | `fleet bridge` |
| The stack's units | `systemctl --user`, `journalctl --user` | `systemctl --user` |

### Notifications

Web Push, sent by this service (`src/push.ts`: RFC 8291 and RFC 8292
with WebCrypto, keys in `~/.local/state/pm-console/push.json`). A device
subscribes under More, Notifications, and chooses what reaches it: a
reply to something asked, something new that needs the owner, new
questions, a failed unit. The Android app shows them as its own.

### Phones

The Android app's home-screen widget reads a short summary (three counts
and the top line of each list) with a token of its own, since it cannot
use the browser's sign-in. Linking passes no secret through an address:
the phone shows the signed-in owner a hash, the owner approves it under
More, Phones, and the phone then presents the value behind the hash to
`POST /console/device/link` and is given its token once. The store
(`devices.json`) keeps hashes of tokens. `GET /console/device/summary`
answers a linked phone and nobody else; both paths are limited, and they
are the only ones under `/console` that answer without the sign-in.

Every operation is an argument vector, never a shell line, and text you
type travels on stdin or as one argument.
Expand Down Expand Up @@ -65,9 +104,10 @@ itself comes from this machine and it crossed no proxy (loopback Host, no
forwarding headers). The connection's address is the test, since headers
are the caller's to write; for the same reason the console only listens
on loopback and refuses to start on any other address. Everything else
needs a token. Outside the install files above, two paths answer without
one: `/console/health` and `/.well-known/assetlinks.json` (the Android
app's link to this origin).
needs a token. Outside the install files above, these answer without
one: `/console/health`, `/.well-known/assetlinks.json` (the Android
app's link to this origin), and the two phone paths under
`/console/device/`, which check a linked phone's own token instead.

## Run

Expand Down Expand Up @@ -96,6 +136,7 @@ the route if the console does not come up with its sign-in settings.
| `PM_CONSOLE_UNITS`, `PM_CONSOLE_PROTECTED_UNITS` | the stack's units | Units the console manages; units it will not stop |
| `PM_CONSOLE_ANDROID_PACKAGE`, `PM_CONSOLE_ANDROID_SHA256` | `today.developing.pmconsole`, none | The Android app's identity in the asset-links file |
| `PM_CONSOLE_ANDROID_APK` | `~/.local/state/pm-console/android/pm-console.apk` | The signed build the console hands to the owner |
| `PM_CONSOLE_DEVICES_FILE` | `~/.local/state/pm-console/devices.json` | Linked phones (hashes of their tokens) |
| `PM_CONSOLE_REPO`, `PM_CONSOLE_QUEUE` | `developing-today/code`, `repo-health-code-pilot` | What it operates on |

A malformed port, a listen address or dashboard address that is not
Expand All @@ -104,10 +145,13 @@ variable.

## Android

`pm-stack/console/android/` is a Trusted Web Activity: the same site in
Chrome without browser chrome, so sign-in is Chrome's own and nothing is
reimplemented. The `pm-console-android` workflow builds it and the host
signs it. Once the signed file is on the host, the console's header
shows "Android app": a download for the signed-in owner at
`pm-stack/console/android/` shows the same site in Chrome without browser
chrome (a Trusted Web Activity), so sign-in is Chrome's own and the app
never falls behind the site. Around that it uses what only an installed
app has: a home-screen widget, dictation from a shortcut or a
quick-settings tile, text shared or selected in any app, long-press
shortcuts, and notifications shown as its own. The `pm-console-android`
workflow builds it and the host signs it. Once the signed file is on the
host, More, Phones offers it to the signed-in owner at
`/console/pm-console.apk`, so the phone gets the app from the site it
opens. See its README.
52 changes: 43 additions & 9 deletions pm-stack/console/android/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,39 @@
# PM console for Android

A Trusted Web Activity: the app opens `https://pm.security.cab/console/`
in Chrome without browser chrome. It is the site, so it does everything
the site does, signs in the way the site does (Chrome's own session), and
never needs a release when the console changes. There is no code in the
module; the launcher activity comes from `androidbrowserhelper`.
The screens are the site itself: the app opens
`https://pm.security.cab/console/` in Chrome without browser chrome (a
Trusted Web Activity). So it does everything the site does, signs in the
way the site does (Chrome's own session), and needs no release when the
console changes.

Around the site, the app uses what only an installed app has:

| What | How it is used | Code |
| -------------------- | ------------------------------------------------------------------------------------------------------------------------- | ------------------------------------- |
| Home-screen widget | In progress, queued next, needs me, and the task being worked on. Each number opens its screen | `StatusWidget`, `Fleet` |
| Dictation | Long-press the icon and choose Dictate, or tap the "Ask the fleet" quick-settings tile: the words land in the Ask box | `DictateActivity`, `AskTileService` |
| Share and selection | Share text from any app, or select text and choose "Ask the fleet": it lands in the Ask box | `ShareActivity` |
| Long-press shortcuts | Dictate, Ask, Needs me, Now. They move the open app to that screen and do not reload it | `OpenActivity`, `res/xml/shortcuts` |
| Notifications | The site's notifications arrive as the app's own, with its mark in the status bar; the app asks for the permission itself | the helper library's activities |
| Links | `https://pm.security.cab/...` links open in the app | the launcher activity's intent filter |

Words handed to the site (shared, selected or dictated) travel after the
`#` of the address, which a browser never sends to a server; they sit in
the Ask box until the owner presses Send.

### The widget's own sign-in

A widget cannot use the browser's session, so the phone is linked once:

1. Add the "PM status" widget to the home screen and tap it.
2. The app opens at More, Phones, showing "Link this phone?". Approve.
3. The widget fills in. It reads again every half hour, when the app is
opened, and when its refresh mark is tapped.

The phone makes a random value and shows the site only its hash; after
the approval it presents the value itself and is given a token that can
read the widget's summary and nothing else. The owner can remove a phone
under More, Phones, and the widget then goes back to "Tap to link".

## How the app and the site trust each other

Expand Down Expand Up @@ -45,10 +74,15 @@ reinstall; nothing else depends on it.

## Install

On the phone, open `https://pm.security.cab/console/`, sign in, and tap
"Android app" in the header. That downloads the signed build from the
host (`/console/pm-console.apk`, owner only); open it to install. Later
builds install over it.
On the phone, open `https://pm.security.cab/console/`, sign in, and go to
More, Phones, "Download the app". That downloads the signed build from
the host (`/console/pm-console.apk`, owner only); open it to install.
Later builds install over it.

The native parts are checked by compiling the build and reading its
merged manifest; the site's side of each (the Ask box taking handed-over
words, linking a phone, the summary) is tested in `test/`. They have not
been exercised by an automated run on a device.

The console serves whatever signed build is at
`~/.local/state/pm-console/android/pm-console.apk` on the host, so
Expand Down
22 changes: 14 additions & 8 deletions pm-stack/console/android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
// The PM console for Android: a Trusted Web Activity. The app is the
// site itself, shown by Chrome without browser chrome, so sign-in is
// Chrome's and nothing is reimplemented here. There is no code in this
// module: the launcher activity comes from androidbrowserhelper.
// The PM console for Android. The screens are the site itself, shown by
// Chrome without browser chrome (a Trusted Web Activity), so sign-in is
// Chrome's and the app never falls behind the site. Around that, the
// app uses what only an installed app has: it receives shared and
// selected text, starts dictation with the phone's own recogniser from
// a shortcut or a quick-settings tile, offers its main screens on a long
// press of the icon, shows the site's notifications as its own, and puts
// a widget on the home screen that reads a short summary by itself.
plugins {
id 'com.android.application'
}
Expand All @@ -15,13 +19,15 @@ android {

defaultConfig {
applicationId 'today.developing.pmconsole'
minSdk 23
minSdk 24
targetSdk 34
versionCode 1
versionName '0.1.0'
versionCode 3
versionName '0.3.0'
manifestPlaceholders = [hostName: 'pm.security.cab', defaultUrl: "${site}/console/"]
// The app's half of the link to the site. The site's half is
// /.well-known/assetlinks.json, served by pm-console.
resValue 'string', 'console_url', "${site}/console/"
resValue 'string', 'site_url', "${site}"
resValue 'string', 'asset_statements', "[{\\\"relation\\\": [\\\"delegate_permission/common.handle_all_urls\\\"], \\\"target\\\": {\\\"namespace\\\": \\\"web\\\", \\\"site\\\": \\\"${site}\\\"}}]"
}

Expand All @@ -31,7 +37,7 @@ android {
main {
manifest.srcFile 'src/twa/AndroidManifest.xml'
res.srcDirs = ['src/twa/res']
java.srcDirs = []
java.srcDirs = ['src/twa/java']
}
}

Expand Down
Loading