Skip to content
Pine Computer Request access
Menu

Blog

Cookbook 03: Browser, shell and files

Export reports from a portal, check the downloaded files in a shell and retrieve a zip. See the recorded Pine Computer run and Ruby code.

By The Pine Computer team · Updated

Cookbook 03: Browser, shell and files

The job is to collect a specified set of HR reports from a portal and return an archive to the application. The program supplies the list of reports, the agent downloads them through the browser, and a shell script checks the files before the application retrieves them.

Follow the files through the run

Two local files define the job. reports.csv tells the agent which reports to export. check.sh contains the application’s checks. The program uploads both into the session before asking the agent to sign in. Credentials travel through the secrets argument; they are not written into the report list.

After the agent’s turn ends, the program runs sh attachments/check.sh on the same computer. It then downloads the session’s artifacts as reports.zip and stops the computer. Browser downloads and the check script are available in the same working environment, so the application can inspect the files before taking them back.

The Ruby shown in the recording

This excerpt assumes an initialized pine client, an accessible HR portal, credentials, and local reports.csv and check.sh files. Those two files are specific to the reports being collected; the excerpt does not define their contents. Direct shell access requires project enablement. See the current files and shell documentation for setup and file paths.

The Ruby below is an excerpt from the October recording, not a current integration recipe. SDK setup and application helpers are omitted. Use the current agent API and file handling docs when building an integration.

Ruby
computer = pine.create_computer
session  = computer.create_session(browser: true)
session.create_tab(url: ENV["HR_URL"])

session.write_file("reports.csv", File.read("reports.csv"))
session.write_file("check.sh", File.read("check.sh"))

session.agent.run("Sign in and export every report listed in reports.csv as CSV. " \
                  "The sign-in details are in $SESSION_SECRETS.",
                  secrets: { "HR_USER" => ENV["HR_USER"], "HR_PASSWORD" => ENV["HR_PASSWORD"] })
session.agent.events { |e| break if e.terminal? }

puts session.exec("sh attachments/check.sh").stdout

File.binwrite("reports.zip", session.download_artifacts_zip)
puts "reports.zip is on this Mac"

gets
computer.stop

Decide whether the archive is ready to use

The example prints the check script’s output. Printing a result does not make it a release condition: as written, the program downloads the archive afterward even if the check reports a problem. An unattended integration should decide whether to accept the files before marking the job complete.

For a monthly report export, that decision needs to answer four questions:

  • Does every requested report have a matching output?
  • Can each file be parsed as the requested format, rather than a downloaded sign-in or error page?
  • Do the report name and period match the request?
  • Is an empty report valid for this account and period, or does it need review?

These are checks to implement for your portal, not results established by this recording. A ZIP file can contain an incomplete set of reports. A nonempty CSV can contain the wrong month.

Recover the missing work

Keep the report request and accepted outputs in your application’s storage. If three reports pass and one is missing, retry the missing export rather than replacing the entire batch. If the portal asks for sign-in again, resume that account’s job after the user restores access.

Download the outputs before stopping the computer: its session files are temporary. A saved browser login does not preserve the archive. Persistence describes that boundary; agent turns describes how to distinguish a finished turn, a failure and a request for input.

More from the blog

Build more.
Hand AI the work.